Lesson plan

Device to cloud: telemetry that survives lesson plan

Telemetry that reaches the server once, in order, through outages: sequence numbers, ArduinoJson payloads, batching, backoff with jitter, an offline queue on SD, device identity and idempotent uploads, on an ESP32-C3.

4 chapters, 7 lessons, about 7 hours, on the ESP32-C3-DevKitM-1. Every lesson runs in the browser, with nothing to install.

The unit

Objectives and materials

By the end, students can

  • What a reading carries, and JSON that says it.
  • Batching, and backing off when the cloud fails.
  • An offline queue on SD, and an identity the cloud trusts.
  • A reliable telemetry node.

Materials for the whole unit

  • ESP32-C3-DevKitM-1
  • microSD card module
  • Pressure, humidity and temperature, BME280

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 55 min

Messages

What a reading carries, and JSON that says it.

LessonTimeWhat students do
Telemetry designWhat a reading must carry to survive the trip: who sent it, a sequence number that is never reused, when it was measured on the device’s own clock, and units in every name. And what a day of it costs.50 min
  1. Run it: a garden node
  2. What a day costs
  3. Four fields that make it survive
  4. Delivered intact
  5. Measure less often
  6. At least once, exactly once
JSON payloadsBuild payloads with ArduinoJson: nested objects and arrays, exact decimals with serialized(), the size before sending, short keys, and a server reply parsed with every failure checked.65 min
  1. Run it: a JsonDocument
  2. Measure before you send
  3. Nested, with exact decimals
  4. Parse the reply
  5. A reply that is not JSON
  6. Valid, but wrong
  7. A damp flag
  8. Short keys

Materials

  • ESP32-C3-DevKitM-1
  • microSD card module
  • Pressure, humidity and temperature, BME280

Check for understanding

Each student finishes "JSON payloads" 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: "Short keys".

Chapter 2. About 1 h 50 min

Sending well

Batching, and backing off when the cloud fails.

LessonTimeWhat students do
BatchingOne request for many readings: a JSON array with a sequence number in each entry, sent a batch at a time, kept whole when the post fails, and the trade between requests and delay.50 min
  1. Run it: requests an hour
  2. Filling the batch
  3. Send it
  4. Keep it when it fails
  5. Bigger batches
  6. Size or time
BackoffWhen the cloud fails: exponential backoff to a cap, full jitter so a thousand nodes do not retry in step, a reset on success, and never retrying a request the server called wrong.60 min
  1. Run it: steady state
  2. The cloud goes down
  3. The window doubles
  4. Recovery
  5. Why the jitter
  6. A lower cap
  7. Backoff in RAM is not enough

Materials

  • ESP32-C3-DevKitM-1
  • microSD card module
  • Pressure, humidity and temperature, BME280

Check for understanding

Each student finishes "Backoff" 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: "Backoff in RAM is not enough".

Chapter 3. About 2 h 5 min

Surviving

An offline queue on SD, and an identity the cloud trusts.

LessonTimeWhat students do
An offline queueReadings on the SD card first, uploads second: a JSON Lines queue file, a marker of how much is sent, the oldest first, nothing marked sent before a 2xx, and a sequence number that survives a reboot.65 min
  1. Run it: write first, send later
  2. Queued
  3. Uploaded, then marked
  4. The cloud goes down
  5. Drained in order
  6. Pull the plug
  7. Smaller batches
  8. Cards wear out
Device identityWho is this node? An id from a config file on the card or from the chip’s MAC, an API key that never lives in the code, an Idempotency-Key that makes a retried upload safe, and what to do when the key is refused.60 min
  1. Run it: an id from the chip
  2. The MAC address
  3. Identity from the card
  4. An Idempotency-Key
  5. A retry is the same request
  6. The key is refused
  7. Provisioning

Materials

  • ESP32-C3-DevKitM-1
  • microSD card module
  • Pressure, humidity and temperature, BME280

Check for understanding

Each student finishes "Device identity" 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: "Provisioning".

Chapter 4. About 1 h 5 min

Boss project

A reliable telemetry node.

LessonTimeWhat students do
Boss: a reliable telemetry nodeEvery idea at once: readings queued on SD with a persistent sequence number, idempotent batches with the node’s identity, backoff with jitter through an outage, a reboot in the middle, and a stop on a refused key.65 min
  1. Run it: garden-07
  2. Batches with a key
  3. An outage
  4. A reboot mid-outage
  5. Recovery, in order
  6. The key is refused
  7. Smaller batches
  8. The promise

Materials

  • ESP32-C3-DevKitM-1
  • microSD card module
  • Pressure, humidity and temperature, BME280

Check for understanding

Each student finishes "Boss: a reliable telemetry node" 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: "The promise".

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.