diff --git a/include/mqtt.h b/include/mqtt.h index 0c88cde..3ff5ccf 100644 --- a/include/mqtt.h +++ b/include/mqtt.h @@ -62,6 +62,7 @@ typedef struct mqtt_settings { uint32_t lwt_retain; uint32_t clean_session; uint32_t keepalive; + bool auto_reconnect; } mqtt_settings; typedef struct mqtt_event_data_t diff --git a/mqtt.c b/mqtt.c index f87d64f..e5567b8 100644 --- a/mqtt.c +++ b/mqtt.c @@ -503,7 +503,11 @@ void mqtt_task(void *pvParameters) client->settings->disconnected_cb(client, NULL); } - continue; + if (!client->settings->auto_reconnect) { + break; + } else { + continue; + } } mqtt_info("Connected to MQTT broker, create sending thread before call connected callback"); xTaskCreate(&mqtt_sending_task, "mqtt_sending_task", 2048, client, CONFIG_MQTT_PRIORITY + 1, &xMqttSendingTask); @@ -520,6 +524,9 @@ void mqtt_task(void *pvParameters) } vTaskDelete(xMqttSendingTask); + if (!client->settings->auto_reconnect) { + break; + } vTaskDelay(1000 / portTICK_RATE_MS); }