@@ -318,13 +318,13 @@ void esp32FOTA::execOTA()
318
318
}
319
319
320
320
bool esp32FOTA::checkJSONManifest (JsonVariant JSONDocument) {
321
- log_i (" Payload type: %s" , JSONDocument[" type" ].as <const char *>() );
322
321
323
322
if (strcmp (JSONDocument[" type" ].as <const char *>(), _firmwareType.c_str ()) != 0 ) {
323
+ log_i (" Payload type in manifest %s doesn't match current firmware %s" , JSONDocument[" type" ].as <const char *>(), _firmwareType.c_str () );
324
324
log_i (" Doesn't match type: %s" , _firmwareType.c_str () );
325
325
return false ; // Move to the next entry in the manifest
326
326
}
327
- log_i (" Matches type: %s " , _firmwareType.c_str () );
327
+ log_i (" Payload type in manifest %s matches current firmware %s " , JSONDocument[ " type " ]. as < const char *>() , _firmwareType.c_str () );
328
328
329
329
semver_free (&_payloadVersion);
330
330
if (JSONDocument[" version" ].is <uint16_t >()) {
@@ -393,62 +393,71 @@ bool esp32FOTA::execHTTPcheck()
393
393
return false ; // WiFi not connected
394
394
}
395
395
396
- HTTPClient http;
397
- WiFiClientSecure client;
398
-
399
- if ( useURL.substring ( 0 , 5 ) == " https" ) {
400
- if (!_allow_insecure_https) {
401
- // If the checkURL is https load the root-CA and connect with that
402
- log_i ( " Loading root_ca.pem" );
403
- File root_ca_file = SPIFFS.open ( " /root_ca.pem" );
404
- if ( !root_ca_file ) {
405
- log_e ( " Could not open root_ca.pem" );
406
- return false ;
407
- }
408
- {
409
- std::string root_ca = " " ;
410
- while ( root_ca_file.available () ){
411
- root_ca.push_back ( root_ca_file.read () );
412
- }
413
- root_ca_file.close ();
414
- http.begin ( useURL, root_ca.c_str () );
396
+ HTTPClient http;
397
+ WiFiClientSecure client;
398
+
399
+ if ( useURL.substring ( 0 , 5 ) == " https" ) {
400
+ if (!_allow_insecure_https) {
401
+ // If the checkURL is https load the root-CA and connect with that
402
+ log_i ( " Loading root_ca.pem" );
403
+ File root_ca_file = SPIFFS.open ( " /root_ca.pem" );
404
+ if ( !root_ca_file ) {
405
+ log_e ( " Could not open root_ca.pem" );
406
+ return false ;
407
+ }
408
+ {
409
+ std::string root_ca = " " ;
410
+ while ( root_ca_file.available () ){
411
+ root_ca.push_back ( root_ca_file.read () );
415
412
}
416
- } else {
417
- // We're downloading from a secure port, but we don't want to validate the root cert.
418
- client.setInsecure ();
419
- http.begin (client, useURL);
413
+ root_ca_file.close ();
414
+ http.begin ( useURL, root_ca.c_str () );
420
415
}
421
416
} else {
422
- http.begin (useURL); // Specify the URL
417
+ // We're downloading from a secure port, but we don't want to validate the root cert.
418
+ client.setInsecure ();
419
+ http.begin (client, useURL);
423
420
}
424
- int httpCode = http.GET (); // Make the request
421
+ } else {
422
+ http.begin (useURL); // Specify the URL
423
+ }
424
+ int httpCode = http.GET (); // Make the request
425
425
426
- if ( httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY ) { // Check is a file was returned
426
+ if ( httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY ) { // Check is a file was returned
427
427
428
- String payload = http.getString ();
428
+ String payload = http.getString ();
429
429
430
- int str_len = payload.length () + 1 ;
431
- char JSONMessage[str_len];
432
- payload.toCharArray (JSONMessage, str_len);
430
+ int str_len = payload.length () + 1 ;
431
+ char JSONMessage[str_len];
432
+ payload.toCharArray (JSONMessage, str_len);
433
433
434
- StaticJsonDocument< 300 > JSONDocument; // Memory pool
435
- DeserializationError err = deserializeJson (JSONDocument , JSONMessage);
434
+ DynamicJsonDocument JSONResult ( 2048 );
435
+ DeserializationError err = deserializeJson (JSONResult , JSONMessage);
436
436
437
- http.end (); // We're done with HTTP - free the resources
437
+ http.end (); // We're done with HTTP - free the resources
438
438
439
- if (err) { // Check for errors in parsing
440
- log_e (" Parsing failed" );
441
- return false ;
442
- }
439
+ if (err) { // Check for errors in parsing
440
+ log_e (" Parsing failed" );
441
+ return false ;
442
+ }
443
443
444
- if (checkJSONManifest (JSONDocument.as <JsonVariant>())) {
445
- return true ;
444
+ if (JSONResult.is <JsonArray>()) {
445
+ // We already received an array of multiple firmware types
446
+ JsonArray arr = JSONResult.as <JsonArray>();
447
+ for (JsonVariant JSONDocument : arr) {
448
+ if (checkJSONManifest (JSONDocument)) {
449
+ return true ;
450
+ }
446
451
}
447
-
448
- return false ; // We didn't get a hit against the above, return false
449
- } else {
450
- log_e (" Error on HTTP request" );
452
+ } else if (JSONResult.is <JsonObject>()) {
453
+ if (checkJSONManifest (JSONResult.as <JsonVariant>()))
454
+ return true ;
451
455
}
456
+
457
+ return false ; // We didn't get a hit against the above, return false
458
+ } else {
459
+ log_e (" Error on HTTP request" );
460
+ http.end ();
452
461
return false ;
453
462
}
454
463
}
0 commit comments