@@ -120,12 +120,22 @@ esp32FOTA::~esp32FOTA(){}
120
120
121
121
esp32FOTA::esp32FOTA ( FOTAConfig_t cfg )
122
122
{
123
- setConfig ( cfg );
123
+ setConfig ( cfg );
124
124
}
125
125
126
126
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
+
127
136
esp32FOTA::esp32FOTA (const char * firmwareType, int firmwareVersion, bool validate, bool allow_insecure_https)
128
137
{
138
+ setString ( _cfg.name , firmwareType );
129
139
_cfg.name = firmwareType;
130
140
_cfg.sem = SemverClass ( firmwareVersion );
131
141
_cfg.check_sig = validate;
@@ -138,7 +148,7 @@ esp32FOTA::esp32FOTA(const char* firmwareType, int firmwareVersion, bool validat
138
148
139
149
esp32FOTA::esp32FOTA (const char * firmwareType, const char * firmwareSemanticVersion, bool validate, bool allow_insecure_https)
140
150
{
141
- _cfg.name = firmwareType;
151
+ setString ( _cfg.name , firmwareType ) ;
142
152
_cfg.check_sig = validate;
143
153
_cfg.unsafe = allow_insecure_https;
144
154
_cfg.sem = SemverClass ( firmwareSemanticVersion );
@@ -149,6 +159,21 @@ esp32FOTA::esp32FOTA(const char* firmwareType, const char* firmwareSemanticVersi
149
159
150
160
151
161
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
+
152
177
153
178
void esp32FOTA::setCertFileSystem ( fs::FS *cert_filesystem )
154
179
{
@@ -419,15 +444,17 @@ bool esp32FOTA::execOTA()
419
444
bool esp32FOTA::execOTA ( int partition, bool restart_after )
420
445
{
421
446
// 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
+ }
422
451
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
431
458
}
432
459
433
460
// call getHTTPStream
@@ -455,15 +482,15 @@ bool esp32FOTA::execOTA( int partition, bool restart_after )
455
482
log_d (" compression: %s" , mode_z ? " enabled" : " disabled" );
456
483
457
484
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;
467
494
}
468
495
469
496
// If using compression, the size is implicitely unknown
@@ -695,17 +722,22 @@ bool esp32FOTA::execHTTPcheck()
695
722
{
696
723
String useURL = String ( _cfg.manifest_url );
697
724
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 ;
702
728
}
703
729
704
730
// 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
+ // }
709
741
710
742
if (_cfg.use_device_id ) {
711
743
// URL may already have GET values
@@ -792,7 +824,7 @@ void esp32FOTA::forceUpdate(const char* firmwareURL, bool validate )
792
824
793
825
void esp32FOTA::forceUpdate (const char * firmwareHost, uint16_t firmwarePort, const char * firmwarePath, bool validate )
794
826
{
795
- String firmwareURL (" http" );
827
+ static String firmwareURL (" http" );
796
828
if ( firmwarePort == 443 || firmwarePort == 4433 ) firmwareURL += " s" ;
797
829
firmwareURL += String (firmwareHost);
798
830
firmwareURL += " :" ;
0 commit comments