Firmware Update
Overview
This tutorial shows how to use Mongoose firmware update support functions in the context of a device dashboard. The UI runs on a web browser and interacts with the device via a RESTful API.
The device dashboard UI, including user authentication, is explained in its own tutorial. To build and try the example, please follow it. Selecting
Firmware Update
in the menu on the left, you'll access the corresponding screen for this tutorialYou basically upload a firmware file, reset the device to boot from it, and commit it or rollback to the previous image.
The MQTT dashboard UI is explained in its own tutorial. To build and try the example, please follow it. It works in a pretty similar way to what we previously described.
API
bool mg_ota_begin(size_t new_firmware_size); // Start writing
bool mg_ota_write(const void *buf, size_t len); // Write chunk, aligned to 1k
bool mg_ota_end(void); // Stop writing
Example RESTful API
For this application, the RESTful server API in the Device Dashboard tutorial provides the following authenticated endpoints:
/api/firmware/upload
- handles the process of uploading a file to the device and saving it as binary data
Each endpoint basically calls its respective backend API function for the OTA process. The update process itself requires three function calls: ota_begin()
, ota_write()
for each data chunk received, and ota_end()
to finish the transaction.
Example RPC API
For this application, the RPC API in the MQTT Dashboard tutorial provides the following methods:
ota.upload
- instructs the device to get and save new firmware
In this example, devices will publish their status, which includes firmware status
Compile options
The implementation is driven by the build option MG_OTA
:
MG_OTA_NONE
- No OTA support, uses a stub implementation that does nothing: src/ota_dummy.cMG_OTA_CUSTOM
- Custom implementation, roll your own set ofmg_ota_*
functions.MG_OTA_<device name>
- OTA for that specific device, see below.
Supported devices
Check src/ota.h for supported devices; e.g.:
Basic usage
The OTA API functions are usually called from:
a RESTful API, as used in the Device Dashboard tutorial:
an RPC API, as used in the MQTT Dashboard tutorial: