🛠 Point d'accès & provisioning Wi-Fi par navigateur (mode SoftAP)

Raspberry Pi Pico W · avance · Schéma : IMG-pico-w-avance-3-picow-softap-provisioning.svg — Pico W emettant son propre reseau Wi-Fi, smartphone connecte a ce reseau affichant le formulaire de configuration, puis fleche de bascule vers le reseau domestique, zone keep-out antenne respectee par le boitier

Objectives

How do you deploy 50 Pico W units for users who don't read serial logs? The official answer: browser-based provisioning, the flagship example in pico_w/wifi/ within pico-examples (access point + web configuration page). The principle: the board broadcasts its own network (the CYW43439 supports a SoftAP with up to 4 clients), the user connects to it from their phone, enters the target network credentials in a form served by the board, and then the board switches to station mode. You will build the same sequence in MicroPython using network.WLAN(network.WLAN.IF_AP).

Hardware

Complete Code

# provisioning.py — SoftAP + formulaire + bascule station (MicroPython)
import machine, network, socket, time

FORM = (b'HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n'
        b'<form method=POST>SSID<input name=s><br>'
        b'<input name=p type=password><br>'
        b'<button>Go</button></form>')

def parse_form(req):
    kv = req.split(b'\r\n\r\n', 1)[-1].decode.split('&')
    d = dict(x.split('=', 1) for x in kv if '=' in x)
    return d.get('s', ''), d.get('p', '')

ap = network.WLAN(network.WLAN.IF_AP)   # mode point d'accès (max 4 clients)
ap.ifconfig = ('192.168.4.1', '255.255.255.0', '192.168.4.1', '8.8.8.8')
ap.config(ssid='PICO-SETUP', key='provision123')   # WPA2, canal par défaut
ap.active(True)
print('reseau PICO-SETUP emis sur 192.168.4.1')

srv = socket.socket
srv.bind(socket.getaddrinfo('192.168.4.1', 80)[0][-1])
srv.listen(1)
srv.settimeout(120)                      # fenêtre de config de 2 minutes
try:
    cl, _ = srv.accept
    req = cl.recv(1024)
    if b'POST' in req:
        ssid, pwd = parse_form(req)
        cl.write(b'HTTP/1.0 200 OK\r\n\r\nConfig ok, au revoir')
        cl.close
        ap.active(False)                 # coupe le SoftAP
        sta = network.WLAN             # retour en station
        sta.active(True)
        sta.connect(ssid.replace('%20', ' '), pwd.replace('%20', ' '))
        for _ in range(60):
            if sta.isconnected: break
            machine.idle
        print('IP finale :', sta.ipconfig('addr4'))
finally:
    srv.close

Expected Verification

On the first boot without known configuration, the PICO-SETUP network appears on the phone; once the form is submitted, the board sends a success message, closes the SoftAP, and joins the home network — the final IP address is displayed once connected. This is exactly the flow of the official C example (which, in turn, serves a real page with a list of scanned networks).

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials