micropython / micropython-esp32

Old port of MicroPython to the ESP32 -- new port is at https://github.com/micropython/micropython
MIT License
675 stars 217 forks source link

add WPS support #218

Closed jhgoebbert closed 1 year ago

jhgoebbert commented 6 years ago

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)
mactijn commented 6 years ago

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