Firmware APIs¶
Firmware Updates¶
To perform a firmware update the <BASE-URL>/api/v1/firmware-update/ endpoint can be used.
According to the request parameters, the configured delivery procedure and the permission scheme,
the Device Hub will provide firmware image via a download link.
A firmware update contains mulitiple stages.
Each firmware update session is identified by an identifer.
The identifier is returned on the initial request (API response entry id) and must be provided on subsequent request endpoints.
The state string (up_to_date, ready, queued, processing, created, unconfirmed, success, fail) is returned in the API response state entry.
The state diagram shows the stages involved for a complete firmware update.
stateDiagram
state request <<fork>>
state "ready" as Ready
state "up_to_date" as UpToDate
state "queued" as Queued
state "processing" as Processing: Run procedure pipeline
state "created" as Created
state "fail" as Fail
state "success" as Success
state "unconfirmed" as Unconfirmed
[*] --> request: /request
request --> Ready: Update available
request --> UpToDate: No update available
UpToDate --> [*]: Timeout
Ready --> [*]: Timeout
Ready --> Queued: /{id}/start
Queued --> Processing
Queued --> Fail : Queing Error
Fail --> [*] : Timeout
Processing --> Created : With confirm step
Processing --> Fail: Processing Error
Created --> Unconfirmed : Timeout
Created --> Success : /{id}/confirm success=True
Processing --> Success : Without confirm step
Created --> Fail : /{id}/confirm success=False
Unconfirmed --> [*] : Timeout
Success --> [*] : Timeout
Example¶
Pre-requisites¶
- Created a Product and Model
- Created a Delivery Method and Delivery Procedure
- Created a Channel
- Created a User with a Token
- Configured access rights
- (optional) Uploaded a Firmware
- (optional) Created a Device
The following API call initiates a firmware update request. It specifies the target image by specifying the Model, Delivery Method, Delivery Procedure, Channel, and the current firmware version of the requester. If the Device ID is provided, the Device Hub will update the device twin information. These parameters would usually be provided by the bootloader of the device. Other combinations of parameters can be used to specify a target image.
Python¶
Requires a client machine with Python 3 and the request package installed.
Request a firmware update session by providing your specification as a JSON body:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | |
Example response:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Start the procedure pipline:
1 2 3 4 5 | |
Wait until the download link is available. Note: Usually you would add some timeout in the loop:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Download the firmware image:
1 2 3 | |
Confirm that the update is completed:
1 2 3 4 5 6 | |
To check if the firmware request session completed successfully, you can check if the
firwmare update state reached success:
1 2 3 4 5 | |
Chunked firmware download¶
To download a firmware image from the DMS server, you have two options:
- download the whole file in one request
- use chunked download using HTTP range requests
In most cases, option 1. will be good enough. However, if you have large firmware images and the connection to the server is unreliable (e.g. LTE connection with weak signal strength), option 2. can be a good alternative.
To download a single chunk, add a HTTP range header to the request, e.g.
1 | |
Range to download all chunks.
The logic to merge the chunks and retry failed requests has to be implemented in the client.
Note that multipart range headers are not supported.
The following is an example in Python to download a firmware image in chunks:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |