🛠 Point d'accès & provisioning Wi-Fi par navigateur (mode SoftAP)
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
- 1 × Raspberry Pi Pico W + MicroPython
_picowfirmware (powered by battery or standalone USB) - A smartphone
- A non-metallic enclosure or a clear window over the antenna area (keep-out zone 14 × 9 mm — the datasheet prohibits metal above it)
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
- Forgetting to disable the AP after provisioning: the board remains in mixed mode and consumes client slots (4 max) — perform a clean switch: AP off / STA on.
- URL-encoded characters in the password (
%20,%26…): an HTML form encodes everything — decode beforeconnect, otherwise you get an incomprehensible association failure. - Metallic enclosure or Pico W placed under a router: the PCB antenna needs its keep-out zone clear; nearby metal degrades gain and bandwidth (documented).
- No persistence: this script restarts provisioning on every boot — in production, save credentials to a flash file and only start the AP if the station
connectfails. - Forcing the phone to stay on the board's network: some OSes automatically switch back to Internet Wi-Fi as soon as
PICO-SETUPhas no gateway — warn the user in the UI or use a captive portal. - In the C SDK, the same flow relies on scanning (
cyw43_wifi_scan_results) to list networks — the official AP provisioning example is the recommended starting point.
Other tutorials for this board
- Faire clignoter la LED embarquée (elle est derrière la puce Wi-Fi !)
- Se connecter à un réseau Wi-Fi (station, WPA2/WPA3)
- Bouton et potentiomètre sans marcher sur le sans-fil (GPIO libres & ADC)
- Servir une page web depuis la Pico W (socket TCP + HTTP)
- Client HTTP : consommer une API depuis la Pico W
- Heure exacte via NTP : l'horloge temps réel des projets connectés
Code examples for this board
clignotante.pyPythonbouton-interruption.pyPythonpwm-servo.pyPythonlecture-adc.pyPythonneopixel.pyPythonoled-i2c.pyPython