peterhinch / micropython-mqtt

A 'resilient' asynchronous MQTT driver. Recovers from WiFi and broker outages.
MIT License
550 stars 117 forks source link

Can not access to ESP8266 if Wifi out of range #17

Closed vigorem closed 2 years ago

vigorem commented 4 years ago

Hi,

I've noticed that I could not upload to my board (ESP8266) if my wifi network was out of range.

ampy.pyboard
.PyboardError: could not exec command

If I come closer to the setup wifi, all works fine again. In some cases my boards are programmed on different wifi networks and I would have flash them do to recover access.

Best,

Sébastien

peterhinch commented 4 years ago

Your query seems to relate to ampy rather than to MQTT. I have no experience of ampy. As this is an Adafruit product you might be best asking on the Adafruit forum.

Alternatively you could try rshell which I use exclusively.

Regards, Pete

vigorem commented 4 years ago

The reason I asked here was that I suspected a blocking error in the micropython-mqtt if the wifi AP was not found.

I do not face any ampy issue in any other code or board I use.

It just happens when I run your library AND I'm out of wifi range.

peterhinch commented 4 years ago

Apologies - I misunderstood your query.

There is a known issue with MicroPython firmware in that DNS queries are blocking. There is a need for a nonblocking implementation of usocket.getaddrinfo. My MQTT library attempts to mitigate the blocking by doing the query once only after power up. This assumes that the initial power up occurs when within range. If the target moves out of range and then back in again, the stored broker address is used so there is no blocking.

Consequently if you power up the device when out of range you will experience blocking. This is regrettable but beyond the scope of something I can fix.

There is a hack if you're prepared to modify my code. I followed the guidelines in the docs for portability. If you're only ever going to connect to one network from ESP8266 devices you could replace the call to getaddrinfo with the result from calling it at the REPL.