-
I'm trying to add light sleep to a polling loop for a wifi sensor but there appears to be some issue with the device either crashing or just not waking up from sleep after a seemingly random number of packets. A stripped down version of my loop that I've been using as a test case is just this:
wlan.send_udp just wraps sock.sendto, encoding the object passed to it in JSON and then sending out the message over UDP. The socket options are (socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP). Aside from the device stopping sending packets and apparently crashing, the interval itself is not that consistent - sometimes it will send two packets in quick sequence, with an interval much shorter than the lightsleep timeout (looks like the previous one has been buffered). My suspicion is that there's an underlying RTOS background task involving the wifi send that's not completed before it goes to sleep, and this is causing it to sometimes buffer packets until next wake, and sometimes just crash due to an inconsistent wifi state. The board I'm using has 2 USB serial, micropython REPL is using the built in USB serial endpoint on the C3 and the other is connected to the C3 UART; I've looked at what's coming off the secondary (UART) one during the crash since it does print boot messages to this port, and I don't see any messages indicating a failure/exception at a level below python. I've also instrumented this loop with a LED blink, and the LED stops blinking with the packets ending, indicating that the device is either crashing or never waking up. The micropython version string is: So with that context I have a few questions:
Addendum: Anyway, it appears this is more of a "not coming out of sleep on time" issue rather than a crash, which at least explains why I didn't see any exception or reboot messages. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I suspect the forced Maybe you will get better results when you allow the RTOS/WIFI to control lightsleep using the WIFI power save options (see e.g. PR #8993 or #6774 - you will need to merge them yourself + build micropython, as these patches aren't merged yet). |
Beta Was this translation helpful? Give feedback.
I suspect the forced
lightsleep()
might do something to your WLAN connection. The ESP WIFI will most likely need to do something to maintain the connection to your AP. WIFI disconnects might be hidden by the automatic reconnect built into micropython (which I consider as a bug on it's own).Maybe you will get better results when you allow the RTOS/WIFI to control lightsleep using the WIFI power save options (see e.g. PR #8993 or #6774 - you will need to merge them yourself + build micropython, as these patches aren't merged yet).