firmware update progress added
This commit is contained in:
parent
0f75145a5f
commit
a7340c1a35
5
Kconfig
5
Kconfig
|
|
@ -44,8 +44,11 @@ menu "WebGUIApp"
|
|||
menu "OTA settings"
|
||||
config WEBGUIAPP_OTA_AUTOUPDATE_ENABLE
|
||||
bool "Enabled OTA autoupdate firmware"
|
||||
default y
|
||||
default n
|
||||
|
||||
config WEBGUIAPP_OTA_RESET_ENABLE
|
||||
bool "Enabled reset config on OTA update"
|
||||
default n
|
||||
|
||||
config WEBGUIAPP_OTA_HOST
|
||||
string "URL of firmware for OTA update"
|
||||
|
|
|
|||
|
|
@ -100,6 +100,8 @@ void GetRFC3339Time(char *t);
|
|||
void StartTimeGet(void);
|
||||
|
||||
esp_err_t StartOTA(void);
|
||||
char* GetAvailVersion();
|
||||
char* GetUpdateStatus();
|
||||
|
||||
void StartSystemTimer(void);
|
||||
uint32_t GetUpTime(void);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@
|
|||
char SysName[32]; ///< User Name
|
||||
char SysPass[32]; ///< User Password
|
||||
char OTAURL[64]; ///< OTA URL
|
||||
int OTAAutoInt;
|
||||
|
||||
char SN[11]; ///< String of serial number (decimal ID)
|
||||
char ID[9]; ///< String of ID ( last 4 bytes of MAC)
|
||||
|
|
@ -52,10 +53,10 @@
|
|||
struct
|
||||
{
|
||||
char bIsOTAEnabled :1;
|
||||
char bIsResetOTAEnabled :1;
|
||||
char bIsLedsEnabled :1; ///< Indication LEDs enable
|
||||
char bIsLoRaConfirm :1; ///< Enable send back confirmation in LoRa channel
|
||||
char bIsTCPConfirm :1; ///< Enable send back confirmation in TCP channel
|
||||
char bit4 :1;
|
||||
char bit5 :1;
|
||||
char bit6 :1;
|
||||
char bit7 :1;
|
||||
|
|
|
|||
|
|
@ -105,26 +105,26 @@ static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData)
|
|||
if (httpd_query_key_value(PostData, "ethen", tmp, sizeof(tmp)) == ESP_OK)
|
||||
{
|
||||
if (!strcmp((const char*) tmp, (const char*) "1"))
|
||||
TempIsETHEnabled = true;
|
||||
TempIsETHEnabled = true;
|
||||
}
|
||||
if (httpd_query_key_value(PostData, "dhcp", tmp, sizeof(tmp)) == ESP_OK)
|
||||
{
|
||||
if (!strcmp((const char*) tmp, (const char*) "1"))
|
||||
TempIsETHDHCPEnabled = true;
|
||||
TempIsETHDHCPEnabled = true;
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(PostData, "ipa", tmp, 15) == ESP_OK)
|
||||
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.IPAddr);
|
||||
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.IPAddr);
|
||||
if (httpd_query_key_value(PostData, "mas", tmp, 15) == ESP_OK)
|
||||
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.Mask);
|
||||
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.Mask);
|
||||
if (httpd_query_key_value(PostData, "gte", tmp, 15) == ESP_OK)
|
||||
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.Gateway);
|
||||
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.Gateway);
|
||||
if (httpd_query_key_value(PostData, "dns1", tmp, 15) == ESP_OK)
|
||||
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.DNSAddr1);
|
||||
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.DNSAddr1);
|
||||
if (httpd_query_key_value(PostData, "dns2", tmp, 15) == ESP_OK)
|
||||
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.DNSAddr2);
|
||||
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.DNSAddr2);
|
||||
if (httpd_query_key_value(PostData, "dns3", tmp, 15) == ESP_OK)
|
||||
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.DNSAddr3);
|
||||
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.DNSAddr3);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -297,29 +297,29 @@ static HTTP_IO_RESULT HTTPPostServicesSettings(httpd_req_t *req, char *PostData)
|
|||
|
||||
#if CONFIG_WEBGUIAPP_MQTT_CLIENTS_NUM == 2
|
||||
httpd_query_key_value(PostData, "mqurl2", GetSysConf()->mqttStation[1].ServerAddr,
|
||||
sizeof(GetSysConf()->mqttStation[1].ServerAddr));
|
||||
sizeof(GetSysConf()->mqttStation[1].ServerAddr));
|
||||
httpd_query_key_value(PostData, "mqid2", GetSysConf()->mqttStation[1].ClientID,
|
||||
sizeof(GetSysConf()->mqttStation[1].ClientID));
|
||||
sizeof(GetSysConf()->mqttStation[1].ClientID));
|
||||
httpd_query_key_value(PostData, "mqsys2", GetSysConf()->mqttStation[1].SystemName,
|
||||
sizeof(GetSysConf()->mqttStation[1].SystemName));
|
||||
sizeof(GetSysConf()->mqttStation[1].SystemName));
|
||||
httpd_query_key_value(PostData, "mqgrp2", GetSysConf()->mqttStation[1].GroupName,
|
||||
sizeof(GetSysConf()->mqttStation[1].GroupName));
|
||||
sizeof(GetSysConf()->mqttStation[1].GroupName));
|
||||
httpd_query_key_value(PostData, "mqname2", GetSysConf()->mqttStation[1].UserName,
|
||||
sizeof(GetSysConf()->mqttStation[1].UserName));
|
||||
sizeof(GetSysConf()->mqttStation[1].UserName));
|
||||
|
||||
if (httpd_query_key_value(PostData, "mqen2", tmp, sizeof(tmp)) == ESP_OK)
|
||||
{
|
||||
if (!strcmp((const char*) tmp, (const char*) "1"))
|
||||
TempIsMQTT2Enabled = true;
|
||||
TempIsMQTT2Enabled = true;
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(PostData, "mqport2", tmp, sizeof(tmp)) == ESP_OK)
|
||||
if (httpd_query_key_value(PostData, "mqport2", tmp, sizeof(tmp)) == ESP_OK)
|
||||
{
|
||||
uint16_t tp = atoi((const char*) tmp);
|
||||
if (tp < 65535 && tp >= 1000)
|
||||
GetSysConf()->mqttStation[1].ServerPort = tp;
|
||||
}
|
||||
if (httpd_query_key_value(PostData, "mqport2", tmp, sizeof(tmp)) == ESP_OK)
|
||||
{
|
||||
uint16_t tp = atoi((const char*) tmp);
|
||||
if (tp < 65535 && tp >= 1000)
|
||||
GetSysConf()->mqttStation[1].ServerPort = tp;
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(PostData, "mqpass2", tmp, sizeof(tmp)) == ESP_OK &&
|
||||
strcmp(tmp, (const char*) "******"))
|
||||
|
|
@ -379,7 +379,7 @@ static HTTP_IO_RESULT HTTPPostSystemSettings(httpd_req_t *req, char *PostData)
|
|||
{
|
||||
char tmp[64];
|
||||
bool TempIsOTAEnabled = false;
|
||||
|
||||
bool TempIsRstEnabled = false;
|
||||
if (httpd_query_key_value(PostData, "nam", tmp, sizeof(tmp)) == ESP_OK)
|
||||
{
|
||||
UnencodeURL(tmp);
|
||||
|
|
@ -400,6 +400,19 @@ static HTTP_IO_RESULT HTTPPostSystemSettings(httpd_req_t *req, char *PostData)
|
|||
TempIsOTAEnabled = true;
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(PostData, "otarst", tmp, sizeof(tmp)) == ESP_OK)
|
||||
{
|
||||
if (!strcmp((const char*) tmp, (const char*) "1"))
|
||||
TempIsRstEnabled = true;
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(PostData, "otaint", tmp, sizeof(tmp)) == ESP_OK)
|
||||
{
|
||||
uint16_t tp = atoi((const char*) tmp);
|
||||
if (tp < 65535 && tp >= 1)
|
||||
GetSysConf()->OTAAutoInt = tp;
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(PostData, "otaurl", tmp, sizeof(tmp)) == ESP_OK)
|
||||
{
|
||||
UnencodeURL(tmp);
|
||||
|
|
@ -430,6 +443,7 @@ static HTTP_IO_RESULT HTTPPostSystemSettings(httpd_req_t *req, char *PostData)
|
|||
if (!strcmp(tmp, (const char*) "syst"))
|
||||
{
|
||||
GetSysConf()->Flags1.bIsOTAEnabled = TempIsOTAEnabled;
|
||||
GetSysConf()->Flags1.bIsResetOTAEnabled = TempIsRstEnabled;
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(PostData, "apply", tmp, 5) == ESP_OK)
|
||||
|
|
@ -450,7 +464,7 @@ static HTTP_IO_RESULT HTTPPostSystemSettings(httpd_req_t *req, char *PostData)
|
|||
{
|
||||
if (!strcmp(tmp, (const char*) "1"))
|
||||
{
|
||||
WiFiScan();
|
||||
WiFiScan();
|
||||
return HTTP_IO_DONE_NOREFRESH;
|
||||
}
|
||||
else if (!strcmp(tmp, (const char*) "2"))
|
||||
|
|
|
|||
|
|
@ -152,6 +152,15 @@ static void HTTPPrint_ota(char *VarData, void *arg)
|
|||
{
|
||||
PrintCheckbox(VarData, arg, GetSysConf()->Flags1.bIsOTAEnabled);
|
||||
}
|
||||
static void HTTPPrint_otarst(char *VarData, void *arg)
|
||||
{
|
||||
PrintCheckbox(VarData, arg, GetSysConf()->Flags1.bIsResetOTAEnabled);
|
||||
}
|
||||
|
||||
static void HTTPPrint_otaint(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%d", GetSysConf()->OTAAutoInt);
|
||||
}
|
||||
|
||||
static void HTTPPrint_serial(char *VarData, void *arg)
|
||||
{
|
||||
|
|
@ -170,6 +179,18 @@ static void HTTPPrint_fver(char *VarData, void *arg)
|
|||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", cur_app_info.version);
|
||||
}
|
||||
}
|
||||
|
||||
static void HTTPPrint_fverav(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", GetAvailVersion());
|
||||
}
|
||||
|
||||
static void HTTPPrint_updstat(char *VarData, void *arg)
|
||||
{
|
||||
snprintf(VarData, MAX_DYNVAR_LENGTH, "%s", GetUpdateStatus());
|
||||
}
|
||||
|
||||
|
||||
static void HTTPPrint_idfver(char *VarData, void *arg)
|
||||
{
|
||||
esp_app_desc_t cur_app_info;
|
||||
|
|
@ -668,7 +689,13 @@ dyn_var_handler_t HANDLERS_ARRAY[] = {
|
|||
{ "login", sizeof("login") - 1, &HTTPPrint_login },
|
||||
{ "pass", sizeof("pass") - 1, &HTTPPrint_pass },
|
||||
{ "ota", sizeof("ota") - 1, &HTTPPrint_ota },
|
||||
{ "otarst", sizeof("otarst") - 1, &HTTPPrint_otarst },
|
||||
{ "otaint", sizeof("otaint") - 1, &HTTPPrint_otaint },
|
||||
{ "fver", sizeof("fver") - 1, &HTTPPrint_fver },
|
||||
{ "fverav", sizeof("fverav") - 1, &HTTPPrint_fverav },
|
||||
{ "updstat", sizeof("updstat") - 1, &HTTPPrint_updstat },
|
||||
|
||||
|
||||
{ "idfver", sizeof("idfver") - 1, &HTTPPrint_idfver },
|
||||
{ "builddate", sizeof("builddate") - 1, &HTTPPrint_builddate },
|
||||
{ "serial", sizeof("serial") - 1, &HTTPPrint_serial },
|
||||
|
|
|
|||
19
src/OTA.c
19
src/OTA.c
|
|
@ -40,8 +40,10 @@ static const char *TAG = "OTAmodule";
|
|||
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");
|
||||
|
||||
char AvailFwVersion[32] = "Unknown";
|
||||
char FwUpdStatus[32] = "Updated";
|
||||
|
||||
#define HASH_LEN 32
|
||||
//#define CONFIG_FIRMWARE_UPGRADE_URL "https://iotronic.cloud:443/firmware/MStation2.bin"
|
||||
#define REPORT_PACKETS_EVERY 100
|
||||
|
||||
esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
||||
|
|
@ -156,6 +158,7 @@ esp_err_t my_esp_https_ota(const esp_http_client_config_t *config)
|
|||
ESP_LOGI(TAG, "********************************");
|
||||
|
||||
//Here compare new and old firmware and make decision of update needed
|
||||
strcpy(AvailFwVersion, new_app_info.version);
|
||||
ESP_LOGI(TAG, "Compare versions: current build is %d, update build is :%d",
|
||||
GetBuildNumber(cur_app_info.version),
|
||||
GetBuildNumber(new_app_info.version));
|
||||
|
|
@ -174,7 +177,8 @@ esp_err_t my_esp_https_ota(const esp_http_client_config_t *config)
|
|||
}
|
||||
if (++countPackets >= REPORT_PACKETS_EVERY)
|
||||
{
|
||||
ESP_LOGI(TAG, "Updated %d bytes", esp_https_ota_get_image_len_read(https_ota_handle));
|
||||
sprintf(FwUpdStatus, "Updated %d bytes", esp_https_ota_get_image_len_read(https_ota_handle));
|
||||
ESP_LOGI(TAG, "%s", FwUpdStatus);
|
||||
countPackets = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -182,12 +186,14 @@ esp_err_t my_esp_https_ota(const esp_http_client_config_t *config)
|
|||
if (err != ESP_OK)
|
||||
{
|
||||
esp_https_ota_abort(https_ota_handle);
|
||||
strcpy(FwUpdStatus,"Error update");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ESP_LOGI(TAG, "New firmware has NOT newer build, SKIP update firmware");
|
||||
strcpy(FwUpdStatus,"Updated actual");
|
||||
}
|
||||
|
||||
esp_err_t ota_finish_err = esp_https_ota_finish(https_ota_handle);
|
||||
|
|
@ -198,6 +204,7 @@ esp_err_t my_esp_https_ota(const esp_http_client_config_t *config)
|
|||
if (need_to_update)
|
||||
{
|
||||
ESP_LOGI(TAG, "Firmware updated and now restarting...");
|
||||
|
||||
esp_restart();
|
||||
}
|
||||
return ESP_OK;
|
||||
|
|
@ -282,4 +289,12 @@ esp_err_t StartOTA(void)
|
|||
return ESP_OK;
|
||||
}
|
||||
|
||||
char* GetAvailVersion()
|
||||
{
|
||||
return AvailFwVersion;
|
||||
}
|
||||
char* GetUpdateStatus()
|
||||
{
|
||||
return FwUpdStatus;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -271,6 +271,19 @@ static void ResetSysConfig(SYS_CONFIG *Conf)
|
|||
sizeof(CONFIG_WEBGUIAPP_USERPASS));
|
||||
|
||||
memcpy(Conf->OTAURL, CONFIG_WEBGUIAPP_OTA_HOST, sizeof(CONFIG_WEBGUIAPP_OTA_HOST));
|
||||
Conf->OTAAutoInt = CONFIG_WEBGUIAPP_OTA_AUTOUPDATE_PERIOD;
|
||||
|
||||
#if CONFIG_WEBGUIAPP_OTA_AUTOUPDATE_ENABLE
|
||||
Conf->Flags1.bIsOTAEnabled = true;
|
||||
#else
|
||||
Conf->Flags1.bIsOTAEnabled = false;
|
||||
#endif
|
||||
|
||||
#if CONFIG_WEBGUIAPP_OTA_RESET_ENABLE
|
||||
Conf->Flags1.bIsResetOTAEnabled = true;
|
||||
#else
|
||||
Conf->Flags1.bIsResetOTAEnabled = false;
|
||||
#endif
|
||||
|
||||
#if CONFIG_WEBGUIAPP_WIFI_ENABLE
|
||||
Conf->wifiSettings.Flags1.bIsWiFiEnabled = CONFIG_WEBGUIAPP_WIFI_ON;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user