update process more informative display, color accent of messages;

increased OTA URL length;
implemented reset after update setting;
This commit is contained in:
Bogdan Pilyugin 2023-01-24 16:04:05 +02:00
parent a7340c1a35
commit 111839f329
3 changed files with 24 additions and 12 deletions

View File

@ -44,7 +44,7 @@
char NetBIOSName[32]; ///< NetBIOS name char NetBIOSName[32]; ///< NetBIOS name
char SysName[32]; ///< User Name char SysName[32]; ///< User Name
char SysPass[32]; ///< User Password char SysPass[32]; ///< User Password
char OTAURL[64]; ///< OTA URL char OTAURL[128]; ///< OTA URL
int OTAAutoInt; int OTAAutoInt;
char SN[11]; ///< String of serial number (decimal ID) char SN[11]; ///< String of serial number (decimal ID)

View File

@ -377,7 +377,7 @@ static HTTP_IO_RESULT HTTPPostServicesSettings(httpd_req_t *req, char *PostData)
static HTTP_IO_RESULT HTTPPostSystemSettings(httpd_req_t *req, char *PostData) static HTTP_IO_RESULT HTTPPostSystemSettings(httpd_req_t *req, char *PostData)
{ {
char tmp[64]; char tmp[128];
bool TempIsOTAEnabled = false; bool TempIsOTAEnabled = false;
bool TempIsRstEnabled = false; bool TempIsRstEnabled = false;
if (httpd_query_key_value(PostData, "nam", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "nam", tmp, sizeof(tmp)) == ESP_OK)

View File

@ -1,4 +1,4 @@
/* Copyright 2022 Bogdan Pilyugin /* Copyright 2022 Bogdan Pilyugin
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,6 +30,8 @@
#include <string.h> #include <string.h>
#include "sdkconfig.h" #include "sdkconfig.h"
#include "romfs.h" #include "romfs.h"
#include "nvs_flash.h"
#include "nvs.h"
#include <sys/socket.h> #include <sys/socket.h>
#include <WebGUIAppMain.h> #include <WebGUIAppMain.h>
@ -41,7 +43,7 @@ extern const uint8_t server_cert_pem_start[] asm("_binary_ca_cert_pem_start");
extern const uint8_t server_cert_pem_end[] asm("_binary_ca_cert_pem_end"); extern const uint8_t server_cert_pem_end[] asm("_binary_ca_cert_pem_end");
char AvailFwVersion[32] = "Unknown"; char AvailFwVersion[32] = "Unknown";
char FwUpdStatus[32] = "Updated"; char FwUpdStatus[64] = "<div class='clok'>Updated</div>";
#define HASH_LEN 32 #define HASH_LEN 32
#define REPORT_PACKETS_EVERY 100 #define REPORT_PACKETS_EVERY 100
@ -177,7 +179,8 @@ esp_err_t my_esp_https_ota(const esp_http_client_config_t *config)
} }
if (++countPackets >= REPORT_PACKETS_EVERY) if (++countPackets >= REPORT_PACKETS_EVERY)
{ {
sprintf(FwUpdStatus, "Updated %d bytes", esp_https_ota_get_image_len_read(https_ota_handle)); sprintf(FwUpdStatus, "<div class='clok'>Updated %d bytes...</div>",
esp_https_ota_get_image_len_read(https_ota_handle));
ESP_LOGI(TAG, "%s", FwUpdStatus); ESP_LOGI(TAG, "%s", FwUpdStatus);
countPackets = 0; countPackets = 0;
} }
@ -186,14 +189,14 @@ esp_err_t my_esp_https_ota(const esp_http_client_config_t *config)
if (err != ESP_OK) if (err != ESP_OK)
{ {
esp_https_ota_abort(https_ota_handle); esp_https_ota_abort(https_ota_handle);
strcpy(FwUpdStatus,"Error update"); strcpy(FwUpdStatus, "<div class='clerr'>Error update</div>");
return err; return err;
} }
} }
else else
{ {
ESP_LOGI(TAG, "New firmware has NOT newer build, SKIP update firmware"); ESP_LOGI(TAG, "New firmware has NOT newer build, SKIP update firmware");
strcpy(FwUpdStatus,"Updated actual"); strcpy(FwUpdStatus, "<div class='clok'>Updated actual</div>");
} }
esp_err_t ota_finish_err = esp_https_ota_finish(https_ota_handle); esp_err_t ota_finish_err = esp_https_ota_finish(https_ota_handle);
@ -203,8 +206,16 @@ esp_err_t my_esp_https_ota(const esp_http_client_config_t *config)
} }
if (need_to_update) if (need_to_update)
{ {
ESP_LOGI(TAG, "Firmware updated and now restarting..."); ESP_LOGI(TAG, "Firmware updated");
strcpy(FwUpdStatus, "<div class='clok'>Updated ok. Restart...</div>");
if (GetSysConf()->Flags1.bIsResetOTAEnabled)
{
ESP_ERROR_CHECK(nvs_flash_erase());
ESP_ERROR_CHECK(nvs_flash_init());
ESP_ERROR_CHECK(ResetInitSysConfig());
}
ESP_LOGI(TAG, "Firmware now restarting...");
vTaskDelay(pdMS_TO_TICKS(3000));
esp_restart(); esp_restart();
} }
return ESP_OK; return ESP_OK;
@ -258,11 +269,11 @@ static void OTATask(void *pvParameter)
else else
{ {
ESP_LOGE(TAG, "Firmware upgrade failed"); ESP_LOGE(TAG, "Firmware upgrade failed");
strcpy(FwUpdStatus, "<div class='clerr'>Error update</div>");
} }
free(certbuf); free(certbuf);
espfs_fclose(file); espfs_fclose(file);
update_error: update_error:
vTaskDelete(NULL); vTaskDelete(NULL);
} }
@ -285,6 +296,7 @@ esp_err_t StartOTA(void)
return ESP_ERR_NOT_FINISHED; return ESP_ERR_NOT_FINISHED;
} }
ESP_LOGI(TAG, "Starting OTA Task"); ESP_LOGI(TAG, "Starting OTA Task");
strcpy(FwUpdStatus, "<div class='clwarn'>Start update...</div>");
xTaskCreate(OTATask, "OTATask", 1024 * 8, (void*) 0, 3, NULL); xTaskCreate(OTATask, "OTATask", 1024 * 8, (void*) 0, 3, NULL);
return ESP_OK; return ESP_OK;
} }