PICO W - lightsleep not working after cyw43_deinit #10889
Replies: 8 comments 10 replies
-
OK, I continued to poke around in the micropython source code. I have a better fix (I think).
I would still like to have an expert comment before I create a pull request. |
Beta Was this translation helpful? Give feedback.
-
I'm not an expert but am trying to build a similar project to yours, here: ghubcoder#8 (comment) Jmodrako found a solution in micropython, the difference being that after wlan.deinit() he adds wlan = None |
Beta Was this translation helpful? Give feedback.
-
if (cyw43_has_pending && (cyw43_poll != NULL)) Last summer I made a garden Pico Solar and everything was working but with the last release it wasn't! I did recompile the most recent github code and change the line 148 with this modification and then it works! daniel@linuxserver:~$ mosquitto_sub -t "#" -v | xargs -d$'\n' -L1 bash -c 'date "+%Y-%m-%d %T $0"' |
Beta Was this translation helpful? Give feedback.
-
I created a pull request with the change to modmachine.c. But, it turns out some else already had a pull request in the queue with the same fix. I learned a lesson, next time I find a bug I need to look for an existing pull request. |
Beta Was this translation helpful? Give feedback.
-
That PR exists already #10803 . |
Beta Was this translation helpful? Give feedback.
-
Tried many different scripts on V1.20 and the latest nightly build, but can not get the Pico W to go into lightsleep. Thanks |
Beta Was this translation helpful? Give feedback.
-
It seems already fixed/committed 3 days ago. |
Beta Was this translation helpful? Give feedback.
-
I did test to confirm that lightsleep does work correctly while wifi chip is disabled.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to build a small app to run from battery with minimum power.
I want to power down the cyw43 wifi module when I don't need it.
I found a recipe to do that as follows.
In a loop I:
do my networking (MQTT). No issues here.
shutdown the wifi connection using:
I have a USB power meter and I see a significant drop in power when wlan.deinit() happens.
It seems the cyw43 is powered down.
Also, if I turn the LED on, when I call wlan.deinit() the LED is turned off.
BTW, whoever implemented deinit() did a good job.
After calling deinit() if I turn on the PICO_W LED or access any other GPIO connected to the cyw43 it just works.
Restarting wifi works top.
The cyw43 is powered up.
After shutting down the wifi connection I call time.sleep_ms(60000) to sleep for a minute.
When it returns the loop starts again and wifi is re-initialized.
On the other hand, using machine.lightsleep(60000) instead of time.sleep_ms() I have a problem.
lightsleep() returns immediately.
I looked at the micropython source code. In the implementation for lightsleep (modmachine.c):
I added an mp_printf to the body of the if statement and confirmed cyw43_has_pending is set.
I think the solution is that either wlan.active(False) or wlan.deinit() should clear cyw43_has_pending.
As an experiment, I modified network_cyw43_deinit() in network_cyw43.c to clear cyw43_has_pending.
This fixed my problem with lightsleep().
IMO, this is not a good fix. The variable cyw43_has_pending is defined in ports/rp2 and only used there.
network_cyw43.c is used for both ports/rp2 and ports/esp32.
I'm new to micropython and github (but not git).
I am willing to prepare a proper fix and submit a pull request.
But I would like some advice from and expert before I proceed.
Beta Was this translation helpful? Give feedback.
All reactions