From e6dcbebdc8ffb9958884a1675ec46fd52a4ef932 Mon Sep 17 00:00:00 2001 From: RobinVdB8 Date: Fri, 24 Nov 2023 18:00:02 +0100 Subject: [PATCH] Fixed infinit loop when MQTT broker closed --- project/Core/Src/mug.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/project/Core/Src/mug.c b/project/Core/Src/mug.c index 002cc7b..160560c 100644 --- a/project/Core/Src/mug.c +++ b/project/Core/Src/mug.c @@ -30,6 +30,7 @@ static uint32_t color_picker(char*); static sFONT* font; static uint16_t xpos; static uint16_t ypos; +static uint16_t connection_attempt_counter; static uint32_t color; static uint32_t bgcolor; static int inpub_id; @@ -190,8 +191,12 @@ static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection } else { LOG_INFO(TAG, "mqtt_connection_cb: Disconnected, reason: %d", status); - //try to reconnect - mosquitto_connect(client); + while (connection_attempt_counter < 50) { + connection_attempt_counter++; + //try to reconnect + mosquitto_connect(client); + } + } } @@ -230,6 +235,7 @@ void mug_init(void) { font = LCD_FONT16; xpos = 50; ypos = 50; + connection_attempt_counter = 0; mqtt_client_t *client = mqtt_client_new(); if (client != NULL) {