First version that compiles with new file layout.
Had to make many changes to get it to compile across many files, including removing the LOCAL specifier from almost all functions. Edited the Makefile to compile all three files and link them. Haven't tested on hardware yet, that's the next step. Lots of small changes to avoid warnings, now that I have turned -Wall on. This makes the code a bit "better". Signed-off-by: A.M. Rowsell <amrowsell@frozenelectronics.ca>
This commit is contained in:
parent
1cd8191682
commit
48702bf328
7 changed files with 124 additions and 72 deletions
42
mqtt.c
42
mqtt.c
|
@ -22,18 +22,14 @@
|
|||
* security or QoS in this basic implementation.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
static os_timer_t oneTimer;
|
||||
static os_timer_t testTimer;
|
||||
#endif
|
||||
static os_timer_t MQTT_KeepAliveTimer;
|
||||
static os_timer_t waitForWifiTimer;
|
||||
|
||||
LOCAL void ICACHE_FLASH_ATTR data_sent_callback(void *arg) {
|
||||
void ICACHE_FLASH_ATTR data_sent_callback(void *arg) {
|
||||
os_printf("Data sent!\n");
|
||||
}
|
||||
|
||||
LOCAL void ICACHE_FLASH_ATTR data_recv_callback(void *arg, char *pdata, unsigned short len) {
|
||||
void ICACHE_FLASH_ATTR data_recv_callback(void *arg, char *pdata, unsigned short len) {
|
||||
struct espconn *pConn = arg;
|
||||
mqtt_session_t *session = pConn->reverse;
|
||||
// deal with received data
|
||||
|
@ -73,13 +69,13 @@ LOCAL void ICACHE_FLASH_ATTR data_recv_callback(void *arg, char *pdata, unsigned
|
|||
break;
|
||||
}
|
||||
if(session->connack_cb != NULL) {
|
||||
session->connack_cb(pData);
|
||||
session->connack_cb(pdata);
|
||||
}
|
||||
break;
|
||||
case MQTT_MSG_TYPE_PUBLISH:
|
||||
os_printf("Application message from server: %s\n", &pdata[3]); // probably incorrect
|
||||
if(session->publish_cb != NULL) {
|
||||
session->publish_cb(pData);
|
||||
session->publish_cb(pdata);
|
||||
}
|
||||
break;
|
||||
case MQTT_MSG_TYPE_SUBACK:
|
||||
|
@ -91,11 +87,24 @@ LOCAL void ICACHE_FLASH_ATTR data_recv_callback(void *arg, char *pdata, unsigned
|
|||
case MQTT_MSG_TYPE_PINGRESP:
|
||||
os_printf("Pong!\n");
|
||||
break;
|
||||
// all remaining cases listed to avoid warnings
|
||||
case MQTT_MSG_TYPE_CONNECT:
|
||||
case MQTT_MSG_TYPE_PUBACK:
|
||||
case MQTT_MSG_TYPE_PUBREC:
|
||||
case MQTT_MSG_TYPE_PUBREL:
|
||||
case MQTT_MSG_TYPE_PUBCOMP:
|
||||
case MQTT_MSG_TYPE_SUBSCRIBE:
|
||||
case MQTT_MSG_TYPE_UNSUBSCRIBE:
|
||||
case MQTT_MSG_TYPE_PINGREQ:
|
||||
case MQTT_MSG_TYPE_DISCONNECT:
|
||||
default:
|
||||
return;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
LOCAL void ICACHE_FLASH_ATTR connected_callback(void *arg) {
|
||||
void ICACHE_FLASH_ATTR connected_callback(void *arg) {
|
||||
struct espconn *pConn = arg;
|
||||
mqtt_session_t *pSession = pConn->reverse;
|
||||
#ifdef DEBUG
|
||||
|
@ -108,16 +117,16 @@ LOCAL void ICACHE_FLASH_ATTR connected_callback(void *arg) {
|
|||
pSession->validConnection = 1;
|
||||
}
|
||||
|
||||
LOCAL void ICACHE_FLASH_ATTR reconnected_callback(void *arg, sint8 err) {
|
||||
void ICACHE_FLASH_ATTR reconnected_callback(void *arg, sint8 err) {
|
||||
os_printf("Reconnected?\n");
|
||||
os_printf("Error code: %d\n", err);
|
||||
}
|
||||
|
||||
LOCAL void ICACHE_FLASH_ATTR disconnected_callback(void *arg) {
|
||||
void ICACHE_FLASH_ATTR disconnected_callback(void *arg) {
|
||||
os_printf("Disconnected\n");
|
||||
}
|
||||
|
||||
LOCAL uint8_t ICACHE_FLASH_ATTR tcpConnect(void *arg) {
|
||||
uint8_t ICACHE_FLASH_ATTR tcpConnect(void *arg) {
|
||||
os_timer_disarm(&waitForWifiTimer);
|
||||
struct ip_info ipConfig;
|
||||
mqtt_session_t *session = arg;
|
||||
|
@ -164,11 +173,13 @@ LOCAL uint8_t ICACHE_FLASH_ATTR tcpConnect(void *arg) {
|
|||
// set timer to try again
|
||||
os_timer_setfn(&waitForWifiTimer, (os_timer_func_t *)tcpConnect, session);
|
||||
os_timer_arm(&waitForWifiTimer, 1000, 0);
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
LOCAL uint8_t ICACHE_FLASH_ATTR *encodeLength(uint32_t trueLength) {
|
||||
uint8_t ICACHE_FLASH_ATTR *encodeLength(uint32_t trueLength) {
|
||||
uint8_t *encodedByte = os_zalloc(sizeof(uint8_t) * 5); // can't be more than 5 bytes
|
||||
uint8_t numBytes = 1;
|
||||
do {
|
||||
|
@ -185,12 +196,12 @@ LOCAL uint8_t ICACHE_FLASH_ATTR *encodeLength(uint32_t trueLength) {
|
|||
|
||||
}
|
||||
|
||||
LOCAL void ICACHE_FLASH_ATTR pingAlive(void *arg) {
|
||||
void ICACHE_FLASH_ATTR pingAlive(void *arg) {
|
||||
mqtt_session_t *pSession = (mqtt_session_t *)arg;
|
||||
mqtt_send(pSession, NULL, 0, MQTT_MSG_TYPE_PINGREQ);
|
||||
}
|
||||
|
||||
LOCAL uint8_t ICACHE_FLASH_ATTR mqtt_send(mqtt_session_t *session, uint8_t *data, uint32_t len, mqtt_message_type msgType) {
|
||||
uint8_t ICACHE_FLASH_ATTR mqtt_send(mqtt_session_t *session, uint8_t *data, uint32_t len, mqtt_message_type msgType) {
|
||||
if(session->validConnection == 1) {
|
||||
os_timer_disarm(&MQTT_KeepAliveTimer); // disable timer if we are called
|
||||
#ifdef DEBUG
|
||||
|
@ -361,4 +372,5 @@ LOCAL uint8_t ICACHE_FLASH_ATTR mqtt_send(mqtt_session_t *session, uint8_t *data
|
|||
} else {
|
||||
os_printf("No wifi! Narf!\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue