Skip to content

OTA Commands

An OTAService receives the OTA commands on commands.<service>.req and replies on events.params.

Message Format

Each command is a SenML record: n is the command name, vs is the payload serialized as a JSON string.

[{"n": "<CommandName>", "vs": "{\"id\": \"<plugin-id>\", ...}"}]

id is the plugin id the plugin sets in connect. The examples on these pages use swupdate for both the service name and the plugin id.

Commands

Command Payload Valid from Description
GetOTAStatus id Any Reports the current state
NotifyOTAUpdate see below updated, update_available Sets the pending update → update_available
StartOTADownload id, dest update_available, download_failed Starts the download → downloading
PauseOTADownload id downloading Pauses the download → paused
ResumeOTADownload id paused Resumes the download → downloading
InstallOTAUpdate id update_ready, update_failed Calls the plugin's install_update → updating
AbortOTAUpdate id download_failed, update_failed Deletes the package → update_available
CancelOTAUpdate id downloading, paused, update_ready Deletes the package → update_available
ClearOTAUpdate id update_available Deletes the package and pending update → updated
ResetOTAState id Any except updating, update_successful Deletes the package, pending update and checkpoint → updated

Payloads

NotifyOTAUpdate

{
  "id": "swupdate",
  "fw_name": "firmware",
  "fw_version": "1.2.3",
  "url": "https://example.com/firmware/v1.2.3.swu",
  "dest": "/data/tolomeo/ota.pkg"
}
Field Required Description
id Yes Plugin id
fw_name No Firmware name. Default N/A
fw_version Yes Firmware version, Semantic Versioning 2.0.0
url Yes Download URL
dest No Download path, see dest. Default download_dir/download_filename, see Configuration File

fw_version is compared with the installed firmware's BUILD_VERSION by Semantic Versioning precedence. Build metadata is ignored.

fw_version Result
Newer Accepted
Equal Ignored, unless the plugin option allow_same_version is true
Older Ignored, unless the plugin option allow_downgrade is true
Not valid SemVer Rejected with "result": "error"

An ignored update changes nothing and still replies "result": "success" with the current state.

The version check comes first, so an ignored update replies success in any state. Otherwise a notification is accepted only in updated and update_available: while an update is downloading, downloaded or failed, NotifyOTAUpdate replies error. Send CancelOTAUpdate or AbortOTAUpdate first to replace it.

StartOTADownload

Field Required Description
id Yes Plugin id
dest No Download path, see dest. Default: the path set by NotifyOTAUpdate

The download URL is always the one set by NotifyOTAUpdate.

dest

dest must name a file inside download_dir, given as an absolute path or relative to download_dir. The directory itself and the checkpoint file are refused. A refused dest replies error and changes nothing.

Replies

Every command replies on events.params with a SenML record named after the command, see SenML. Its vs decodes to:

{"id": "swupdate", "result": "success", "status": "update_available"}
Field Description
result success or error
status The state after the command, see States
error The reason. Present only when result is error

A command sent from a state not listed under Valid from replies error and changes nothing. The one exception is a NotifyOTAUpdate the version check ignores, which replies success.

An InstallOTAUpdate whose install_update raises after entering updating replies error with status update_failed.

ResetOTAState is a hard reset for development and recovery: it drops the pending update. It is refused while updating, so an install is never cut short.

Status Events

The service publishes the state on events.infos at startup and after every transition:

{
  "fwName": "firmware",
  "fwVersion": "1.2.3",
  "otaStatus": "downloading",
  "pendingFwName": "firmware",
  "pendingFwVersion": "1.3.0",
  "timestamp": 1700000010
}

fwName and fwVersion describe the installed firmware. pendingFwName and pendingFwVersion describe the recorded pending update, which is kept until it is cleared or reset, so they still appear in update_successful. pendingFwName is left out when the notification gave no fw_name.

See also