Page 1 of 1

Cannot set STA config after wakeup

Posted: Mon Sep 02, 2019 9:48 pm
by digitalchemy
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?

Re: Cannot set STA config after wakeup

Posted: Tue Sep 17, 2019 8:54 pm
by digitalchemy
Nobody has anything to say about this?
What happens to the wifi stack after reset?

Re: Cannot set STA config after wakeup

Posted: Tue Sep 17, 2019 9:21 pm
by kevinkk525
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.

Re: Cannot set STA config after wakeup

Posted: Wed Sep 18, 2019 12:07 am
by jimmo
digitalchemy wrote:
Mon Sep 02, 2019 9:48 pm
Does the ESP8266 somehow remeber the wireless configuration from previous project and load it up after wakeup by timer?
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 pm
while not wifi.isconnected():
wifi.connect("<my SSID>", "<my password>")
Is it necessary to call connect in the loop? Can you just call connect once, then loop until it connects (or times out?).

I'd be curious as to whether it's failing on the first call to connect or the subsequent ones.