Page 1 of 1

What makes WiFi config persistent?

Posted: Mon Oct 31, 2016 8:12 pm
by cpr
:?: 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?

Re: What makes WiFi config persistent?

Posted: Mon Oct 31, 2016 9:13 pm
by markxr
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.

Re: What makes WiFi config persistent?

Posted: Mon Oct 31, 2016 11:37 pm
by bitninja
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!

Re: What makes WiFi config persistent?

Posted: Thu Apr 30, 2020 8:25 am
by cemox
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?

Re: What makes WiFi config persistent?

Posted: Thu Apr 30, 2020 1:27 pm
by jomas
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

Re: What makes WiFi config persistent?

Posted: Thu Apr 30, 2020 10:12 pm
by bitninja
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.

Re: What makes WiFi config persistent?

Posted: Fri May 01, 2020 3:37 pm
by cemox
Thank you, it works.