mirror of
https://github.com/espressif/esp-mqtt.git
synced 2025-08-02 20:25:10 +02:00
implemented disconnected callback
This commit is contained in:
@@ -44,8 +44,7 @@ typedef struct mqtt_settings {
|
||||
mqtt_write_callback write_cb;
|
||||
|
||||
mqtt_event_callback connected_cb;
|
||||
mqtt_event_callback disconnected_cb; // unused
|
||||
mqtt_event_callback reconnect_cb; // unused
|
||||
mqtt_event_callback disconnected_cb;
|
||||
|
||||
mqtt_event_callback subscribe_cb;
|
||||
mqtt_event_callback publish_cb;
|
||||
|
11
mqtt.c
11
mqtt.c
@@ -498,8 +498,12 @@ void mqtt_task(void *pvParameters)
|
||||
mqtt_info("Connected to server %s:%d", client->settings->host, client->settings->port);
|
||||
if (!mqtt_connect(client)) {
|
||||
client->settings->disconnect_cb(client);
|
||||
|
||||
if (client->settings->disconnected_cb) {
|
||||
client->settings->disconnected_cb(client, NULL);
|
||||
}
|
||||
|
||||
continue;
|
||||
//return;
|
||||
}
|
||||
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);
|
||||
@@ -511,13 +515,16 @@ void mqtt_task(void *pvParameters)
|
||||
mqtt_start_receive_schedule(client);
|
||||
|
||||
client->settings->disconnect_cb(client);
|
||||
if (client->settings->disconnected_cb) {
|
||||
client->settings->disconnected_cb(client, NULL);
|
||||
}
|
||||
|
||||
vTaskDelete(xMqttSendingTask);
|
||||
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||
|
||||
}
|
||||
mqtt_destroy(client);
|
||||
|
||||
|
||||
}
|
||||
|
||||
mqtt_client *mqtt_start(mqtt_settings *settings)
|
||||
|
Reference in New Issue
Block a user