← Back to the chapter · Next detail →

Technical detail · Device State Machines: Modes and Safety

Timers, persistence, and reconnect history

Use timers that measure elapsed time without jumping when the wall clock changes. These are called monotonic timers; use them for connection attempts, sensor warmup, acknowledgements, watchdog windows, and lockout cooldowns.

Persist only states that must survive reboot; recompute volatile states such as transient network connection after startup.

Statecharts are diagrams that can group states and show parallel behavior. SCXML is a format for describing such models. A transition table lets code look up a rule by state and event. Property-based tests generate many event sequences to check rules that should always hold. These tools help keep models, code, and tests aligned.

When a device reconnects, compare its shadow versions with local changes before applying old requests. MQTT retained state is the last message a broker saves for new subscribers. A rollback slot holds the earlier firmware so an OTA update can be undone. On reconnect, define how the device compares these versions and its local event log before choosing what to apply.

← Back to the chapter · Next detail →