fixed webguiapp default configuration;

changed network ready conditions checks;
This commit is contained in:
Bogdan Pilyugin 2023-01-12 15:40:39 +02:00
parent 67cf2bf3a9
commit 50f8656b7a
4 changed files with 331 additions and 331 deletions

49
Kconfig
View File

@ -40,6 +40,55 @@ menu "WebGUIApp"
default n default n
help help
This will reset to default settings on every startup This will reset to default settings on every startup
menu "OTA settings"
config WEBGUIAPP_OTA_AUTOUPDATE_ENABLE
bool "Enabled OTA autoupdate firmware"
default y
config WEBGUIAPP_OTA_HOST
string "URL of firmware for OTA update"
default "https://iotronic.cloud/firmware/firmware.bin"
help
URL of firmware file for OTA update
config WEBGUIAPP_OTA_AUTOUPDATE_PERIOD
int "OTA autoupdate period in seconds"
range 1 100000
default 3600
help
Autoupdate period for OTA
endmenu
menu "SNTP client settings"
config WEBGUIAPP_SNTP_AUTOUPDATE_ENABLE
bool "Enabled SNTP time update"
default y
config WEBGUIAPP_SNTP_HOST
string "URL of SNTP server"
default "2.pool.ntp.org"
help
URL of firmware file for OTA update
config WEBGUIAPP_SNTP_AUTOUPDATE_PERIOD
int "SNTP autoupdate period in seconds"
range 1 100000
default 3600
help
Autoupdate period for SNTP client
config WEBGUIAPP_SNTP_TIMEZONE
int "Timezone"
range -12 12
default 2
help
Timezone in hours. Positive for East and negative for the West
endmenu
menu "SPI settings" menu "SPI settings"
config WEBGUIAPP_SPI_ENABLE config WEBGUIAPP_SPI_ENABLE

View File

