From 77e83a3d4434df4accf4d8e3df62950c629f46a6 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Fri, 13 Nov 2020 14:22:26 +0100 Subject: [PATCH] publish something --- cube/User/Src/mqttTest.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cube/User/Src/mqttTest.c b/cube/User/Src/mqttTest.c index 0c97c0b..2ba936c 100644 --- a/cube/User/Src/mqttTest.c +++ b/cube/User/Src/mqttTest.c @@ -9,7 +9,7 @@ #include #include #include - +#include extern const uint8_t MQTT_SOCK; @@ -26,6 +26,10 @@ static void mqttCallback(char *topic, uint8_t *payload, uint16_t payloadLength) } +void mqttLoopHandler(void *handle) { + mqttLoop(&mqttClient); +} + void mqttTestHandler(void *handle) { static uint8_t state = 0; static uint8_t message[] = "Hello world\n\r"; @@ -55,14 +59,26 @@ void mqttTestHandler(void *handle) { break; case 2: - coloredMsg(LOG_YELLOW, "mth, waiting"); - + coloredMsg(LOG_YELLOW, "mth, start mqtt loop"); + schAdd(mqttLoopHandler, NULL, 0, 100); + 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); + state = 4; + break; + + case 4: + coloredMsg(LOG_YELLOW, "mth, waiting"); + break; case 255: coloredMsg(LOG_YELLOW, "mth, error state, will stop here"); schDel(mqttTestHandler, NULL); + schDel(mqttLoopHandler, NULL); break; } } else {