Data Gator
Hardware and software documentation for the Data Gator project.
Loading...
Searching...
No Matches
update.cpp File Reference

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>
Include dependency graph for update.cpp:
This graph shows which files directly or indirectly include this file:

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.
 

Detailed Description

Defines utilities for managing firmware updates, using Over-The-Air updates.

Macro Definition Documentation

◆ OTA_SERVER

#define OTA_SERVER   "192.168.50.10"

Over-The-Air update server address.

Static IP address for the server hosting the firmware update files.

Function Documentation

◆ attempt_update()

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.

◆ new_firmware_version_available()

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.

◆ update_error()

void update_error ( int  err)

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.

◆ update_finished()

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.

◆ update_progress()

void update_progress ( int  cur,
int  total 
)

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.

Parameters
curbytes downloaded so far
totaltotal file size in bytes

◆ update_started()

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.

Variable Documentation

◆ USB_DEBUG

const bool USB_DEBUG
extern

USB serial debugging enabled.

Serial debug enable flag, set in config.h