@ -1,271 +1,223 @@
/*! 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.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
* \file SystemConfiguration.h * \file SystemConfiguration.h
* \version 1.0 * \version 1.0
* \date 2022-08-13 * \date 2022-08-13
* \author Bogdan Pilyugin * \author Bogdan Pilyugin
* \brief * \brief
* \details * \details
* \copyright Apache License, Version 2.0 * \copyright Apache License, Version 2.0
*/ */
#ifndef COMPONENTS_WEB_GUI_APPLICATION_INCLUDE_SYSTEMCONFIGURATION_H_ #ifndef COMPONENTS_WEB_GUI_APPLICATION_INCLUDE_SYSTEMCONFIGURATION_H_
#define COMPONENTS_WEB_GUI_APPLICATION_INCLUDE_SYSTEMCONFIGURATION_H_ #define COMPONENTS_WEB_GUI_APPLICATION_INCLUDE_SYSTEMCONFIGURATION_H_
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "esp_netif.h" #include "esp_netif.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#define DEFAULT_HOST_NAME "DEVICE_HOSTNAME" ///<Default host name of device // Application-dependent structure used to contain address information
#define SYSTEM_DEFAULT_USERNAME "user" /**
#define SYSTEM_DEFAULT_PASSWORD "password" * @struct APP_CONFIG
#define SYSTEM_DEFAULT_OTAURL "https://iotronic.cloud/firmware/HB75ControllerFirmware.bin" * @brief The main configuration structure
* @details This structure saving to EEPROM and loading from EEPROM\n
#define DEFAULT_SNTP_SERVERNAME "ntp5.stratum2.ru" * on device boot. On load the checksumm is calculate and compare to \n
#define DEFAULT_SNTP_TIMEZONE 2 * saved one. If find difference (due to eeprom memory distortions),\n
#define DEFAULT_SNTP_ETH_IS_ENABLED false * the default values will be loaded.
#define DEFAULT_SNTP_WIFI_IS_ENABLED false */
#define DEFAULT_SNTP_GLOBAL_ENABLED true typedef struct
{
#define DEFAULT_MQTT_SERVERNAME "iotronic.cloud" char NetBIOSName[32]; ///< NetBIOS name
#define DEFAULT_MQTT_SERVERPORT 1883 char SysName[32]; ///< User Name
#define DEFAULT_MQTT_CLIENTID "HB75_DISP1" char SysPass[32]; ///< User Password
#define DEFAULT_MQTT_CLIENTID2 "HB75_DISP2" char OTAURL[64]; ///< OTA URL
#define DEFAULT_MQTT_USERNAME "hb75_username"
#define DEFAULT_MQTT_USERPASS "hb75_pass" char SN[11]; ///< String of serial number (decimal ID)
#define DEFAULT_MQTT_ROOTTOPIC "HB75_CONTROLLER" char ID[9]; ///< String of ID ( last 4 bytes of MAC)
#define DEFAULT_MQTT_GLOBAL_ENABLED true
struct
//WIFI interface related constatnts {
#define DEFAULT_WIFI_SSID_INF_NAME "wifiapname" char bIsOTAEnabled :1;
#define DEFAULT_WIFI_SSID_INF_KEY "wifikey" char bIsLedsEnabled :1; ///< Indication LEDs enable
#define DEFAULT_WIFI_SSID_AP_NAME "HB75" char bIsLoRaConfirm :1; ///< Enable send back confirmation in LoRa channel
#define DEFAULT_WIFI_SSID_AP_KEY "123456789" char bIsTCPConfirm :1; ///< Enable send back confirmation in TCP channel
char bit4 :1;
#define DEFAULT_WIFI_IP_ADDR_INF "192.168.150.1" char bit5 :1;
#define DEFAULT_WIFI_MASK "255.255.255.0" char bit6 :1;
#define DEFAULT_WIFI_GATE "192.168.150.1" char bit7 :1;
#define DEFAULT_WIFI_IP_ADDR_AP "192.168.150.1" } Flags1; // Flag structure
#define DEFAULT_WIFI_FLAG_ISAP true struct
#define DEFAULT_WIFI_FLAG_DHCP_ENABLED true {
#define DEFAULT_WIFI_FLAG_ISWIFI_ENABLED true int TimeZone;
char SntpServerAdr[33];
#define DEFAULT_ETH_IP_ADDR "192.168.150.2" struct
#define DEFAULT_ETH_MASK "255.255.255.0" {
#define DEFAULT_ETH_GATE "192.168.150.1" char b1 :1;
char b2 :1;
#define DEFAULT_ETH_FLAG_DHCP_ENABLED true char b3 :1;
#define DEFAULT_ETH_FLAG_ISETH_ENABLED true char b4 :1;
char b5 :1;
#define DEFAULT_DNS1 "8.8.8.8" char b6 :1;
#define DEFAULT_DNS2 "4.4.8.8" char b7 :1;
#define DEFAULT_DNS3 "1.1.1.1" char bIsGlobalEnabled :1;
} Flags1;
} sntpClient;
// Application-dependent structure used to contain address information
#if CONFIG_WEBGUIAPP_MQTT_ENABLE
/** struct
* @struct APP_CONFIG {
* @brief The main configuration structure char ServerAddr[32];
* @details This structure saving to EEPROM and loading from EEPROM\n uint16_t ServerPort;
* on device boot. On load the checksumm is calculate and compare to \n char SystemName[32];
* saved one. If find difference (due to eeprom memory distortions),\n char GroupName[32];
* the default values will be loaded. char ClientID[32];
*/ char UserName[32];
typedef struct char UserPass[32];
{ struct
char NetBIOSName[32]; ///< NetBIOS name {
char SysName[32]; ///< User Name char b0 :1;
char SysPass[32]; ///< User Password char b1 :1;
char OTAURL[64]; ///< OTA URL char b2 :1;
char b3 :1;
char SN[11]; ///< String of serial number (decimal ID) char b4 :1;
char ID[9]; ///< String of ID ( last 4 bytes of MAC) char b5 :1;
char b6 :1;
struct char bIsGlobalEnabled :1;
{ } Flags1;
char bIsOTAEnabled :1; } mqttStation[CONFIG_WEBGUIAPP_MQTT_CLIENTS_NUM];
char bIsLedsEnabled :1; ///< Indication LEDs enable #endif
char bIsLoRaConfirm :1; ///< Enable send back confirmation in LoRa channel
char bIsTCPConfirm :1; ///< Enable send back confirmation in TCP channel #if CONFIG_WEBGUIAPP_ETHERNET_ENABLE
char bit4 :1; struct
char bit5 :1; {
char bit6 :1; esp_ip4_addr_t IPAddr; // IP address
char bit7 :1; esp_ip4_addr_t Mask; // network mask
} Flags1; // Flag structure esp_ip4_addr_t Gateway; // gateway
esp_ip4_addr_t DNSAddr1; //
struct esp_ip4_addr_t DNSAddr2; //
{ esp_ip4_addr_t DNSAddr3; //
int TimeZone; uint8_t MACAddr[6]; // MAC address
char SntpServerAdr[33];
struct struct
{ {
char bIsWifiEnabled :1; char bIsDHCPEnabled :1;
char bIsEthEnabled :1; char b1 :1;
char b3 :1; char b2 :1;
char b4 :1; char b3 :1;
char b5 :1; char b4 :1;
char b6 :1; char b5 :1;
char b7 :1; char b6 :1;
char bIsGlobalEnabled :1; char bIsETHEnabled :1;
} Flags1; } Flags1; // Flag structure
} sntpClient;
} ethSettings;
#if CONFIG_WEBGUIAPP_MQTT_ENABLE #endif
struct
{ #if CONFIG_WEBGUIAPP_WIFI_ENABLE
char ServerAddr[32]; struct
uint16_t ServerPort; {
char SystemName[32]; esp_ip4_addr_t InfIPAddr; // IP address in infrastructure(INF) mode
char GroupName[32]; esp_ip4_addr_t InfMask; // network mask in INF mode
char ClientID[32]; esp_ip4_addr_t InfGateway; // gateway IP in INF mode
char UserName[32]; esp_ip4_addr_t ApIPAddr; // IP address in Access point(AP) mode
char UserPass[32]; esp_ip4_addr_t DNSAddr1; // DNS in station mode
struct esp_ip4_addr_t DNSAddr2; // DNS in station mode
{ esp_ip4_addr_t DNSAddr3; // DNS in station mode
char b0 :1;
char b1 :1; char InfSSID[32]; // Wireless SSID in INF mode
char b2 :1; char InfSecurityKey[32]; // Network key in INF mode
char b3 :1; char ApSSID[32]; // Wireless SSID in AP mode
char b4 :1; char ApSecurityKey[32]; // Wireless key in AP mode
char b5 :1;
char b6 :1; char MACAddrInf[6]; // MAC address
char bIsGlobalEnabled :1; char MACAddrAp[6]; // MAC address
} Flags1;
} mqttStation[CONFIG_WEBGUIAPP_MQTT_CLIENTS_NUM]; struct
#endif {
char bIsDHCPEnabled :1;
#if CONFIG_WEBGUIAPP_ETHERNET_ENABLE char bIsAP :1;
struct char b2 :1;
{ char b3 :1;
esp_ip4_addr_t IPAddr; // IP address char b4 :1;
esp_ip4_addr_t Mask; // network mask char b5 :1;
esp_ip4_addr_t Gateway; // gateway char b6 :1;
esp_ip4_addr_t DNSAddr1; // char bIsWiFiEnabled :1;
esp_ip4_addr_t DNSAddr2; // } Flags1; // Flag structure
esp_ip4_addr_t DNSAddr3; //
uint8_t MACAddr[6]; // MAC address } wifiSettings;
struct #endif
{ #if CONFIG_WEBGUIAPP_GPRS_ENABLE
char bIsDHCPEnabled :1; struct
char b1 :1; {
char b2 :1; esp_ip4_addr_t IPAddr; // IP address
char b3 :1; esp_ip4_addr_t Mask; // network mask
char b4 :1; esp_ip4_addr_t Gateway; // gateway
char b5 :1; esp_ip4_addr_t DNSAddr1; //
char b6 :1; esp_ip4_addr_t DNSAddr2; //
char bIsETHEnabled :1; esp_ip4_addr_t DNSAddr3; //
} Flags1; // Flag structure uint8_t MACAddr[6]; // MAC address
struct
} ethSettings; {
#endif char b0 :1;
char b1 :1;
#if CONFIG_WEBGUIAPP_WIFI_ENABLE char b2 :1;
struct char b3 :1;
{ char b4 :1;
esp_ip4_addr_t InfIPAddr; // IP address in infrastructure(INF) mode char b5 :1;
esp_ip4_addr_t InfMask; // network mask in INF mode char b6 :1;
esp_ip4_addr_t InfGateway; // gateway IP in INF mode char bIsGSMEnabled :1;
esp_ip4_addr_t ApIPAddr; // IP address in Access point(AP) mode } Flags1; // Flag structure
esp_ip4_addr_t DNSAddr1; // DNS in station mode
esp_ip4_addr_t DNSAddr2; // DNS in station mode } gsmSettings;
esp_ip4_addr_t DNSAddr3; // DNS in station mode #endif
char InfSSID[32]; // Wireless SSID in INF mode struct
char InfSecurityKey[32]; // Network key in INF mode {
char ApSSID[32]; // Wireless SSID in AP mode char DevEui[8];
char ApSecurityKey[32]; // Wireless key in AP mode char AppEui[8];
char AppKey[16];
char MACAddrInf[6]; // MAC address
char MACAddrAp[6]; // MAC address struct
{
struct char b0 :1;
{ char b1 :1;
char bIsDHCPEnabled :1; char b2 :1;
char bIsAP :1; char b3 :1;
char b2 :1; char b4 :1;
char b3 :1; char b5 :1;
char b4 :1; char b6 :1;
char b5 :1; char bIsLoRaWANEnabled :1;
char b6 :1; } Flags1; // Flag structure
char bIsWiFiEnabled :1;
} Flags1; // Flag structure } lorawanSettings;
} wifiSettings;
} SYS_CONFIG;
#endif
#if CONFIG_WEBGUIAPP_GPRS_ENABLE esp_err_t ReadNVSSysConfig(SYS_CONFIG *SysConf);
struct esp_err_t WriteNVSSysConfig(SYS_CONFIG *SysConf);
{ esp_err_t InitSysConfig(void);
esp_ip4_addr_t IPAddr; // IP address esp_err_t ResetInitSysConfig(void);
esp_ip4_addr_t Mask; // network mask SYS_CONFIG* GetSysConf(void);
esp_ip4_addr_t Gateway; // gateway
esp_ip4_addr_t DNSAddr1; // esp_err_t WebGuiAppInit(void);
esp_ip4_addr_t DNSAddr2; // void DelayedRestart(void);
esp_ip4_addr_t DNSAddr3; //
uint8_t MACAddr[6]; // MAC address
struct #endif /* COMPONENTS_WEB_GUI_APPLICATION_INCLUDE_SYSTEMCONFIGURATION_H_ */
{
char b0 :1;
char b1 :1;
char b2 :1;
char b3 :1;
char b4 :1;
char b5 :1;
char b6 :1;
char bIsGSMEnabled :1;
} Flags1; // Flag structure
} gsmSettings;
#endif
struct
{
char DevEui[8];
char AppEui[8];
char AppKey[16];
struct
{
char b0 :1;
char b1 :1;
char b2 :1;
char b3 :1;
char b4 :1;
char b5 :1;
char b6 :1;
char bIsLoRaWANEnabled :1;
} Flags1; // Flag structure
} lorawanSettings;
} SYS_CONFIG;
esp_err_t ReadNVSSysConfig(SYS_CONFIG *SysConf);
esp_err_t WriteNVSSysConfig(SYS_CONFIG *SysConf);
esp_err_t InitSysConfig(void);
esp_err_t ResetInitSysConfig(void);
SYS_CONFIG* GetSysConf(void);
esp_err_t WebGuiAppInit(void);
void DelayedRestart(void);
#endif /* COMPONENTS_WEB_GUI_APPLICATION_INCLUDE_SYSTEMCONFIGURATION_H_ */

View File

@ -156,48 +156,37 @@ esp_err_t WebGuiAppInit(void)
} }
#endif #endif
bool WiFiApOnly = false;
#if !CONFIG_WEBGUIAPP_GPRS_ENABLE && !CONFIG_WEBGUIAPP_ETHERNET_ENABLE && CONFIG_WEBGUIAPP_WIFI_ENABLE
if (GetSysConf()->wifiSettings.Flags1.bIsAP)
WiFiApOnly = true;
#endif
/*Start services depends on client connection*/ /*Start services depends on client connection*/
#if CONFIG_WEBGUIAPP_GPRS_ENABLE || CONFIG_WEBGUIAPP_ETHERNET_ENABLE || CONFIG_WEBGUIAPP_WIFI_ENABLE #if CONFIG_WEBGUIAPP_GPRS_ENABLE || CONFIG_WEBGUIAPP_ETHERNET_ENABLE || CONFIG_WEBGUIAPP_WIFI_ENABLE
{ //start all services no depends on network ready
ESP_ERROR_CHECK(start_file_server()); ESP_ERROR_CHECK(start_file_server());
if (!WiFiApOnly) //Wait for network ready
{ while (!(
//start all services
/*Wait for interfaces connected*/ #ifdef CONFIG_WEBGUIAPP_GPRS_ENABLE
while (!(
#ifdef CONFIG_WEBGUIAPP_GPRS_ENABLE
isPPPConnected() || isPPPConnected() ||
#endif #endif
#ifdef CONFIG_WEBGUIAPP_WIFI_ENABLE #ifdef CONFIG_WEBGUIAPP_WIFI_ENABLE
isWIFIConnected() || isWIFIConnected() ||
#endif #endif
#ifdef CONFIG_WEBGUIAPP_ETHERNET_ENABLE #ifdef CONFIG_WEBGUIAPP_ETHERNET_ENABLE
isETHConnected() || isETHConnected() ||
#endif #endif
++NetworkStartTimeout >= NETWORK_START_TIMEOUT)) ++NetworkStartTimeout >= NETWORK_START_TIMEOUT))
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
//Start all services needed internet connection //Network ready or network not available now, but maybe restore later
StartTimeGet(); StartTimeGet();
#if CONFIG_WEBGUIAPP_MQTT_ENABLE #if CONFIG_WEBGUIAPP_MQTT_ENABLE
if (GetSysConf()->mqttStation[0].Flags1.bIsGlobalEnabled if (GetSysConf()->mqttStation[0].Flags1.bIsGlobalEnabled
|| GetSysConf()->mqttStation[1].Flags1.bIsGlobalEnabled) || GetSysConf()->mqttStation[1].Flags1.bIsGlobalEnabled)
{ {
MQTTRun(); MQTTRun();
}
#endif
}
#endif
} }
#endif
#endif
return ESP_OK; return ESP_OK;
} }
@ -280,9 +269,9 @@ static void ResetSysConfig(SYS_CONFIG *Conf)
sizeof(CONFIG_WEBGUIAPP_USERNAME)); sizeof(CONFIG_WEBGUIAPP_USERNAME));
memcpy(Conf->SysPass, CONFIG_WEBGUIAPP_USERPASS, memcpy(Conf->SysPass, CONFIG_WEBGUIAPP_USERPASS,
sizeof(CONFIG_WEBGUIAPP_USERPASS)); sizeof(CONFIG_WEBGUIAPP_USERPASS));
//memcpy(Conf->OTAURL, CONFIG_WEBGUIAPP_, sizeof(SYSTEM_DEFAULT_OTAURL));
memcpy(Conf->OTAURL, SYSTEM_DEFAULT_OTAURL, sizeof(SYSTEM_DEFAULT_OTAURL)); memcpy(Conf->OTAURL, CONFIG_WEBGUIAPP_OTA_HOST, sizeof(CONFIG_WEBGUIAPP_OTA_HOST));
#if CONFIG_WEBGUIAPP_WIFI_ENABLE #if CONFIG_WEBGUIAPP_WIFI_ENABLE
Conf->wifiSettings.Flags1.bIsWiFiEnabled = CONFIG_WEBGUIAPP_WIFI_ON; Conf->wifiSettings.Flags1.bIsWiFiEnabled = CONFIG_WEBGUIAPP_WIFI_ON;
memcpy(Conf->wifiSettings.ApSSID, CONFIG_WEBGUIAPP_WIFI_SSID_AP, memcpy(Conf->wifiSettings.ApSSID, CONFIG_WEBGUIAPP_WIFI_SSID_AP,
@ -363,12 +352,10 @@ esp_netif_str_to_ip4(CONFIG_WEBGUIAPP_DNS3_ADDRESS_DEFAULT, (esp_ip4_addr_t*) &C
memcpy(Conf->mqttStation[1].UserPass, CONFIG_WEBGUIAPP_MQTT_PASSWORD, sizeof(CONFIG_WEBGUIAPP_MQTT_PASSWORD)); memcpy(Conf->mqttStation[1].UserPass, CONFIG_WEBGUIAPP_MQTT_PASSWORD, sizeof(CONFIG_WEBGUIAPP_MQTT_PASSWORD));
#endif #endif
#endif #endif
memcpy(Conf->sntpClient.SntpServerAdr, DEFAULT_SNTP_SERVERNAME, memcpy(Conf->sntpClient.SntpServerAdr, CONFIG_WEBGUIAPP_SNTP_HOST,
sizeof(DEFAULT_SNTP_SERVERNAME)); sizeof(CONFIG_WEBGUIAPP_SNTP_HOST));
Conf->sntpClient.Flags1.bIsEthEnabled = DEFAULT_SNTP_ETH_IS_ENABLED; Conf->sntpClient.Flags1.bIsGlobalEnabled = CONFIG_WEBGUIAPP_SNTP_AUTOUPDATE_ENABLE;
Conf->sntpClient.Flags1.bIsWifiEnabled = DEFAULT_SNTP_WIFI_IS_ENABLED; Conf->sntpClient.TimeZone = CONFIG_WEBGUIAPP_SNTP_TIMEZONE;
Conf->sntpClient.Flags1.bIsGlobalEnabled = DEFAULT_SNTP_GLOBAL_ENABLED;
Conf->sntpClient.TimeZone = DEFAULT_SNTP_TIMEZONE;
#ifdef CONFIG_WEBGUIAPP_LORAWAN_ENABLE #ifdef CONFIG_WEBGUIAPP_LORAWAN_ENABLE
Conf->lorawanSettings.Flags1.bIsLoRaWANEnabled = true; Conf->lorawanSettings.Flags1.bIsLoRaWANEnabled = true;
@ -397,7 +384,7 @@ esp_err_t ReadNVSSysConfig(SYS_CONFIG *SysConf)
ESP_LOGI(TAG, "Size of structure to read is %d", L); ESP_LOGI(TAG, "Size of structure to read is %d", L);
err = nvs_get_blob(my_handle, "sys_conf", SysConf, &L); err = nvs_get_blob(my_handle, "sys_conf", SysConf, &L);
if (err != ESP_OK) if (err != ESP_OK)
return err; goto nvs_operation_err;
unsigned char sha256_saved[32]; unsigned char sha256_saved[32];
unsigned char sha256_calculated[32]; unsigned char sha256_calculated[32];
@ -406,17 +393,26 @@ esp_err_t ReadNVSSysConfig(SYS_CONFIG *SysConf)
L = 32; L = 32;
err = nvs_get_blob(my_handle, "sys_conf_sha256", sha256_saved, &L); err = nvs_get_blob(my_handle, "sys_conf_sha256", sha256_saved, &L);
if (err != ESP_OK) if (err != ESP_OK)
return err; goto nvs_operation_err;
SHA256Hash((unsigned char*) SysConf, sizeof(SYS_CONFIG), sha256_calculated);
SHA256Hash((unsigned char*) SysConf, sizeof(SYS_CONFIG), sha256_calculated);
BytesToStr(sha256_saved, sha_print, 32); BytesToStr(sha256_saved, sha_print, 32);
ESP_LOGI(TAG, "Saved hash of structure is %s", sha_print); ESP_LOGI(TAG, "Saved hash of structure is %s", sha_print);
BytesToStr(sha256_calculated, sha_print, 32); BytesToStr(sha256_calculated, sha_print, 32);
ESP_LOGI(TAG, "Calculated hash of structure is %s", sha_print); ESP_LOGI(TAG, "Calculated hash of structure is %s", sha_print);
if (memcmp(sha256_calculated, sha256_saved, L))
{
err = ESP_ERR_INVALID_CRC;
goto nvs_operation_err;
}
nvs_close(my_handle); nvs_close(my_handle);
return ESP_OK; return ESP_OK;
nvs_operation_err:
nvs_close(my_handle);
return err;
} }
esp_err_t WriteNVSSysConfig(SYS_CONFIG *SysConf) esp_err_t WriteNVSSysConfig(SYS_CONFIG *SysConf)
@ -432,7 +428,7 @@ esp_err_t WriteNVSSysConfig(SYS_CONFIG *SysConf)
ESP_LOGI(TAG, "Size of structure to write is %d", L); ESP_LOGI(TAG, "Size of structure to write is %d", L);
err = nvs_set_blob(my_handle, "sys_conf", SysConf, L); err = nvs_set_blob(my_handle, "sys_conf", SysConf, L);
if (err != ESP_OK) if (err != ESP_OK)
return err; goto nvs_wr_oper_err;
unsigned char sha256[32]; unsigned char sha256[32];
unsigned char sha_print[32 * 2 + 1]; unsigned char sha_print[32 * 2 + 1];
@ -444,16 +440,20 @@ esp_err_t WriteNVSSysConfig(SYS_CONFIG *SysConf)
L = 32; L = 32;
err = nvs_set_blob(my_handle, "sys_conf_sha256", sha256, L); err = nvs_set_blob(my_handle, "sys_conf_sha256", sha256, L);
if (err != ESP_OK) if (err != ESP_OK)
return err; goto nvs_wr_oper_err;
// Commit // Commit
err = nvs_commit(my_handle); err = nvs_commit(my_handle);
if (err != ESP_OK) if (err != ESP_OK)
return err; goto nvs_wr_oper_err;
// Close
nvs_close(my_handle);
nvs_close(my_handle);
return ESP_OK; return ESP_OK;
nvs_wr_oper_err:
nvs_close(my_handle);
return err;
} }
SYS_CONFIG* GetSysConf(void) SYS_CONFIG* GetSysConf(void)
@ -465,20 +465,19 @@ esp_err_t InitSysConfig(void)
{ {
esp_err_t err; esp_err_t err;
err = ReadNVSSysConfig(&SysConfig); err = ReadNVSSysConfig(&SysConfig);
if (err != ESP_ERR_NVS_NOT_FOUND) if (err == ESP_ERR_INVALID_CRC || err == ESP_ERR_NVS_NOT_FOUND)
{ {
if (err == ESP_OK) ESP_LOGW(TAG, "Reset and write default system configuration");
{
ESP_LOGI(TAG, "Read system configuration OK");
}
return err;
}
else
{
ESP_LOGI(TAG, "Reset and write default system configuration");
ResetSysConfig(&SysConfig); ResetSysConfig(&SysConfig);
err = WriteNVSSysConfig(&SysConfig); err = WriteNVSSysConfig(&SysConfig);
return err;
} }
else if (err == ESP_OK)
{
ESP_LOGI(TAG, "Read system configuration OK");
}
else
ESP_LOGW(TAG, "Error reading NVS configuration:%s", esp_err_to_name(err));
return err; return err;
} }
@ -497,7 +496,7 @@ void DelayedRestartTask(void *pvParameter)
void DelayedRestart(void) void DelayedRestart(void)
{ {
xTaskCreate(DelayedRestartTask, "RestartTask", 1024 * 4, (void*) 0, 3, xTaskCreate(DelayedRestartTask, "RestartTask", 1024 * 4, (void*) 0, 3,
NULL); NULL);
} }
bool GetUserAppNeedReset(void) bool GetUserAppNeedReset(void)

View File

@ -167,7 +167,7 @@ static void wifi_init_softap(void *pvParameter)
.authmode = WIFI_AUTH_WPA_WPA2_PSK .authmode = WIFI_AUTH_WPA_WPA2_PSK
}, },
}; };
if (strlen(DEFAULT_WIFI_SSID_AP_KEY) == 0) if (strlen(CONFIG_WEBGUIAPP_WIFI_KEY_AP) == 0)
{ {
wifi_config.ap.authmode = WIFI_AUTH_OPEN; wifi_config.ap.authmode = WIFI_AUTH_OPEN;
} }
@ -367,7 +367,7 @@ static void wifi_init_apsta(void *pvParameter)
.authmode = WIFI_AUTH_WPA_WPA2_PSK .authmode = WIFI_AUTH_WPA_WPA2_PSK
}, },
}; };
if (strlen(DEFAULT_WIFI_SSID_AP_KEY) == 0) if (strlen(CONFIG_WEBGUIAPP_WIFI_KEY_AP) == 0)
{ {
ap_wifi_config.ap.authmode = WIFI_AUTH_OPEN; ap_wifi_config.ap.authmode = WIFI_AUTH_OPEN;
} }