Cannot set STA config after wakeup

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
digitalchemy
Posts: 2
Joined: Mon Sep 02, 2019 9:20 pm

Cannot set STA config after wakeup

Post by digitalchemy » Mon Sep 02, 2019 9:48 pm

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?

digitalchemy
Posts: 2
Joined: Mon Sep 02, 2019 9:20 pm

Re: Cannot set STA config after wakeup

Post by digitalchemy » Tue Sep 17, 2019 8:54 pm

Nobody has anything to say about this?
What happens to the wifi stack after reset?

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: Cannot set STA config after wakeup

Post by kevinkk525 » Tue Sep 17, 2019 9:21 pm

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

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Cannot set STA config after wakeup

Post by jimmo » Wed Sep 18, 2019 12:07 am

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.

Post Reply