From b2167bdf3ae69aca6f53ac5abf1eec04b613d8a0 Mon Sep 17 00:00:00 2001 From: Antoine Date: Thu, 1 Oct 2015 22:18:30 +0200 Subject: [PATCH] mqtt:close() send the DISCONNECT message (fix #673) --- app/modules/mqtt.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/modules/mqtt.c b/app/modules/mqtt.c index b6d73725..65caf0ac 100644 --- a/app/modules/mqtt.c +++ b/app/modules/mqtt.c @@ -1034,7 +1034,14 @@ static int mqtt_socket_close( lua_State* L ) if(mud->pesp_conn == NULL) return 0; - // call mqtt_disconnect() + // Send disconnect message + mqtt_message_t* temp_msg = mqtt_msg_disconnect(&mud->mqtt_state.mqtt_connection); + NODE_DBG("Send MQTT disconnect infomation, data len: %d, d[0]=%d \r\n", temp_msg->length, temp_msg->data[0]); + if(mud->secure) + espconn_secure_sent(mud->pesp_conn, temp_msg->data, temp_msg->length); + else + espconn_sent(mud->pesp_conn, temp_msg->data, temp_msg->length); + mud->mqtt_state.auto_reconnect = 0; // stop auto reconnect. #ifdef CLIENT_SSL_ENABLE