Fastest WLAN connect with AP fallback

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
User avatar
Posts: 142
Joined: Sat Jan 07, 2017 1:52 am
Location: Singapore / Cornwall

Fastest WLAN connect with AP fallback

Post by devnull » Thu Feb 23, 2017 12:41 pm

Does anyone have a faster, more concise, low RAM WLAN connection routine that falls back to AP mode if it can't connect to the wlan ?

Code: Select all

def connect(timeout=10,ssid=None,passkey=None):
	from network import WLAN,STA_IF, AP_IF
	sta = WLAN(STA_IF)
	if not sta.isconnected():
        from time import sleep_ms
        for count in range(timeout*10):
        	if sta.isconnected(): break
        if not sta.isconnected():
        	sta = WLAN(AP_IF)	
	print('Connect msec:',count*100,'ifconfig:',sta.ifconfig())
	return sta

wl = connect(timeout=5,ssid='wlan@mywan',passkey='mypass')

Post Reply