Page 1 of 1

Realiable WiFi using PYBD

Posted: Thu Jul 25, 2019 10:24 pm
by agners
Hi MicroPython community,

First, thanks for making something awesome as MicroPython happen! It really makes my software engineer heart really warm and cozy!

I use my SF2W since some weeks to log data to a MQTT server. This works nice and rather reliably. However, when my WiFi disappears my Python script gets stuck and remains so after connecting. I tried to make it more reliable, but was not really able to.

I tried with something like this in my main loop:

[code]
if not wl.isconnected():
errled.on()
wl.disconnect()
wl.connect(...)
while not wl.isconnected():
time.sleep_ms(200)
[/code]

However, from what I can see wl.isconnected() never gets True in those situation.

Enabling tracing seems to indicate that the lower layer connects, but it seems not to be reflected on the Python API:

[code]
[ 884015] ASYNC(0000,32,0,0,0)
[ 884018] ASYNC(0000,ASSOC_REQ_IE,0,0,0)
[ 884018] ASYNC(0000,AUTH,0,0,0)
[ 884040] ASYNC(0000,ASSOC_RESP_IE,0,0,0)
[ 884040] ASYNC(0000,9,0,0,0)
[ 884040] ASYNC(0001,LINK,0,0,0)
[ 884049] ASYNC(0000,PSK_SUP,6,0,0)
[ 884114] ASYNC(0000,JOIN,0,0,0)
[ 884115] ASYNC(0000,125,0,0,0)

>>> wl.status()
-2
>>> [ 888723] ETHRX len=152 dst=... src=.... type=IPv4 srcip=.... dstip=..

>>> wl.isconnected()
False
[/code]

I also found this which claims that PYBD should automatically reconnect:
https://github.com/peterhinch/micropyth ... /pyboard_d

This seems not true/have issues?

Banner says I am using:
MicroPython v1.10-445-ga9b1d3ca3 on 2019-05-29; PYBD_SF2W with STM32F722IEK

Which I think is the latest version? (at least banner did not change after reflashing some minutes ago. But *please* add version information to the PYBD builds in your downloads section...)

Best regards,
Stefan

Re: Realiable WiFi using PYBD

Posted: Fri Jul 26, 2019 5:17 pm
by pythoncoder
There are two issues here. Firstly there is this Pyboard D issue which is still outstanding.
tl;dr the Pyboard D can get into a state where a connection is lost and can only be regained by a reset. This is a bug which will doubtless be fixed.

You haven't said what library you are using for MQTT. The official library responds badly to WiFi outages (regardless of platform). The general issues are discussed here.

There is a resilient MQTT implementation here.