From f99c9b5ac6103207651dcd740c5f0122c18b9f7b Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Thu, 28 Mar 2019 19:19:49 -0500 Subject: [PATCH] mqttbutton: Fix MQTT disconnect handler When the MQTT disconnect handler is called, it would crash the microcontroller because it was attempting to call `close` on a nil value `client`. This was supposed to have been `mqtt_client`. Immediately calling the WiFi timer callback is also a problem, as it effectively puts the microcontroller into a busy loop if the WiFi is already connected but the MQTT broker is unavailable. Adding a 1 second delay here should prevent crashing in this case. --- mqttbutton.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mqttbutton.lua b/mqttbutton.lua index 757c318..99bead4 100644 --- a/mqttbutton.lua +++ b/mqttbutton.lua @@ -43,8 +43,8 @@ end function on_mqtt_disconnected(client) print("MQTT Disconnected") - client:close() - on_wifi_timer() + mqtt_client:close() + tmr.alarm(WIFI_TIMER_ID, 1000, 0, on_wifi_timer) end function on_wifi_connected()