From 5d169b59459e9d5d7fa296b1f424eb8ab950f53f Mon Sep 17 00:00:00 2001 From: Tom K Date: Fri, 26 Mar 2021 08:57:49 +1100 Subject: [PATCH] Gracefully disconnect MQTT (#23) * Gracefully disconnect MQTT * Add MG_F_SEND_AND_CLOSE flag to disconnect --- src/mgos_mqtt_conn.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mgos_mqtt_conn.c b/src/mgos_mqtt_conn.c index def9513..d438804 100644 --- a/src/mgos_mqtt_conn.c +++ b/src/mgos_mqtt_conn.c @@ -490,7 +490,8 @@ void mgos_mqtt_conn_disconnect(struct mgos_mqtt_conn *c) { if (c == NULL) return; c->reconnect_timeout_ms = -1; // Prevent reconnect. if (c->nc != NULL) { - c->nc->flags |= MG_F_CLOSE_IMMEDIATELY; + mg_mqtt_disconnect(c->nc); + c->nc->flags |= MG_F_SEND_AND_CLOSE; } }