@@ -387,34 +387,32 @@ bool FirmwareVersionCheck( char *firmware_latest, String firmware_ota_url ) {
387
387
if ( pemfile ) {
388
388
char *DownloadServerPemChain = nullptr ;
389
389
size_t pemSize = pemfile.size ();
390
- if ( pemSize == 0 ) {
391
- DownloadServerPemChain = (char *)malloc (pemSize);
392
- if ( pemSize != pemfile.readBytes (DownloadServerPemChain, pemSize) ) {
393
- Serial.printf (" Reading %s pem server certificate chain failed.\r\n " ,DOWNLOAD_CERT_PEM_FILE);
390
+ DownloadServerPemChain = (char *)malloc (pemSize);
391
+ if ( pemSize != pemfile.readBytes (DownloadServerPemChain, pemSize) ) {
392
+ Serial.printf (" Reading %s pem server certificate chain failed.\r\n " ,DOWNLOAD_CERT_PEM_FILE);
393
+ } else {
394
+ Serial.printf (" Read %s pem server certificate chain from SPIFFS\r\n " ,DOWNLOAD_CERT_PEM_FILE);
395
+ Serial.write ((const unsigned char *)DownloadServerPemChain,pemSize);
396
+
397
+ // Increase the watchdog timer before starting the firmware upgrade
398
+ // The download and write can trip the watchdog timer and the old firmware
399
+ // will abort / reset before the new firmware is complete.
400
+ esp_task_wdt_init (15 ,0 );
401
+
402
+ Serial.println (" Starting OpenEEW OTA firmware upgrade..." );
403
+ esp_http_client_config_t config = {0 };
404
+ config.url = firmware_ota_url.c_str () ;
405
+ config.cert_pem = DownloadServerPemChain ;
406
+ esp_err_t ret = esp_https_ota (&config);
407
+ if (ret == ESP_OK) {
408
+ Serial.println (" OTA upgrade downloaded. Restarting..." );
409
+ esp_restart ();
394
410
} else {
395
- Serial.printf (" Read %s pem server certificate chain from SPIFFS\r\n " ,DOWNLOAD_CERT_PEM_FILE);
396
- Serial.write ((const unsigned char *)DownloadServerPemChain,pemSize);
397
-
398
- // Increase the watchdog timer before starting the firmware upgrade
399
- // The download and write can trip the watchdog timer and the old firmware
400
- // will abort / reset before the new firmware is complete.
401
- esp_task_wdt_init (15 ,0 );
402
-
403
- Serial.println (" Starting OpenEEW OTA firmware upgrade..." );
404
- esp_http_client_config_t config = {0 };
405
- config.url = firmware_ota_url.c_str () ;
406
- config.cert_pem = DownloadServerPemChain ;
407
- esp_err_t ret = esp_https_ota (&config);
408
- if (ret == ESP_OK) {
409
- Serial.println (" OTA upgrade downloaded. Restarting..." );
410
- esp_restart ();
411
- } else {
412
- esp_task_wdt_init (5 ,0 );
413
- Serial.println (" The OpenEEW OTA firmware upgrade failed : ESP_FAIL" );
414
- }
411
+ esp_task_wdt_init (5 ,0 );
412
+ Serial.println (" The OpenEEW OTA firmware upgrade failed : ESP_FAIL" );
415
413
}
416
- free ( DownloadServerPemChain );
417
414
}
415
+ free ( DownloadServerPemChain );
418
416
} else {
419
417
Serial.println (" Failed to open server pem chain." );
420
418
}
0 commit comments