Below you will find information about how to use the IoT Bridge to manage and update firmware on devices via LWM2M and the standard firmware update process using object #5.
push
and pull
models for delivering firmware, but in general pull
is the preferred method to use.The LWM2M Inventory is available under the Advanced
menu. It allows you to upload files that can be served to devices through either push
or pull
firmware update operations.
Before you can initiate an update using the built-in hosting service, you must upload files, otherwise you can still use external URLs for your firmware file.
When using the IoT Bridge to initiate and manage a firmware update operation, the flow of events and data will look like this:
lwm2m.firmwareUpdate()
. See the LWM2M documentation for details about the parameters for this function.idle
to downloading
to downloaded
LWM2M FOTA Status
events will be generated to allow triggers to update connected applications with the status of the updates.downloaded
the server will automatically execute the update
resource to initiate the update operation.downloaded
to updating
to idle
LWM2M FOTA Status
events will be generated to allow triggers to update connected applications with the status of the updates.idle
), a LWM2M FOTA Complete
event will be generated.Below you will find instructions to import a Solution Template to demonstrate and lay the foundation for managing firmware updates for LWM2M devices in the IoT Bridge.
Below you will find descriptions of the triggers.
This example modifies the devices in your IoT hub by adding more fields to the Device Twin. The following fields are added to the twin:
{
"fota": {
"manufacturer": "tartabit",
"version": "1.1.0",
"state": "idle",
"result": "in-progress",
"uri": "http://...."
}
}
1. Azure IoT Hub - FOTA - On Register
This trigger collects information from devices when they register to the server and updates the device twin. By default it gathers the manufacturer, model, and version of the device, but can easily be extended to gather other information.
2. Azure IoT Hub - FOTA - On Status Update
This trigger fires whenever the firmware state machine for a device advances. The states mostly follow the states defined in the LWM2M specification, however, you may see some other transient states used by the platform to manage the reliability of the firmware update process. You should not need to update this trigger.
3. Azure IoT hub - FOTA - On Complete
This trigger fires when a firmware update completes on a device, this could be a success or a failure. The trigger updates the twin accordingly. You should not need to update this trigger.
4. Azure IoT hub - FOTA - Twin Changed
This is a sample trigger that initiates a firmware update on a device when the fota.uri
field in the twin is set and the IoT Bridge receives a notification.
Below you will find some example for how you can initiate an update on one or more devices.
You must have imported the template above before continuing.
Connect one or more LWM2M devices.
Navigate to your IoT Hub and create a new Device configuration.
Enter a name for your configuration.
For this example, the only field required is to set properties.desired.fota.uri to the URI or file name you want to download to the device.
Setup your metrics for the results. You can paste the configuration at the bottom of this section to configure the metrics later.
Set your target condition, in this example we set the properties.reported.fota.version to find the old version we want to update.
At this point you can review and create your configuration, below is the JSON for this example:
{
"id": "my-update-220425",
"priority": 10,
"targetCondition": "properties.reported.fota.version='1.1.0'",
"content": {
"deviceContent": {
"properties.desired.fota.uri": "http://localhost?ver=3.5.1"
}
},
"labels": {},
"metrics": {
"queries": {
"inProgress": "SELECT deviceId FROM devices WHERE properties.reported.fota.result='in-progress'",
"completed": "SELECT deviceId FROM devices WHERE properties.reported.fota.result='firmware updated successfully'"
},
"results": {}
},
"etag": ""
}
The configuration overview shows the status of your campaign.
These triggers may initiate reads (especially during registration) that are duplicated with other logic. In production, you may elect to merge the functionality of the triggers in this project with other triggers that access the same data to reduce data/power consumption in the device.