Skip to content
Merged

0.2.6 #117

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/arduino.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Arduino Build

# The workflow will run on every push and pull request to the repository
on:
- push
- pull_request

jobs:
compile-sketch:
runs-on: ubuntu-latest

steps:

- name: Checkout repository
uses: actions/checkout@v3

- name: Compile examples
uses: arduino/compile-sketches@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
fqbn: esp32:esp32:esp32
platforms: |
- name: esp32:esp32
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
libraries: |
- name: esp32FOTA
path: ./
- name: ArduinoJson
- name: ESP32-targz
- name: esp32-flashz
source-url: https://github.com/vortigont/esp32-flashz.git

#sketch-paths: |
#- examples/HTTP/HTTP/HTTP.ino
cli-compile-flags: |
- --warnings="default"
4 changes: 2 additions & 2 deletions .github/workflows/platformio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
ls
mkdir -p tests/test_http
mkdir -p tests/test_https
cp examples/HTTP/HTTP.ino tests/test_http/main.cpp
cp examples/HTTP/HTTPS.ino tests/test_https/main.cpp
cp examples/HTTP/HTTP/HTTP.ino tests/test_http/main.cpp
cp examples/HTTP/HTTPS/HTTPS.ino tests/test_https/main.cpp
# globally install the esp32FOTA library from local folder, don't update the platformio.ini
pio lib install --no-save file://$(realpath ./)
pio run
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions examples/withDeviceID/withDeviceID.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const char *ssid = "";
const char *password = "";

// esp32fota esp32fota("<Type of Firme for this device>", <this version>, <validate signature>);
esp32FOTA FOTA("esp32-fota-http", 1, false);
esp32FOTA esp32FOTA("esp32-fota-http", 1, false);
const char* manifest_url = "http://server/fota/fota.json";

void setup()
Expand Down Expand Up @@ -54,10 +54,10 @@ void setup_wifi()

