So, I tested the master branch and dev branch in the firmware produced with NodeMCU custom builds (http://nodemcu-build.com/) upon the ESP8266 MCU.
And, I made a few tweaks in the code for connecting to the MQTT broker which I found here: https://github.com/nodemcu/nodemcu-firmware
These are the changes I made:
- removing the subscriber
- adding a loop of 100 messages around --> m:publish("/topic","hello",0,0, function(conn) print("sent") end)
And, this is how it looks like now:
-- init mqtt client with keepalive timer 120sec
m = mqtt.Client("clientid", 120, "user", "password")
m:on("connect", function(con) print ("connected") end)
m:on("offline", function(con) print ("offline") end)
-- m:connect( host, port, secure, auto_reconnect, function(client) )
-- for secure: m:connect("192.168.11.118", 1880, 1, 0)
-- for auto-reconnect: m:connect("192.168.11.118", 1880, 0, 1)
m:connect("192.168.11.118", 1880, 0, 0, function(conn) print("connected") end)
-- publish a message with data = hello, QoS = 0, retain = 0
local i = 1
while i < 10 do
m:publish("/topic","hello",0,0, function(conn) print("sent") end)
i = i + 1
end
m:close();
My message broker is the Eclipse Mosquitto and I have made sure to launch a subscriber on all topic #.
Although the messages are correct, but their arrival is very slow on the subscriber, like a delay of 1 second for each message.
Now, I've been trying to figure out why, but have come up with no luck yet.
So, I did a few experiments and came to a conclusion that the messages get stored in the form of a queue in the memory, which is then read by a timer that sends it through MQTT. Now, sending too many messages just increases this queue but fails in delivering the messages together. Moreover, just after a few messages get queued, the device reboots as if it crashed due to lack of memory.
Does anybody have a clue so as to what exactly is going on? My theory is just based on assumptions as of now.