Skip to content

Commit ae10808

Browse files
authored
Merge pull request #117 from chrisjoyce911/0.2.6
0.2.6
2 parents 0a067ad + 4a902d2 commit ae10808

File tree

11 files changed

+108
-39
lines changed

11 files changed

+108
-39
lines changed

.github/workflows/arduino.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Arduino Build
2+
3+
# The workflow will run on every push and pull request to the repository
4+
on:
5+
- push
6+
- pull_request
7+
8+
jobs:
9+
compile-sketch:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
14+
- name: Checkout repository
15+
uses: actions/checkout@v3
16+
17+
- name: Compile examples
18+
uses: arduino/compile-sketches@v1
19+
with:
20+
github-token: ${{ secrets.GITHUB_TOKEN }}
21+
fqbn: esp32:esp32:esp32
22+
platforms: |
23+
- name: esp32:esp32
24+
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
25+
libraries: |
26+
- name: esp32FOTA
27+
path: ./
28+
- name: ArduinoJson
29+
- name: ESP32-targz
30+
- name: esp32-flashz
31+
source-url: https://github.com/vortigont/esp32-flashz.git
32+
33+
#sketch-paths: |
34+
#- examples/HTTP/HTTP/HTTP.ino
35+
cli-compile-flags: |
36+
- --warnings="default"

.github/workflows/platformio.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ jobs:
4242
ls
4343
mkdir -p tests/test_http
4444
mkdir -p tests/test_https
45-
cp examples/HTTP/HTTP.ino tests/test_http/main.cpp
46-
cp examples/HTTP/HTTPS.ino tests/test_https/main.cpp
45+
cp examples/HTTP/HTTP/HTTP.ino tests/test_http/main.cpp
46+
cp examples/HTTP/HTTPS/HTTPS.ino tests/test_https/main.cpp
4747
# globally install the esp32FOTA library from local folder, don't update the platformio.ini
4848
pio lib install --no-save file://$(realpath ./)
4949
pio run
File renamed without changes.
File renamed without changes.

examples/withDeviceID/withDeviceID.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const char *ssid = "";
2222
const char *password = "";
2323

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

2828
void setup()
@@ -54,10 +54,10 @@ void setup_wifi()
5454