void loop()
{
bool updatedNeeded = FOTA.execHTTPcheck();
bool updatedNeeded = esp32FOTA.execHTTPcheck();
if (updatedNeeded)
{
FOTA.execOTA();
esp32FOTA.execOTA();
}

delay(2000);
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "esp32FOTA",
"version": "0.2.5",
"version": "0.2.6",
"keywords": "firmware, OTA, Over The Air Updates, ArduinoOTA",
"description": "Allows for firmware to be updated from a webserver, the device can check for updates at any time. Uses a simple JSON file to outline if a new firmware is avaiable.",
"examples": "examples/*/*.ino",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=esp32FOTA
version=0.2.5
version=0.2.6
author=Chris Joyce
maintainer=Chris Joyce <[email protected]>
sentence=A simple library for firmware OTA updates
Expand Down
88 changes: 60 additions & 28 deletions src/esp32FOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,22 @@ esp32FOTA::~esp32FOTA(){}

esp32FOTA::esp32FOTA( FOTAConfig_t cfg )
{
setConfig( cfg );
setConfig( cfg );
}


void esp32FOTA::setString( const char *dest, const char* src )
{
if( !src ) return;
dest = (const char*)calloc( strlen(src)+1, sizeof(char));
strcpy( (char*)dest, src );
}



esp32FOTA::esp32FOTA(const char* firmwareType, int firmwareVersion, bool validate, bool allow_insecure_https)
{
setString( _cfg.name, firmwareType );
_cfg.name = firmwareType;
_cfg.sem = SemverClass( firmwareVersion );
_cfg.check_sig = validate;
Expand All @@ -138,7 +148,7 @@ esp32FOTA::esp32FOTA(const char* firmwareType, int firmwareVersion, bool validat

esp32FOTA::esp32FOTA(const char* firmwareType, const char* firmwareSemanticVersion, bool validate, bool allow_insecure_https)
{
_cfg.name = firmwareType;
setString( _cfg.name, firmwareType );
_cfg.check_sig = validate;
_cfg.unsafe = allow_insecure_https;
_cfg.sem = SemverClass( firmwareSemanticVersion );
Expand All @@ -149,6 +159,21 @@ esp32FOTA::esp32FOTA(const char* firmwareType, const char* firmwareSemanticVersi



void esp32FOTA::setConfig( FOTAConfig_t cfg )
{
setString( _cfg.name, cfg.name );
setString( _cfg.manifest_url, cfg.manifest_url );

_cfg.sem = cfg.sem;
_cfg.check_sig = cfg.check_sig;
_cfg.unsafe = cfg.unsafe;
_cfg.use_device_id = cfg.use_device_id;
_cfg.root_ca = cfg.root_ca;
_cfg.pub_key = cfg.pub_key;
}




void esp32FOTA::setCertFileSystem( fs::FS *cert_filesystem )
{
Expand Down Expand Up @@ -419,15 +444,17 @@ bool esp32FOTA::execOTA()
bool esp32FOTA::execOTA( int partition, bool restart_after )
{
// health checks
if( partition != U_SPIFFS && partition != U_FLASH ) {
Serial.printf("Bad partition number: %i or empty URL, aborting\n", partition);
return false;
}
if( partition == U_SPIFFS && _flashFileSystemUrl.isEmpty() ) {
log_i("[SKIP] No spiffs/littlefs/fatfs partition was specified");
return true; // data partition is optional, so not an error
} else if ( partition == U_FLASH && _firmwareUrl.isEmpty() ) {
log_e("No app partition was specified");
return false; // app partition is mandatory
} else if( partition != U_SPIFFS && partition != U_FLASH ) {
log_e("Bad partition number: %i or empty URL", partition);
return false;
log_i("[SKIP] No spiffs/littlefs/fatfs partition was specified");
return true; // data partition is optional, so not an error
}
if ( partition == U_FLASH && _firmwareUrl.isEmpty() ) {
Serial.printf("No firmware URL, aborting\n");
return false; // app partition is mandatory
}

// call getHTTPStream
Expand Down Expand Up @@ -455,15 +482,15 @@ bool esp32FOTA::execOTA( int partition, bool restart_after )
log_d("compression: %s", mode_z ? "enabled" : "disabled" );

if( _cfg.check_sig ) {
if( mode_z ) {
Serial.println("[ERROR] Compressed && signed image is not (yet) supported");
return false;
}
if( updateSize == UPDATE_SIZE_UNKNOWN || updateSize <= FW_SIGNATURE_LENGTH ) {
Serial.println("[ERROR] Malformed signature+fw combo");
return false;
}
updateSize -= FW_SIGNATURE_LENGTH;
if( mode_z ) {
Serial.println("[ERROR] Compressed && signed image is not (yet) supported");
return false;
}
if( updateSize == UPDATE_SIZE_UNKNOWN || updateSize <= FW_SIGNATURE_LENGTH ) {
Serial.println("[ERROR] Malformed signature+fw combo");
return false;
}
updateSize -= FW_SIGNATURE_LENGTH;
}

// If using compression, the size is implicitely unknown
Expand Down Expand Up @@ -695,17 +722,22 @@ bool esp32FOTA::execHTTPcheck()
{
String useURL = String( _cfg.manifest_url );

// being deprecated, soon unsupported!
if( useURL.isEmpty() && !checkURL.isEmpty() ) {
Serial.println("checkURL will soon be unsupported, use FOTAConfig_t::manifest_url instead!!");
useURL = checkURL;
if( useURL.isEmpty() ) {
Serial.println("No manifest_url provided in config, aborting!");
return false;
}

// being deprecated, soon unsupported!
if( useDeviceID ) {
Serial.println("useDeviceID will soon be unsupported, use FOTAConfig_t::use_device_id instead!!");
_cfg.use_device_id = useDeviceID;
}
// if( useURL.isEmpty() && !checkURL.isEmpty() ) {
// Serial.println("checkURL will soon be unsupported, use FOTAConfig_t::manifest_url instead!!");
// useURL = checkURL;
// }

// // being deprecated, soon unsupported!
// if( useDeviceID ) {
// Serial.println("useDeviceID will soon be unsupported, use FOTAConfig_t::use_device_id instead!!");
// _cfg.use_device_id = useDeviceID;
// }

if (_cfg.use_device_id) {
// URL may already have GET values
Expand Down Expand Up @@ -792,7 +824,7 @@ void esp32FOTA::forceUpdate(const char* firmwareURL, bool validate )

void esp32FOTA::forceUpdate(const char* firmwareHost, uint16_t firmwarePort, const char* firmwarePath, bool validate )
{
String firmwareURL("http");
static String firmwareURL("http");
if ( firmwarePort == 443 || firmwarePort == 4433 ) firmwareURL += "s";
firmwareURL += String(firmwareHost);
firmwareURL += ":";
Expand Down
9 changes: 5 additions & 4 deletions src/esp32FOTA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ class esp32FOTA
void useDeviceId( bool use=true ) { _cfg.use_device_id = use; }

// config setter
void setConfig( FOTAConfig_t cfg ) { _cfg = cfg; }
void setConfig( FOTAConfig_t cfg );

// Manually specify the manifest url, this is provided as a transition between legagy and new config system
void setManifestURL( const String &manifest_url ) { _cfg.manifest_url = manifest_url.c_str(); }
void setManifestURL( const String &manifest_url ) { setString( _cfg.manifest_url, manifest_url.c_str() ); }

// use this to set "Authorization: Basic" or other specific headers to be sent with the queries
void setExtraHTTPHeader( String name, String value ) { extraHTTPHeaders[name] = value; }
Expand Down Expand Up @@ -311,8 +311,8 @@ class esp32FOTA
bool setupHTTP( const char* url );
void setFotaStream( Stream* stream ) { _stream = stream; }

[[deprecated("Use setManifestURL( String ) or cfg.manifest_url with setConfig( FOTAConfig_t )")]] String checkURL = "";
[[deprecated("Use cfg.use_device_id with setConfig( FOTAConfig_t )")]] bool useDeviceID = false;
//[[deprecated("Use setManifestURL( String ) or cfg.manifest_url with setConfig( FOTAConfig_t )")]] String checkURL = "";
//[[deprecated("Use cfg.use_device_id with setConfig( FOTAConfig_t )")]] bool useDeviceID = false;


private:
Expand All @@ -329,6 +329,7 @@ class esp32FOTA

void setupStream();
void stopStream();
void setString( const char *dest, const char* src ); // mem allocator

FOTAConfig_t _cfg;

Expand Down