What makes WiFi config persistent?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
cpr
Posts: 11
Joined: Thu Mar 03, 2016 4:56 pm
Location: LDK, OWL @ .de

What makes WiFi config persistent?

Post by cpr » Mon Oct 31, 2016 8:12 pm

:?: If I follow the docs at http://docs.micropython.org/en/latest/e ... f-the-wifi and use

Code: Select all

def do_connect():
    import network
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        sta_if.connect('<essid>', '<password>')
        while not sta_if.isconnected():
            pass
    print('network config:', sta_if.ifconfig())
in my main.py
to connect to my WiFi,

this is what I get at the REPL by connectoing with screen /dev/ttyUSB0 115200:
scandone
no <essid> found, reconnect after 1s
reconnect
...
scandone
no <essid> found, reconnect after 1s
reconnect
I am (only) curious as what this makes the config persistent?
Is that some Espressif stuff?

Would I need to

Code: Select all

sta_if.active(False)
in some "shutdown" code to dsable this?

markxr
Posts: 62
Joined: Wed Jun 01, 2016 3:41 pm

Re: What makes WiFi config persistent?

Post by markxr » Mon Oct 31, 2016 9:13 pm

The API provided by the espressif firmware does this automatically when you call the function to set the config.

There is a second function which does not save the config, there is a big discussion in this pull request:

https://github.com/micropython/micropython/pull/2510

On how / whether to use it.

bitninja
Posts: 131
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: What makes WiFi config persistent?

Post by bitninja » Mon Oct 31, 2016 11:37 pm

I believe is actually implements it by writing the credentials to EEPROM. I seem to remember Arduino code that could manage it by reading/writing to the EEPROM.

Setting the STA interface to not be active will disable the constant trying to connect. All you have to do is re-enable it though (even after a reboot) and it will begin trying to connect again with the info stored in the EEPROM.

Anyway, it all seems to happen automatically... which ends up being convenient... at least for me!

User avatar
cemox
Posts: 32
Joined: Mon Oct 08, 2018 5:31 pm
Location: Turkey

Re: What makes WiFi config persistent?

Post by cemox » Thu Apr 30, 2020 8:25 am

Yesterday, I compiled the latest version of micropython for ESP8266 and I started seeing this annoying output in repl repeatedly:

Code: Select all

connected with Cisti, channel 1
dhcp client start...
ip:192.168.1.4,mask:255.255.255.0,gw:192.168.1.1
state: 5 -> 2 (22c0)
rm 0
reconnect
state: 2 -> 0 (0)
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 7
cnt 
I have to enter "ctrl + c" to access the repl promt. Pretty annoying. It was not the case with 1.12 version of binary. Any ideas about how to get rid of it or suppress it?

jomas
Posts: 50
Joined: Mon Dec 25, 2017 1:48 pm
Location: Netherlands

Re: What makes WiFi config persistent?

Post by jomas » Thu Apr 30, 2020 1:27 pm

cemox wrote:
Thu Apr 30, 2020 8:25 am
Yesterday, I compiled the latest version of micropython for ESP8266 and I started seeing this annoying output in repl repeatedly:

Code: Select all

connected with Cisti, channel 1
dhcp client start...
ip:192.168.1.4,mask:255.255.255.0,gw:192.168.1.1
state: 5 -> 2 (22c0)
rm 0
reconnect
state: 2 -> 0 (0)
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 7
cnt 
I have to enter "ctrl + c" to access the repl promt. Pretty annoying. It was not the case with 1.12 version of binary. Any ideas about how to get rid of it or suppress it?
See my post "jomas » Tue Apr 28, 2020 11:07 pm":
viewtopic.php?f=16&t=8234

bitninja
Posts: 131
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Re: What makes WiFi config persistent?

Post by bitninja » Thu Apr 30, 2020 10:12 pm

If you edit your boot.py you can un-comment the

Code: Select all

import esp
esp.osdebug(None)
lines and that will remove most of the messages. I still get one message when I connect but otherwise it stays quiet.

User avatar
cemox
Posts: 32
Joined: Mon Oct 08, 2018 5:31 pm
Location: Turkey

Re: What makes WiFi config persistent?

Post by cemox » Fri May 01, 2020 3:37 pm

Thank you, it works.

Post Reply