![]() |
Data Gator
Hardware and software documentation for the Data Gator project.
|
Defines utilities for managing firmware updates, using Over-The-Air updates. More...
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
#include <HTTPUpdate.h>
#include <tinyxml2.h>
#include <MQTTMailer.hpp>
Go to the source code of this file.
Macros | |
#define | OTA_SERVER "192.168.50.10" |
Over-The-Air update server address. | |
Functions | |
string | new_firmware_version_available () |
Check if server has different firmware version. | |
void | update_progress (int cur, int total) |
Prints update process progress to the serial interface. | |
void | update_started () |
Send status message to the MQTT broker that the update process started. | |
void | update_finished () |
Log update process finished. | |
void | update_error (int err) |
Log update process errored out. | |
void | attempt_update () |
Attempts OTA firmware update from server. | |
Variables | |
const bool | USB_DEBUG |
USB serial debugging enabled. | |
PubSubClient | mqtt_client |
MQTT client object for logging. | |
Defines utilities for managing firmware updates, using Over-The-Air updates.
#define OTA_SERVER "192.168.50.10" |
Over-The-Air update server address.
Static IP address for the server hosting the firmware update files.
void attempt_update | ( | ) |
Attempts OTA firmware update from server.
Checks current firmware version on server, if different then update. Based on concepts from an example in the HTTPUpdate library.
This allows firmware upgrades AND downgrades. Attempts an update from the server three times before continuing.
Attaches three event callback functions to the httpUpdate object. Each callback function publishes debug messages which can be retrieved from a MQTT debug topic datagator/ota/<MAC address>
as well as the serial output.
If serial debugging is available, the server url can be checked in serial output.
string new_firmware_version_available | ( | ) |
Check if server has different firmware version.
Accesses the server using the IP address defined by OTA_SERVER. If the server hosted version of doesn't match then the firmware file name is retrieved and the file downloaded from the server.
Status messages are logged to serial and the MQTT broker if possible.
Log update process errored out.
Notifies the MQTT broker and prints the update error message to the serial line. The message on the serial port will contain the HTTP error code. Logging error code is not included in MQTT message since most likely failure is connection.
void update_finished | ( | ) |
Log update process finished.
Notifies the MQTT broker and prints the update finished message to the serial line. Only printed if successful.
Prints update process progress to the serial interface.
Prints number of bytes downloaded out of the total file size to serial interface, but only if the USB_DEBUG flag is set.
cur | bytes downloaded so far |
total | total file size in bytes |
void update_started | ( | ) |
Send status message to the MQTT broker that the update process started.
Notifies MQTT broker and prints to the serial interface that the device has begun updating from the server hosted file.