IoT and Smart Systems Engineer · Projects

Project 2: Readings that survive drops and power cuts

Marking guide version 1 · Lessons: IO7 lessons 1–5, IO8 lessons 1–5, IO10 lesson 3

The problem and who it's for

The school's Wi-Fi is switched off at night and sometimes for days, and power cuts are common. In the starter, waiting readings are kept in a list in memory that a reset loses and that grows without limit. The device waits up to 30 seconds for Wi-Fi every time, sends everything at once with QoS 0 to a made-up topic, and forgets readings whether or not they arrived. It keeps every reading even when nothing has changed, and has no status or last will, so the dashboard can't tell a sleeping device from a dead one. The committee needs every reading that matters, once each, and a clear view of which devices are alive.

Scope

Not included

Before you start

Starter files

Download everything at once: starter/iot-starter.zip.

Milestones

  1. Read docs/FORMATS.md, run python tools/broker.py, and watch the starter's messages with a standard MQTT client.
  2. Keep readings in flash and survive power cuts (tests 1 and 2).
  3. Add the capacity limit and sending oldest first with QoS 1 in batches (tests 3 and 4).
  4. Forget readings only after confirmation, and match the agreed format (tests 5 and 6).
  5. Add backoff, status and the last will (tests 7 and 8).
  6. Add edge filtering and write docs/buffer-design.md (tests 9 and 10), then run all 10 tests twice in a row.

Expected outputs

Acceptance tests

# Input Expected result
1 pytest tests/test_buffer.py 10 of 10 pass, twice in a row
2 A reset; a power cut part-way through a write; a full buffer Waiting readings survive, nothing already saved is lost, and the oldest are dropped and counted when full (tests 1, 2 and 3)
3 Wi-Fi returns; a PUBACK is lost; a standard client subscribes Readings go oldest first with QoS 1 in batches, a reading is sent again until confirmed, and the client receives the agreed format (tests 4, 5 and 6)
4 A day without Wi-Fi; sleeping; a lost connection Few attempts, short wakes and the backlog cleared afterwards; "asleep" before sleep, and "offline" from the last will (tests 7 and 8)
5 A steady tank; an alarm; docs/buffer-design.md Fewer readings when nothing changes, alarms at once, and the design written down (tests 9 and 10)

Failure and recovery exercises

  1. Forget readings as soon as they're sent and run test 5. Count what's missing and explain what the committee would see, then restore it.
  2. Rewrite the whole log in place and run test 2. Explain what a power cut does to it, then restore the append-only log.
  3. Remove the backoff and run python tools/simulate.py --days 3 --wifi-down 1. Compare the Wi-Fi attempts and battery life, then restore it.

Evidence to submit

Marking guide and self-check

Pass rule: every Safety-critical (S) and Mandatory (M) item must be met. A single unmet safety item means the project is not complete, whatever else is done. Quality items are for your own improvement.

Your answers are saved in this browser on this device. Self-checked means you checked your own work against this guide; it is not a reviewer's approval. Never paste passwords, keys, tokens or real customer data here.

Checklist (marking guide version 1)
Evidence

← PreviousA year on one battery
ProLearners Assist