This commit is contained in:
Wolfgang Hottgenroth 2020-11-16 17:33:17 +01:00
parent 4468cc1368
commit 878da97ace
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F

View File

@ -27,12 +27,25 @@ const static char WatchdogTopic[] = "IoT/Watchdog";
const static char StartupTopic[] = "IoT/MBGW3/Startup"; const static char StartupTopic[] = "IoT/MBGW3/Startup";
const static char StatusTopic[] = "IoT/MBGW3/Status"; const static char StatusTopic[] = "IoT/MBGW3/Status";
static uint32_t watchdogCounter = 0;
void watchdogHandler(void *handle) {
if (watchdogCounter > 0) {
coloredMsg(LOG_GREEN, "Watchdog received in between");
watchdogCounter = 0;
} else {
coloredMsg(LOG_RED, "No watchdog received in between, booting the system ...");
// boot the system
}
}
// typedef void (*callback_t)(char*, uint8_t*, uint16_t); // typedef void (*callback_t)(char*, uint8_t*, uint16_t);
static void mqttCallback(char *topic, uint8_t *payload, uint16_t payloadLength) { static void mqttCallback(char *topic, uint8_t *payload, uint16_t payloadLength) {
logMsg("mqcb: %s : %.*s", topic, payloadLength, payload);
if (0 == strcmp(topic, WatchdogTopic)) { if (0 == strcmp(topic, WatchdogTopic)) {
coloredMsg(LOG_GREEN, "mqcb: watchdog message received"); watchdogCounter++;
} else {
logMsg("mqcb: %s : %.*s", topic, payloadLength, payload);
} }
} }
@ -88,6 +101,8 @@ void mqttCommHandler(void *handle) {
coloredMsg(LOG_YELLOW, "mqch, subscribe watchdog"); coloredMsg(LOG_YELLOW, "mqch, subscribe watchdog");
res = subscribe(&mqttClient, WatchdogTopic, MQTTQOS0); res = subscribe(&mqttClient, WatchdogTopic, MQTTQOS0);
coloredMsg(LOG_YELLOW, "mqch, subscribe returned %d", res); coloredMsg(LOG_YELLOW, "mqch, subscribe returned %d", res);
schAdd(watchdogHandler, NULL, 0, 60);
coloredMsg(LOG_YELLOW, "mqch, watchdogHandler scheduled");
state = 4; state = 4;
break; break;
@ -106,6 +121,7 @@ void mqttCommHandler(void *handle) {
case 255: case 255:
coloredMsg(LOG_YELLOW, "mqch, error state, will stop here"); coloredMsg(LOG_YELLOW, "mqch, error state, will stop here");
schDel(mqttCommHandler, NULL); schDel(mqttCommHandler, NULL);
schDel(watchdogHandler, NULL);
coloredMsg(LOG_YELLOW, "mqch, trying again in one minute"); coloredMsg(LOG_YELLOW, "mqch, trying again in one minute");
schAdd(mqttCommHandler, NULL, 60000, 100); schAdd(mqttCommHandler, NULL, 60000, 100);
break; break;