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 sFONT* font;
static uint16_t xpos; static uint16_t xpos;
static uint16_t ypos; static uint16_t ypos;
static uint16_t connection_attempt_counter;
static uint32_t color; static uint32_t color;
static uint32_t bgcolor; static uint32_t bgcolor;
static int inpub_id; static int inpub_id;
@@ -190,9 +191,13 @@ static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection
} else { } else {
LOG_INFO(TAG, "mqtt_connection_cb: Disconnected, reason: %d", status); LOG_INFO(TAG, "mqtt_connection_cb: Disconnected, reason: %d", status);
while (connection_attempt_counter < 50) {
connection_attempt_counter++;
//try to reconnect //try to reconnect
mosquitto_connect(client); mosquitto_connect(client);
} }
}
} }
/** /**
@@ -230,6 +235,7 @@ void mug_init(void) {
font = LCD_FONT16; font = LCD_FONT16;
xpos = 50; xpos = 50;
ypos = 50; ypos = 50;
connection_attempt_counter = 0;
mqtt_client_t *client = mqtt_client_new(); mqtt_client_t *client = mqtt_client_new();
if (client != NULL) { if (client != NULL) {