Connected devices in MicroPython lesson plan
Network-ready MicroPython on the Pico W: every WiFi state and failure, HTTP status codes and headers, a web server from a bare socket, JSON both ways, asyncio servers, backoff and the watchdog, ending in an ocean buoy dashboard.
Objectives and materials
By the end, students can
- The network module and HTTP requests, failures included.
- A web server from a socket, and JSON for programs.
- asyncio servers, and recovering from every failure.
- An ocean buoy dashboard on a Pico W.
Materials for the whole unit
- Pressure, humidity and temperature, BME280
- Raspberry Pi Pico W
Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.
The board as a client
The network module and HTTP requests, failures included.
| Lesson | Time | What students do |
|---|---|---|
| The network modulePast "connected": every state a station passes through, a connect function with a timeout that fails fast, the address, mask, gateway and DNS server, the hostname and MAC, and names that do not resolve. | 60 min |
|
| urequests in depthEvery answer has a status: 200 and 201 for success, 4xx for your mistake, 5xx for the server’s. Headers, bodies, a fetch() that always closes, failures before any answer, and a POST with your own headers. | 65 min |
|
Materials
- Raspberry Pi Pico W
Check for understanding
Each student finishes "urequests in depth" on their own, without opening the hints. The simulator checks 8 of its 8 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Memory on a microcontroller".
The board as a server
A web server from a socket, and JSON for programs.
| Lesson | Time | What students do |
|---|---|---|
| A tiny web serverThe board as the server, from a bare socket: bind, listen, accept, read the request line, route the path, send a status line, headers and a page, and switch the Pico W’s LED from a browser. | 50 min |
|
| JSON both waysThe language devices and dashboards speak: parse a space weather feed into dicts and lists, survive bad JSON and missing keys, turn your own readings into JSON, and serve them at /api. | 60 min |
|
Materials
- Raspberry Pi Pico W
Check for understanding
Each student finishes "JSON both ways" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Serve it at /api".
Robust devices
asyncio servers, and recovering from every failure.
| Lesson | Time | What students do |
|---|---|---|
| asyncio serversA server that does not stop the world: asyncio.start_server with one coroutine per connection, a blinker task that never pauses, and the rule that makes it all work: await, never sleep. | 50 min |
|
| Error recoveryA device that keeps working when the network does not: retries with exponential backoff for joining and for requests, running on the last good value, and a hardware watchdog that restarts a hung board. | 65 min |
|
Materials
- Raspberry Pi Pico W
Check for understanding
Each student finishes "Error recovery" on their own, without opening the hints. The simulator checks 8 of its 8 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Layers of defense".
Boss project
An ocean buoy dashboard on a Pico W.
| Lesson | Time | What students do |
|---|---|---|
| Boss: an ocean buoy dashboardA Pico W on a buoy: a BME280 read by an asyncio task, a sea forecast fetched with backoff, an HTML dashboard and a JSON API served at once, and a storm light driven by the forecast and the pressure. | 65 min |
|
Materials
- Pressure, humidity and temperature, BME280
- Raspberry Pi Pico W
Check for understanding
Each student finishes "Boss: an ocean buoy dashboard" on their own, without opening the hints. The simulator checks 8 of its 8 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Tune the storm line".
Teach this unit as a class
Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.
The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.