HydraFerret Over The Air firmware updates

Enfield Cat's Blog: Arduino and other projects.


Introduction

The HydraFerret devices can have their firmware updated (or reverted to their previous image) using an over the air (ota) update. There are various ways of doing this, such as checking for update on reboot, manually from the command prompt, or scheduled as an output variable. The basic ota command summary is as follows:

ota [update|revert|<url>]
    Check and apply over the air update
    Revert to previous installation.
    Set base URL for OTA metadata and image

cert [ota <fileName>]
    Certificate file to use if using https for transfers

[enable|disable] otaonboot
    Enable or disable ota update check on reboot

output [[0-7] [pin] var ota <rpn condition for ota update check>]
    Enable ota check based on some condition, eg 15th of the month at noon:
    output 0 39 var ota memory.dom 15 = memory.hour 12 = & memory.min 5 < &

Using https

To use https, you need to enter the Root CA Certificate to trust in a file called "/rootCACertificate" on the esp32 module. The HydraFerret build include an approximately 200k filesystem used principally for holding certificate information. But other arbitrary data may be stored here too. File system manipulation commads are:

dir                - directory listing of the filesystem
del <file-name>    - delete the file
read <file-name>   - display the file contents
write <file-name>  - display the file contents, note you can overwrite but not edit files.

Ideally you should use secure http to transfer data to and from any site on the internet. The "down side" to using https is the overhead required for encryption/ decryption of data. You will also need to configure the root CA (Certificate Authority) who you wish to trust. This means a slightly bigger effort in configuring the the connection, and perhaps a slightly slower transfer during the update. But it means you are downloading the device image from a trusted source.

Web server configuration

The OTA transfer can be done using either http or https. You can use your own web server or https://camelthorn.cloud/projects/HydraFerret/ to do this. The webserver holding the binary image used for the update should hold some metadata about the image to download as well as the image. These are placed in the same web sub-directory / folder as each other. The metadata can be created manually, but using a PHP script to generate it is the best way of providing it. The PHP program can dynamically adjust the metadata whenever the the image is updated. A possible PHP implementation uses "metadata.php" as below, with the binary file in "esp32.img":

<?php
$filename="esp32.img";
$statvar=stat($filename);
$sha256var=hash_file("sha256", $filename);
echo "name: $filename\n";
echo "size: $statvar[size]\n";
echo "sequence: $statvar[mtime]\n";
echo "sha256: $sha256var\n"; ?>



Thank you for visiting camelthorn.cloudHome