Hello, I ran into issue trying to reconnect to wifi with my ESP8266 after waking up from deep sleep.
My code looks like this:
import network
import urequests
import machine
rtc = machine.RTC()
rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)
wifi = network.WLAN(network.STA_IF)
wifi.active(True)
while not wifi.isconnected():
wifi.connect("<my SSID>", "<my password>")
# do some requests an display the responses on display
wifi.disconnect()
wifi.active(False)
rtc.alarm(rtc.ALARM0, 600000)
machine.deepsleep()
When the code statrts executing after boot everything works fine. But when the board wakes up from the sleep it raises:
OSError: Cannot set STA config
and it insists the error happens on the line where wifi.connect() is called.
Also, I noticed that the AP interface automaticaly activates after the wakeup, although I never called for it in my code (in this project).
My uPython version is v1.11-8-g48dcbbe60.
What am I doing wrong?
Does the ESP8266 somehow remeber the wireless configuration from previous project and load it up after wakeup by timer?
Cannot set STA config after wakeup
-
- Posts: 2
- Joined: Mon Sep 02, 2019 9:20 pm
Re: Cannot set STA config after wakeup
Nobody has anything to say about this?
What happens to the wifi stack after reset?
What happens to the wifi stack after reset?
-
- Posts: 969
- Joined: Sat Feb 03, 2018 7:02 pm
Re: Cannot set STA config after wakeup
I can't say why it doesn't work but I can say that I do not know why you disable the wifi before going to deep sleep. In deep sleep wifi is disabled anyway. And when it wakes up from deepsleep, the esp8266 will automatically reconnect.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode
Re: Cannot set STA config after wakeup
Yes, this is unique to the ESP8266 though. I believe it even does this after full power off. The other ports don't do this.digitalchemy wrote: ↑Mon Sep 02, 2019 9:48 pmDoes the ESP8266 somehow remeber the wireless configuration from previous project and load it up after wakeup by timer?
Is it necessary to call connect in the loop? Can you just call connect once, then loop until it connects (or times out?).digitalchemy wrote: ↑Mon Sep 02, 2019 9:48 pmwhile not wifi.isconnected():
wifi.connect("<my SSID>", "<my password>")
I'd be curious as to whether it's failing on the first call to connect or the subsequent ones.