Lesson plan

Connected devices lesson plan

WiFi, APIs, a web server, MQTT, ESP-NOW and BLE on the ESP32, and a device that keeps going when the network does not.

4 chapters, 7 lessons, about 4 hours, on the ESP32 DevKit V1. Every lesson runs in the browser, with nothing to install.

The unit

Objectives and materials

By the end, students can

  • Join WiFi, call an API, and serve a page of your own.
  • MQTT through a broker, and ESP-NOW with no router at all.
  • A Bluetooth LE server a phone can find, write and listen to.
  • The time from the network, and a device that rejoins on its own.

Materials for the whole unit

  • ESP32 DevKit V1 x 2
  • ESP32-C3-DevKitM-1
  • Four-digit display, TM1637
  • Full-size breadboard
  • LED x 2
  • Pushbutton
  • Resistor x 2

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.

Chapter 1. About 1 h 50 min

On the network

Join WiFi, call an API, and serve a page of your own.

LessonTimeWhat students do
Joining WiFiThe connect loop every connected device starts with: WiFi.begin, the states a station walks through, the address DHCP hands out, and what a wrong password and a wrong network name look like.40 min
  1. Run it
  2. The address
  3. The states of a station
  4. Get the password wrong
  5. Now the wrong name
  6. Signal strength
Calling an APIHTTPClient against a JSON API: a GET, the status code, the body, a different endpoint, and what a request that cannot reach its server returns.35 min
  1. Run it
  2. The status code
  3. The JSON body
  4. Ask a different server
  5. A request that cannot get there
A web serverThe board serves a page: a WiFiServer on port 80 reads the browser’s request a line at a time, switches two LEDs from the path, and prints the page back.35 min
  1. Run it
  2. Where to point the browser
  3. Press a button on the page
  4. Start with the light on
  5. Who can reach it

Materials

  • ESP32 DevKit V1
  • ESP32-C3-DevKitM-1
  • Full-size breadboard
  • LED x 2
  • Resistor x 2

Check for understanding

Each student finishes "A web server" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Who can reach it".

Chapter 2. About 1 h 10 min

Messages

MQTT through a broker, and ESP-NOW with no router at all.

LessonTimeWhat students do
MQTT with PubSubClientPublish and subscribe through a broker: topics, payloads, QoS and retained messages, the PubSubClient connect loop with its error codes, and the same reading sent over HTTP where the simulator has no broker.35 min
  1. A post office for devices
  2. Write the PubSubClient loop
  3. Read the error code
  4. QoS and retained messages
  5. Send the reading anyway
ESP-NOWTwo ESP32s and no router: a button on one switches an LED on the other over ESP-NOW, the sender hears the acknowledgment, and a wrong MAC address shows what no answer looks like.35 min
  1. Run it
  2. Press the button
  3. The receiver lights up
  4. Send to nobody
  5. When to use it

Materials

  • ESP32 DevKit V1 x 2
  • ESP32-C3-DevKitM-1
  • Full-size breadboard
  • LED
  • Pushbutton
  • Resistor

Check for understanding

Each student finishes "ESP-NOW" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "When to use it".

Chapter 3. About 25 min

Talk to a phone

A Bluetooth LE server a phone can find, write and listen to.

LessonTimeWhat students do
BLE: a lamp your phone can findBluetooth Low Energy the way phones see it: a GATT server with the Nordic UART service, a characteristic to write, notifications back, and advertising again after a phone leaves.25 min
  1. Run it
  2. Services and characteristics
  3. Connect, switch it, and leave
  4. Give it your name

Materials

  • ESP32 DevKit V1
  • LED
  • Resistor

Check for understanding

Each student finishes "BLE: a lamp your phone can find" on their own, without opening the hints. The simulator checks 4 of its 4 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Give it your name".

Chapter 4. About 35 min

Stay connected

The time from the network, and a device that rejoins on its own.

LessonTimeWhat students do
Reconnecting and NTP timeA clock that gets the time from NTP, keeps counting on its own, shows your time zone, and notices when WiFi drops and joins again without a reset.35 min
  1. Run it
  2. Ask for the time
  3. Counting on its own
  4. Your time zone
  5. When WiFi drops

Materials

  • ESP32 DevKit V1
  • Four-digit display, TM1637

Check for understanding

Each student finishes "Reconnecting and NTP time" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.

Then ask each one to explain, in a sentence or two, the last thing it asked of them: "When WiFi drops".

Your class

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.