refactor loop handling
This commit is contained in:
@ -25,11 +25,6 @@ static void mqttCallback(char *topic, uint8_t *payload, uint16_t payloadLength)
|
||||
logMsg("mcb: %s : %*s", topic, payloadLength, payload);
|
||||
}
|
||||
|
||||
|
||||
void mqttLoopHandler(void *handle) {
|
||||
mqttLoop(&mqttClient);
|
||||
}
|
||||
|
||||
void mqttTestHandler(void *handle) {
|
||||
static uint8_t state = 0;
|
||||
static uint8_t message[] = "Hello world\n\r";
|
||||
@ -59,33 +54,36 @@ void mqttTestHandler(void *handle) {
|
||||
break;
|
||||
|
||||
case 2:
|
||||
coloredMsg(LOG_YELLOW, "mth, start mqtt loop");
|
||||
schAdd(mqttLoopHandler, NULL, 0, 100);
|
||||
coloredMsg(LOG_YELLOW, "mth, publish something");
|
||||
res = publish(&mqttClient, "wiznet/hello", message, strlen(message), false);
|
||||
coloredMsg(LOG_YELLOW, "mth, publish returned %d", res);
|
||||
state = 3;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
coloredMsg(LOG_YELLOW, "mth, publish something");
|
||||
res = publish(&mqttClient, "wiznet/hello", message, strlen(message), false);
|
||||
coloredMsg(LOG_YELLOW, "mth, publish returned %d", res);
|
||||
coloredMsg(LOG_YELLOW, "mth, subscribe something");
|
||||
res = subscribe(&mqttClient, "wiznet/helloback", MQTTQOS0);
|
||||
coloredMsg(LOG_YELLOW, "mth, subscribe returned %d", res);
|
||||
state = 4;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
coloredMsg(LOG_YELLOW, "mth, subscribe something");
|
||||
res = subscribe(&mqttClient, "wiznet/helloback", MQTTQOS0);
|
||||
coloredMsg(LOG_YELLOW, "mth, subscribe returned %d", res);
|
||||
coloredMsg(LOG_YELLOW, "mth, now entering the loop");
|
||||
state = 5;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
// coloredMsg(LOG_YELLOW, "mth, waiting");
|
||||
// coloredMsg(LOG_YELLOW, "mth, looping");
|
||||
if (! mqttLoop(&mqttClient)) {
|
||||
state = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 255:
|
||||
coloredMsg(LOG_YELLOW, "mth, error state, will stop here");
|
||||
schDel(mqttTestHandler, NULL);
|
||||
schDel(mqttLoopHandler, NULL);
|
||||
coloredMsg(LOG_YELLOW, "mth, trying again in one minute");
|
||||
schAdd(mqttTestHandler, NULL, 60000, 100);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user