5555
void loop()
5656
{
57-
bool updatedNeeded = FOTA.execHTTPcheck();
57+
bool updatedNeeded = esp32FOTA.execHTTPcheck();
5858
if (updatedNeeded)
5959
{
60-
FOTA.execOTA();
60+
esp32FOTA.execOTA();
6161
}
6262

6363
delay(2000);

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "esp32FOTA",
3-
"version": "0.2.5",
3+
"version": "0.2.6",
44
"keywords": "firmware, OTA, Over The Air Updates, ArduinoOTA",
55
"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.",
66
"examples": "examples/*/*.ino",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=esp32FOTA
2-
version=0.2.5
2+
version=0.2.6
33
author=Chris Joyce
44
maintainer=Chris Joyce <chris@joyce.id.au>
55
sentence=A simple library for firmware OTA updates

src/esp32FOTA.cpp

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,22 @@ esp32FOTA::~esp32FOTA(){}
120120

121121
esp32FOTA::esp32FOTA( FOTAConfig_t cfg )
122122
{
123-
setConfig( cfg );
123+
setConfig( cfg );
124124
}
125125

126126

127+
void esp32FOTA::setString( const char *dest, const char* src )
128+
{
129+
if( !src ) return;
130+
dest = (const char*)calloc( strlen(src)+1, sizeof(char));
131+
strcpy( (char*)dest, src );
132+
}
133+
134+
135+
127136
esp32FOTA::esp32FOTA(const char* firmwareType, int firmwareVersion, bool validate, bool allow_insecure_https)
128137
{
138+
setString( _cfg.name, firmwareType );
129139
_cfg.name = firmwareType;
130140
_cfg.sem = SemverClass( firmwareVersion );
131141
_cfg.check_sig = validate;
@@ -138,7 +148,7 @@ esp32FOTA::esp32FOTA(const char* firmwareType, int firmwareVersion, bool validat
138148

139149
esp32FOTA::esp32FOTA(const char* firmwareType, const char* firmwareSemanticVersion, bool validate, bool allow_insecure_https)
140150
{
141-
_cfg.name = firmwareType;
151+
setString( _cfg.name, firmwareType );
142152
_cfg.check_sig = validate;
143153
_cfg.unsafe = allow_insecure_https;
144154
_cfg.sem = SemverClass( firmwareSemanticVersion );
@@ -149,6 +159,21 @@ esp32FOTA::esp32FOTA(const char* firmwareType, const char* firmwareSemanticVersi
149159

150160

151161

162+
void esp32FOTA::setConfig( FOTAConfig_t cfg )
163+
{
164+
setString( _cfg.name, cfg.name );
165+
setString( _cfg.manifest_url, cfg.manifest_url );
166+
167+
_cfg.sem = cfg.sem;
168+
_cfg.check_sig = cfg.check_sig;
169+
_cfg.unsafe = cfg.unsafe;
170+
_cfg.use_device_id = cfg.use_device_id;
171+
_cfg.root_ca = cfg.root_ca;
172+
_cfg.pub_key = cfg.pub_key;
173+
}
174+
175+
176+
152177

153178
void esp32FOTA::setCertFileSystem( fs::FS *cert_filesystem )
154179
{
@@ -419,15 +444,17 @@ bool esp32FOTA::execOTA()
419444
bool esp32FOTA::execOTA( int partition, bool restart_after )
420445
{
421446
// health checks
447+
if( partition != U_SPIFFS && partition != U_FLASH ) {
448+
Serial.printf("Bad partition number: %i or empty URL, aborting\n", partition);
449+
return false;
450+
}
422451
if( partition == U_SPIFFS && _flashFileSystemUrl.isEmpty() ) {
423-
log_i("[SKIP] No spiffs/littlefs/fatfs partition was specified");
424-
return true; // data partition is optional, so not an error
425-
} else if ( partition == U_FLASH && _firmwareUrl.isEmpty() ) {
426-
log_e("No app partition was specified");
427-
return false; // app partition is mandatory
428-
} else if( partition != U_SPIFFS && partition != U_FLASH ) {
429-
log_e("Bad partition number: %i or empty URL", partition);
430-
return false;
452+
log_i("[SKIP] No spiffs/littlefs/fatfs partition was specified");
453+
return true; // data partition is optional, so not an error
454+
}
455+
if ( partition == U_FLASH && _firmwareUrl.isEmpty() ) {
456+
Serial.printf("No firmware URL, aborting\n");
457+
return false; // app partition is mandatory
431458
}
432459

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

457484
if( _cfg.check_sig ) {
458-
if( mode_z ) {
459-
Serial.println("[ERROR] Compressed && signed image is not (yet) supported");
460-
return false;
461-
}
462-
if( updateSize == UPDATE_SIZE_UNKNOWN || updateSize <= FW_SIGNATURE_LENGTH ) {
463-
Serial.println("[ERROR] Malformed signature+fw combo");
464-
return false;
465-
}
466-
updateSize -= FW_SIGNATURE_LENGTH;
485+
if( mode_z ) {
486+
Serial.println("[ERROR] Compressed && signed image is not (yet) supported");
487+
return false;
488+
}
489+
if( updateSize == UPDATE_SIZE_UNKNOWN || updateSize <= FW_SIGNATURE_LENGTH ) {
490+
Serial.println("[ERROR] Malformed signature+fw combo");
491+
return false;
492+
}
493+
updateSize -= FW_SIGNATURE_LENGTH;
467494
}
468495

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

698-
// being deprecated, soon unsupported!
699-
if( useURL.isEmpty() && !checkURL.isEmpty() ) {
700-
Serial.println("checkURL will soon be unsupported, use FOTAConfig_t::manifest_url instead!!");
701-
useURL = checkURL;
725+
if( useURL.isEmpty() ) {
726+
Serial.println("No manifest_url provided in config, aborting!");
727+
return false;
702728
}
703729

704730
// being deprecated, soon unsupported!
705-
if( useDeviceID ) {
706-
Serial.println("useDeviceID will soon be unsupported, use FOTAConfig_t::use_device_id instead!!");
707-
_cfg.use_device_id = useDeviceID;
708-
}
731+
// if( useURL.isEmpty() && !checkURL.isEmpty() ) {
732+
// Serial.println("checkURL will soon be unsupported, use FOTAConfig_t::manifest_url instead!!");
733+
// useURL = checkURL;
734+
// }
735+
736+
// // being deprecated, soon unsupported!
737+
// if( useDeviceID ) {
738+
// Serial.println("useDeviceID will soon be unsupported, use FOTAConfig_t::use_device_id instead!!");
739+
// _cfg.use_device_id = useDeviceID;
740+
// }
709741

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

793825
void esp32FOTA::forceUpdate(const char* firmwareHost, uint16_t firmwarePort, const char* firmwarePath, bool validate )
794826
{
795-
String firmwareURL("http");
827+
static String firmwareURL("http");
796828
if ( firmwarePort == 443 || firmwarePort == 4433 ) firmwareURL += "s";
797829
firmwareURL += String(firmwareHost);
798830
firmwareURL += ":";

0 commit comments

Comments
 (0)