State Machine Design Record

State Machine Design Record

animation
state-machines
design-patterns

Try It Yourself: State Machine Design Record

Choose one IoT workflow and complete a design record before coding.

state_machine: device-command-lifecycle
initial_state: SAFE_OFF
states:
  - SAFE_OFF
  - ARMED
  - ACTIVE
  - LIMITED
  - EMERGENCY_STOP
  - LOCKOUT
events:
  - arm_requested
  - start_requested
  - stop_requested
  - limit_exceeded
  - watchdog_warning
  - inspected_reset
transition_example:
  source: ACTIVE
  event: limit_exceeded
  guard: sensor_reading_is_valid
  action: reduce_output_and_log_fault
  target: LIMITED
  timeout: move_to_emergency_stop
invalid_event_policy:
  in_lockout: reject_and_log
observability:
  transition_log_fields:
    - previous_state
    - event
    - guard_result
    - target_state
    - timestamp
    - firmware_version
tests:
  - invalid_event_in_each_state
  - timeout_from_each_waiting_state
  - reboot_from_each_persisted_state
  - emergency_stop_priority

Review the record with someone who owns operations or safety. The best state-machine reviews find missing events before they become field failures.

Back to the chapter