Pico W WiFi Cheatsheet

Pico W WiFi Cheatsheet

network module, urequests, web server, and AP mode.

Station Mode
wlan = network.WLAN(network.STA_IF) Create station interface
wlan.active(True) Enable the WiFi radio
wlan.connect(ssid, password) Connect to a network
wlan.status() == 3 Status 3 = connected
wlan.ifconfig()[0] Get the assigned IP address
HTTP Requests
import urequests MicroPython HTTP library (like Python requests)
r = urequests.get(url) Perform a GET request
r = urequests.post(url, data=body) Perform a POST request
r.status_code / r.text / r.json() Response status, text body, or parsed JSON
r.close() Always close the response to free memory
AP Mode
network.WLAN(network.AP_IF) Create access point interface
ap.config(essid="name", password="pw", security=4) Configure AP name and WPA2 password
ap.active(True) Start the access point
ap.ifconfig()[0] AP gateway IP (usually 192.168.4.1)
Credentials
Create secrets.py on Pico W Store SSID and PASSWORD constants in a separate file
from secrets import SSID, PASSWORD Import credentials without hardcoding them
Add secrets.py to .gitignore Prevent credentials being committed to version control
import ujson MicroPython JSON encoder/decoder for API payloads