Skip to content

Commit

Permalink
improve parser stability
Browse files Browse the repository at this point in the history
  • Loading branch information
vppillai committed Jan 20, 2021
1 parent 1c27e07 commit 5b77d2d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<group>
<file>file:/D:/PIC32MZW1_Curiosity_OOB/src/firmware/src/msd_app.c</file>
<file>file:/D:/PIC32MZW1_Curiosity_OOB/src/firmware/src/msd_app.h</file>
<file>file:/D:/PIC32MZW1_Curiosity_OOB/src/firmware/src/mqtt_app.c</file>
<file>file:/D:/PIC32MZW1_Curiosity_OOB/src/firmware/src/config/pic32mz_w1_curiosity/user.h</file>
</group>
</open-files>
Expand Down
17 changes: 12 additions & 5 deletions src/firmware/src/mqtt_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
MQTT_APP_DATA mqtt_appData;

int32_t MqttCallback(SYS_MQTT_EVENT_TYPE eEventType, void *data, uint16_t len, void* cookie) {
static int errorCount=0;
static int errorCount = 0;
switch (eEventType) {
case SYS_MQTT_EVENT_MSG_RCVD:
{
Expand All @@ -64,7 +64,14 @@ int32_t MqttCallback(SYS_MQTT_EVENT_TYPE eEventType, void *data, uint16_t len, v
break;
}

bool desiredState = (bool) cJSON_GetObjectItem(state, "toggle")->valueint;
//Get the toggle state
cJSON *toggle = cJSON_GetObjectItem(state, "toggle");
if (!state) {
cJSON_Delete(messageJson);
break;
}

bool desiredState = (bool) toggle->valueint;
if (desiredState) {
LED_GREEN_On();
SYS_CONSOLE_PRINT(TERM_GREEN"LED ON\r\n"TERM_RESET);
Expand Down Expand Up @@ -122,7 +129,7 @@ int32_t MqttCallback(SYS_MQTT_EVENT_TYPE eEventType, void *data, uint16_t len, v
{
//SYS_CONSOLE_PRINT("\nMqttCallback(): Published Sensor Data\r\n");
mqtt_appData.MQTTPubQueued = false;
errorCount=0;
errorCount = 0;
}
break;
case SYS_MQTT_EVENT_MSG_CONNACK_TO:
Expand All @@ -142,10 +149,10 @@ int32_t MqttCallback(SYS_MQTT_EVENT_TYPE eEventType, void *data, uint16_t len, v
SYS_CONSOLE_PRINT("\nMqttCallback(): PUBACK Timed out. non-Fatal error.\r\n");
mqtt_appData.MQTTPubQueued = false;
errorCount++;
if(errorCount>5) {
if (errorCount > 5) {
SYS_CONSOLE_PRINT(TERM_RED"\nMqttCallback(): Too many failed events. Forcing a reset\r\n"TERM_RESET);
}
while(1); //force a WDT reset
while (1); //force a WDT reset
}
break;
case SYS_MQTT_EVENT_MSG_UNSUBACK_TO:
Expand Down

0 comments on commit 5b77d2d

Please sign in to comment.