From b0a30bf216bf3126b2af8f3f3b89153d14a53450 Mon Sep 17 00:00:00 2001 From: Simone Orru Date: Wed, 26 Jun 2024 11:50:51 +0200 Subject: [PATCH] Disconnect before callback Signed-off-by: Simone Orru --- lib/astarte_device_sdk/device.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/astarte_device_sdk/device.c b/lib/astarte_device_sdk/device.c index 2d78b1b4..4dece7b3 100644 --- a/lib/astarte_device_sdk/device.c +++ b/lib/astarte_device_sdk/device.c @@ -278,6 +278,8 @@ static void on_disconnected_handler(astarte_mqtt_t *astarte_mqtt) { struct astarte_device *device = CONTAINER_OF(astarte_mqtt, struct astarte_device, astarte_mqtt); + device->connection_state = DEVICE_DISCONNECTED; + if (device->disconnection_cbk) { astarte_device_disconnection_event_t event = { .device = device, @@ -286,8 +288,6 @@ static void on_disconnected_handler(astarte_mqtt_t *astarte_mqtt) device->disconnection_cbk(event); } - - device->connection_state = DEVICE_DISCONNECTED; } static void on_incoming_handler(astarte_mqtt_t *astarte_mqtt, const char *topic, size_t topic_len,