Skip to content

Simple upload/download server for OTA with Arduino IDE integration (2024)

License

Notifications You must be signed in to change notification settings

matthewgream/ota

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

For the server:

# install nodejs && npm -- needed for ota_server.local which is ota/server/daemon/server.js and runs from systemd on port 8090
# install avahi -- needed to pubish ota.local on multicast dns, starts in rc.local AFTER dhcp assignment

# images are stored in /opt/ota/images

$ mkdir -p /opt/ota && cd /opt/ota
$ git clone https://github.com/matthewgream/ota.git
$ cd ota
$ ( cd server/daemon && npm install )
$ sudo cp server/config/*.service /etc/systemd/system
$ if [ -f /etc/rc.local ]; then sudo echo systemctl start [email protected] >> /etc/rc.local; else sudo cp server/config/rc.local /etc/rc.local; fi
$ sudo systemctl start [email protected]
$ sudo systemctl enable ota_server && sudo systemctl start ota_server

$ ping ota.local
$ journalctl -au [email protected]
$ journalctl -au ota_server
$ curl http://ota.local:8090/images

In a browser, http://ota.local:8090/images yields a human readable and sorted list of images.

Images

For the images, they can be copied into the /ota/server/images directory, noting the specific format and compression, or use a client side tool. For client side tool for Arduino IDE, see client/arduino_ide/platform.local.txt and client/arduino_ide/upload_fota.ps1 to automate uploads from Arduino IDE builds. For client side tool for Platform IO, see client/platform_io/platformio.ini, client/platform_io/build_post_ota_upload.py, and client/platform_io/build_pre_set_variables.py to automate uploads from Platform IO builds. Images are compressed with zlib in the server before being stored with .zz extension.

For the clients, a request with specific type, vers and addr will yield the most recent version of images available (or nothing, if no newer version).

$ curl http://ota.local:8090/images/images.json?type=batterymonitor-custom-esp32c3\&vers=1.0.2\&addr=01:02:03:04:05:06
[{"type":"batterymonitor-custom-esp32c3","version":"1.0.4","url":"http://ota.local:8090/images/batterymonitor-custom-esp32c3_v1.0.4.bin.zz"}]

For an Arduino based client, use the esp32FOTA library (https://docs.arduino.cc/libraries/esp32fota) and the esp32-flashz library (https://docs.arduino.cc/libraries/esp32-flashz). You can see an example wrapper in client/arduino/UtilitiesOTA.hpp and client/arduino/ProgramUpdates.hpp . For substantive documentation, see https://github.com/chrisjoyce911/esp32FOTA.

Some experimental code exists for a Raspberry PI based recovery image, see server/daemon/server-backup.js and the todo directory. This will be better integrated in future.

Images

#define DEFAULT_NETWORK_SSID "ssid"
#define DEFAULT_NETWORK_PASS "pass"
#define DEFAULT_NETWORK_RETRY_COUNT 20
#define DEFAULT_NETWORK_RETRY_DELAY 1000
#define DEFAULT_SOFTWARE_TIME (60*60*12) // check every 12 hours
#define DEFAULT_SOFTWARE_TYPE "weatherdisplay-inkplate2-esp32"
#define DEFAULT_SOFTWARE_VERS "1.5.1"
#define DEFAULT_SOFTWARE_JSON "http://ota.local:8090/images/images.json"
#include "UtilityOTA.hpp"

uint32_t ota_counter = ... seconds since previous check
DEBUG_PRINTF ("[ota_counter: %lu until %d]\n", ota_counter, DEFAULT_SOFTWARE_TIME);
if (ota_counter >= DEFAULT_SOFTWARE_TIME) {
    ota_counter = 0;
    ota_check_and_update (DEFAULT_NETWORK_SSID, DEFAULT_NETWORK_PASS, DEFAULT_NETWORK_RETRY_COUNT, DEFAULT_NETWORK_RETRY_DELAY,
        DEFAULT_SOFTWARE_JSON, DEFAULT_SOFTWARE_TYPE, DEFAULT_SOFTWARE_VERS, [&] () { program->reset (); });
}

Note the server also includes code for address based json configuration requests. Note also there is no security: no passwords, no certificates, etc and is designed for a local network.

Note the audit trail in the journal:

server.js[16428]: express up for 'ota_server' ! -> IPv6/:::8090 [/opt/ota/images]
server.js[16428]: /images manifest request: 1 items, 218 bytes, types=[batterymonitor-custom-esp32c3], type=batterymonitor-custom-esp32c3, vers=1.0.3, addr=24:58:7c:35:e9:e4
server.js[16428]: /images upload succeeded: 'batterymonitor-custom-esp32c3_v1.0.4.bin' (2003376 bytes) --> '/opt/ota/images/batterymonitor-custom-esp32c3_v1.0.4.bin.zz' (1181661 bytes) [::ffff:192.168.0.149]

About

Simple upload/download server for OTA with Arduino IDE integration (2024)

Topics

Resources

License

Stars

Watchers

Forks