MQTT on Esp8266
MQTT on Esp8266
Hey I wanted to play a little with MQTT and Adafruit.IO, as I'm building some sensors for my home. But when I import "umqtt" library it looks empty... (help(umqtt) lists only __name__ and __path__ there) Tried to use library made for CirquitPython (Adafruit version of MicroPython) but lib don't work correctly - throws some errors on standard MicroPython. Is there any other library that I can use?
Re: MQTT on Esp8266
You need to choose between umqtt.simple and umqtt.robust, which are modules within umqtt, although maintained as separate subdirectories at micropython-lib.
https://github.com/micropython/micropyt ... qtt.simple
https://github.com/micropython/micropyt ... qtt.robust
If you are in a position to experiment with a more complex build, you could try mqtt_as from...
https://github.com/peterhinch/micropython-mqtt
https://github.com/micropython/micropyt ... qtt.simple
https://github.com/micropython/micropyt ... qtt.robust
If you are in a position to experiment with a more complex build, you could try mqtt_as from...
https://github.com/peterhinch/micropython-mqtt
Re: MQTT on Esp8266
Thank you : )
Just few minutes before reading your answer found info about mqtt.simple and mqtt.robust.
Anyway, in the meantime, I have created (very simple) communication between my modules and Mac in python using sockets and simple messages - it works, so no need for mqtt - for now at least.
Just few minutes before reading your answer found info about mqtt.simple and mqtt.robust.
Anyway, in the meantime, I have created (very simple) communication between my modules and Mac in python using sockets and simple messages - it works, so no need for mqtt - for now at least.
Re: MQTT on Esp8266
Hi, I'm using simple and robust micropython implementation, as posted above on a WiPy3, using Aedes as MQTT broker. I noticed that after around 30 minutes, I'm not able to send messages to my broker anymore.
Since I thought it could be a case of disconnection (even if I haven't seen nor any reconnection message neither any other type of error, both on client side and server side), I tried to play with keepAlive option, specifying a value greater than 0, but I haven't spotted any difference even specifying 3600. To be more precise, I just replaced 0 with 3600 here in the constructor (https://github.com/micropython/micropyt ... ple.py#L10).
This behavior is present in a real application, where my device is at home and the broker is deployed on Amazon, I never saw any problem in local.
I thought that "check_msg" method would be enough to maintain the connection, but at the moment it seems that the only one is to publish a message to the broker.
Do you have any advice?
Thanks.
Since I thought it could be a case of disconnection (even if I haven't seen nor any reconnection message neither any other type of error, both on client side and server side), I tried to play with keepAlive option, specifying a value greater than 0, but I haven't spotted any difference even specifying 3600. To be more precise, I just replaced 0 with 3600 here in the constructor (https://github.com/micropython/micropyt ... ple.py#L10).
This behavior is present in a real application, where my device is at home and the broker is deployed on Amazon, I never saw any problem in local.
I thought that "check_msg" method would be enough to maintain the connection, but at the moment it seems that the only one is to publish a message to the broker.
Do you have any advice?
Thanks.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: MQTT on Esp8266
The official MQTT libraries don't ping the broker*. The broker should be sent a ping or a publication at least once in the keepalive period, otherwise when the keepalive period expires the broker assumes the connection has failed. It then sends the last will and closes the connection.
So, to use the official libraries with a permanently open connection, you need to issue regular publications. Given the inherent imperfection of wireless links I favour sending publications about three times per keepalive period to keep the link open.
However this doesn't explain why your connection is going down after 30 minutes when the keepalive period is an hour. Debugging this might be easier if you used the last will feature: you'd then get positive confirmation that the broker was downing the connection.
* This resilient asynchronous library does ping the broker.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: MQTT on Esp8266
[quote=pythoncoder post_id=25446 time=1518601410 user_id=265]
However this doesn't explain why your connection is going down after 30 minutes when the keepalive period is an hour. Debugging this might be easier if you used the last will feature: you'd then get positive confirmation that the broker was downing the connection.
* This [url=https://github.com/peterhinch/micropython-mqtt.git]resilient asynchronous[/url] library does ping the broker.
[/quote]
Thanks, I can't explain it too, I'll use the last will feature. It's not clear if there's some settings issue with my broker, I'll try also to investigate more about it.
However this doesn't explain why your connection is going down after 30 minutes when the keepalive period is an hour. Debugging this might be easier if you used the last will feature: you'd then get positive confirmation that the broker was downing the connection.
* This [url=https://github.com/peterhinch/micropython-mqtt.git]resilient asynchronous[/url] library does ping the broker.
[/quote]
Thanks, I can't explain it too, I'll use the last will feature. It's not clear if there's some settings issue with my broker, I'll try also to investigate more about it.