Trigger OTA via NATS¶
This guide covers driving a firmware update on a running service with the NATS CLI.
Prerequisites¶
- The NATS CLI, configured for the device's NATS server
- A service running an
OTAPlugin. The examples useswupdateas the service name and the plugin id
Watch Status and Replies¶
Open two terminals and leave them running:
nats sub events.infos # status events, one per state change
nats sub events.params # command replies
Run an Update¶
-
Notify the update:
nats pub commands.swupdate.req \ '[{"n":"NotifyOTAUpdate","vs":"{\"id\":\"swupdate\",\"fw_name\":\"firmware\",\"fw_version\":\"1.2.3\",\"url\":\"https://example.com/firmware/v1.2.3.swu\"}"}]'The status moves to
update_available.fw_versionmust be newer than the installed firmware, unless the plugin allows an equal or older one. See OTA Commands. -
Download the package. The status moves to
downloading, thenupdate_ready: -
Install it. The status moves to
updating, thenupdate_successful:
Read the Status¶
To match a reply to its request, add --reply "<unique-id>". The reply on events.params carries the same id.
Pause and Resume a Download¶
nats pub commands.swupdate.req '[{"n":"PauseOTADownload","vs":"{\"id\":\"swupdate\"}"}]'
nats pub commands.swupdate.req '[{"n":"ResumeOTADownload","vs":"{\"id\":\"swupdate\"}"}]'
Recover from a Failure¶
| Command | From | Result |
|---|---|---|
AbortOTAUpdate |
download_failed, update_failed |
update_available, package deleted |
CancelOTAUpdate |
downloading, paused, update_ready |
update_available, package deleted |
ClearOTAUpdate |
update_available |
updated, pending update dropped |
ResetOTAState |
Any except updating, update_successful |
updated, pending update and checkpoint dropped |
After AbortOTAUpdate or CancelOTAUpdate, download the package again before installing.
Troubleshooting¶
The status stays updated after NotifyOTAUpdate¶
The version check ignored the update: fw_version is equal to or older than the installed firmware. Send a newer
version, or set allow_same_version or allow_downgrade in the plugin's configuration.
The reply has "result": "error"¶
The error field gives the reason. The common one is a command sent from a state that does not allow it; see the
Valid from column in OTA Commands.
See also
- OTA Commands — every command, payload, reply and status event
- OTA State Machine — the states a command moves the update through
- Trigger OTA via HTTP — the same lifecycle through the ToloMEO HTTP API