Fixed infinit loop when MQTT broker closed

This commit is contained in:
RobinVdB8
2023-11-24 18:00:02 +01:00
parent 7fc1560bb7
commit e6dcbebdc8

View File

@@ -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) {