micropython-esp32 icon indicating copy to clipboard operation
micropython-esp32 copied to clipboard

add WPS support

Open jhgoebbert opened this issue 7 years ago • 1 comments

This adds WPS support. In Python WPS can be used like this:

from network import WLAN,STA_IF
from network import STA_WPS_PROBING, STA_WPS_SUCCESS, STA_WPS_FAILED, STA_WPS_TIMEOUT
from time import sleep

wlan = WLAN(STA_IF) # get current object, without changing the mode
wlan.active(True)

wlan.start_wps()
while wlan.status() == STA_WPS_PROBING:
    print("probing with WPS")
	sleep(0.5)
	
if wlan.status() == STA_WPS_SUCCESS:
    print("WPS successful")
	print("   ESSID:    ", wlan.config('essid')
	print("   Password: ", wlan.config('password')
	
	# connect using these credentials
	wlan.connect(wlan.config('essid'), wlan.config('password'))
	print("Waiting for connection...")
    while not wlan.isconnected():
        idle() # save power while waiting
    print("Connected.")
	
elif wlan.status() == STA_WPS_FAILED:
    print("WPS failed")
	# attention: triggers disconnect event (which results in a reconnect with last essid/passwd)
	
elif wlan.status() == STA_WPS_TIMEOUT:
    print("WPS timeout")
	# attention: triggers disconnect event (which results in a reconnect with last essid/passwd)

jhgoebbert avatar Nov 03 '17 13:11 jhgoebbert

I've backported this to the main repo: https://github.com/micropython/micropython/pull/3530

Also, in your example, lines 15 and 16 both miss a ")" at the end

mactijn avatar Dec 30 '17 17:12 mactijn