MQTT Client disconnections
Posted: Fri May 08, 2015 6:28 pm
Hello all,
After reading up about MQTT, I decided to implement a small test with my ESP-01 module. I downloaded the Mosquito broker version 1.4.1 for Windows and got that running successfully. Next, I wrote a simple MQTT client program for the ESP itself, and another for my laptop. The test was supposed to be a simple ping-pong parlay: laptop publishes a message to the /ping topic which the ESP is subscribed to, and the ESP (on receiving a message from the /ping topic) publishes to the /pong topic which the laptop is subscribed to. The laptop logs the reception, waits for 30 seconds and sends another message on the /ping topic....
Àfter about five minutes, the MQTT client on the ESP goes offline for no apparent reason. This happened each time I ran the test. I then increased the delay between pings to 60 seconds, and now the MQTT client on the ESP goes offline at about 727 seconds consistently. I can still send commands to the ESP and receive replies after the disconnection, and heap size is usually around 16.5k when the disconnection happens.
I'd really appreciate any help with this. The broker also simply reports a socket error with the ESP client and subsequently disconnects it.
The lua code is given below:
After reading up about MQTT, I decided to implement a small test with my ESP-01 module. I downloaded the Mosquito broker version 1.4.1 for Windows and got that running successfully. Next, I wrote a simple MQTT client program for the ESP itself, and another for my laptop. The test was supposed to be a simple ping-pong parlay: laptop publishes a message to the /ping topic which the ESP is subscribed to, and the ESP (on receiving a message from the /ping topic) publishes to the /pong topic which the laptop is subscribed to. The laptop logs the reception, waits for 30 seconds and sends another message on the /ping topic....
Àfter about five minutes, the MQTT client on the ESP goes offline for no apparent reason. This happened each time I ran the test. I then increased the delay between pings to 60 seconds, and now the MQTT client on the ESP goes offline at about 727 seconds consistently. I can still send commands to the ESP and receive replies after the disconnection, and heap size is usually around 16.5k when the disconnection happens.
I'd really appreciate any help with this. The broker also simply reports a socket error with the ESP client and subsequently disconnects it.
The lua code is given below:
Code: Select all
wifi.start.connect()
tmr.delay(2000000)
function handle publish(conn,topic,data)
if data~=nil then
print(data)
m:publish ("/pong”,"hollerback",0,0,function(conn) print("Pong") end)
end
end
m=MQTT.Client("esp",120,”user","pass")
m:on("message”, handlepublish)
m:connect("192.168.1.168", 1883,0,function(conn) print("Connected") end)
m:subscribe("/ping",0,function(conn) print("Subscribe success") end)
m:on("offline", function(conn) print("Offline") end)