Is wifi.persistent implemented?

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
shellian.systems
Posts: 3
Joined: Thu Dec 20, 2018 2:50 pm

Is wifi.persistent implemented?

Post by shellian.systems » Thu Dec 20, 2018 3:19 pm

Hi Folks,

I've searched the forums and noted some discussions back in 2016 about issues and challenges disabling the wifi credential persistent storage on the esp8266. I know over in the arduino world that the function WiFi.persistent(false) exists to disable the constant writing of the credentials to flash, and save wearing out the flash. I don't see anything equivalent in the micropython references, unless I'm missing it somewhere.

There are definitely use cases for this functionality and it would be valuable I believe to have it in micropython if it's possible. In my own case, I have a device that powers up multiple times per day, I pass it a static ip address and wifi credentials in code, so there is no need to needlessly write flash every time.

Please advise.

Thank you very much!
Brian

User avatar
pythoncoder
Posts: 3509
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Is wifi.persistent implemented?

Post by pythoncoder » Sat Dec 22, 2018 6:57 am

By default the ESP8266 remembers its connection, so if you always connect to the same network you only ever need to update the flash once. Power cycle it: a few seconds after power up it will reconnect without running any code. You can check this by using the isconnected() method of station interface (assuming you're using that mode).
Peter Hinch

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

Re: Is wifi.persistent implemented?

Post by kevinkk525 » Sat Dec 22, 2018 9:11 am

I think the question was if having network.connect("SSID","PASSPHRASE") will write the credentials to flash every time it is called as this would be a waste of flash cycles as the credentials are already stored on the flash. Therefore he's asking for a method to disable saving the credentials to the flash generally, resulting in the need to call network.connect() with credentials every time as the device does not remember them.

User avatar
pythoncoder
Posts: 3509
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Is wifi.persistent implemented?

Post by pythoncoder » Sat Dec 22, 2018 9:32 am

OK, the approach I use is to pause after power-up for a period to allow it to connect automatically. If, at the end, isconnected() returns False, then connect with specific credentials.
Peter Hinch

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

Re: Is wifi.persistent implemented?

Post by kevinkk525 » Sat Dec 22, 2018 11:03 am

Sounds like a reasonable workaround.

shellian.systems
Posts: 3
Joined: Thu Dec 20, 2018 2:50 pm

Re: Is wifi.persistent implemented?

Post by shellian.systems » Sat Dec 22, 2018 12:42 pm

Thank you pythoncoder and kevinkk525 for your comments and ideas.

In my use case, and a few other designs I have seen, the wifi is not necessarily needed initially as there is nothing significant to report to a server somewhere. In my case, I disable radio at boot to conserve precious battery power. When it is time to connect, I may be connecting to any one of a few available AP's in the environment depending on the nature of the data needing to be reported. Thus, the st_if.connect(ssid,password) may be different from boot to boot. Obviously, I make those decisions in code and make the appropriate connection as needed, passing the needed credentials. I feel it would be valuable to be able to disable that constant flash write in micropython too to preserve the module.

I'm not whining about the micropython equivalent function not existing. If I had the lower level skills necessary to port functions like that, I would give it a go, but, I don't...yet ;) But, if anyone is so inclined to do so, I'm just saying that there are valuable use cases for it.

Cheers,
Brian

User avatar
pythoncoder
Posts: 3509
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Is wifi.persistent implemented?

Post by pythoncoder » Sat Dec 22, 2018 5:40 pm

Fair point.
Peter Hinch

flywire
Posts: 22
Joined: Wed Jan 02, 2019 7:08 am

Re: Is wifi.persistent implemented?

Post by flywire » Fri Jan 04, 2019 7:09 am

I am having problems maintaining a persistent connection so I can use WebREPL

boot.py

Code: Select all

# This file is executed on every boot (including wake-boot from deepsleep)
import esp
esp.osdebug(None)
import uos, machine
uos.dupterm(machine.UART(0, 115200), 1)
import wifi_connect_stn
wifi_connect_stn()
import gc
import webrepl
webrepl.start()
gc.collect()
wifi_connect_stn.py (with my network details removed):

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)
        wlan.connect('essid', 'password')
        while not sta_if.isconnected():
            pass
    print('network config:', sta_if.ifconfig())

do_connect()

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

Re: Is wifi.persistent implemented?

Post by kevinkk525 » Fri Jan 04, 2019 7:30 am

Sorry, your post is off-topic here. Please open your own thread.

shellian.systems
Posts: 3
Joined: Thu Dec 20, 2018 2:50 pm

Re: Is wifi.persistent implemented?

Post by shellian.systems » Fri Jan 04, 2019 11:34 am

Hi Flywire,
As kevinkk525 mentioned, we are discussing a different "persistent" here. Not a persistent network connection, but rather maintaining network credentials in flash persistently.

That said, I don't see anything in your code sample that should not work in terms of connecting to a network, so if your network connection is dropping out, I would say the problem would be environmental...distance to access point, obstructions, interference, router issue, etc, etc.

Perhaps you want to focus on those things for your trouble shooting.
Good luck.
Brian





flywire wrote:
Fri Jan 04, 2019 7:09 am
I am having problems maintaining a persistent connection so I can use WebREPL

boot.py

Code: Select all

# This file is executed on every boot (including wake-boot from deepsleep)
import esp
esp.osdebug(None)
import uos, machine
uos.dupterm(machine.UART(0, 115200), 1)
import wifi_connect_stn
wifi_connect_stn()
import gc
import webrepl
webrepl.start()
gc.collect()
wifi_connect_stn.py (with my network details removed):

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)
        wlan.connect('essid', 'password')
        while not sta_if.isconnected():
            pass
    print('network config:', sta_if.ifconfig())

do_connect()

Post Reply