Over the Air Updates#
Over the Air (OTA) updates are a way to update the firmware of a device remotely. This is a mandatory feature for any IoT device. The device must be able to update its firmware without any physical user intervention.
flownexus implements OTA updates according to the LwM2M protocol. The LwM2M protocol specifies how to update the firmware of a device. The OTA process is implemented by sending a link to a firmware via LwM2M object 5/0/1 - Package URI. This method is called Pull via HTTP(s) and is faster, compared to a transfer via CoAP. Updates via CoAP blockwise transfer to download the firmware are not supported.
A https server is usually be hosted under a subdomain. The default is
https://fw.flownexus.org
. This makes it easy to use a self-signed
certificate for the https server. For details, check chapter
Setup a Virtual Server.
More information about a possible firmware implementation can be found in the
lwm2m_client
firmware sample at
flownexus/simulation/lwm2m_client/src/firmware_update.c
.
Note
Firmware Updates are implemented in the LwM2M server and the example firmware. A set up a PKI with self-signed certificates is required for the server to communicate with the device via https. This setup will be described in upcoming releases shortly.
Update process of a Firmware#
The update process is described in detail in the LwM2M core specification v1.1.1 Chapter E.6 LwM2M Object: Firmware Update. This chapter summarizes the update process:
flownexus sends a link to the firmware to the device via LwM2M object 5/0/1 - Package URI. It is a relative link to the firmware on the server, e.g.
/binaries/v0.1.0.bin
. The hosthttps://fw.flownexus.org
is fixed in firmware.The device downloads the firmware from the server via http(s) and sets the state to
STATE_DOWNLOADING
.The device sets the state to
STATE_DOWNLOADED
after the download is complete.flownexus executes the command 5/0/2 - Update to the device.
The device sets the state to
STATE_UPDATING
upon receiving the command.The device updates the firmware, usually by performing a reboot.
The device registers and sends the firwmare version to flownexus via resource
Firmware Version - 3/0/3
. Depending if the update was successful or not, flownexus sets the result and state of the update in the database accordingly.
This process ensures that errors during the update process are handled and communicated to the backend.
States of a OTA Update#
There are 4 device states during an OTA update. flownexus tracks the state of
the device during the update process in the database (FirmwareUpdate table).
Once the update is completed (failed or successful), the state is set always
set to STATE_IDLE
.
State |
Description |
---|---|
STATE_IDLE |
device is idle |
STATE_DOWNLOADING |
device is downloading |
STATE_DOWNLOADED |
download is complete |
STATE_UPDATING |
device is updating |
Result Codes for an OTA Update#
For every OTA update, a result is generated after the update failed or
successful. There can be only one active OTA update at a time for each client.
An active OTA is indicated by the result RESULT_DEFAULT
. The result for
each OTA update is stored in the database (FirmwareUpdate table).
Result |
Description |
---|---|
RESULT_DEFAULT |
default state |
RESULT_SUCCESS |
update was successful |
RESULT_NO_STORAGE |
no storage available |
RESULT_OUT_OF_MEM |
out of memory |
RESULT_CONNECTION_LOST |
connection was lost |
RESULT_INTEGRITY_FAILED |
integrity check failed |
RESULT_UNSUP_FW |
unsupported firmware |
RESULT_INVALID_URI |
invalid uri provided |
RESULT_UPDATE_FAILED |
update failed |
RESULT_UNSUP_PROTO |
unsupported protocol |