some changing in project root structure
This commit is contained in:
parent
a839672932
commit
020798c68a
|
|
@ -14,4 +14,5 @@
|
||||||
<pathentry excluding="**/CMakeFiles/**" kind="out" path="build"/>
|
<pathentry excluding="**/CMakeFiles/**" kind="out" path="build"/>
|
||||||
</storageModule>
|
</storageModule>
|
||||||
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
|
||||||
|
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
||||||
</cproject>
|
</cproject>
|
||||||
|
|
@ -1,30 +1,30 @@
|
||||||
adapters.html
|
adapters.html
|
||||||
api
|
api
|
||||||
api/dbg.json
|
api/dbg.json
|
||||||
api/dbg2.json
|
api/dbg2.json
|
||||||
api/gendata.json
|
api/gendata.json
|
||||||
api/mem.json
|
api/mem.json
|
||||||
api/set1.json
|
api/set1.json
|
||||||
api/set2.json
|
api/set2.json
|
||||||
api/set3.json
|
api/set3.json
|
||||||
api/stat.json
|
api/stat.json
|
||||||
api/status.json
|
api/status.json
|
||||||
api/tmr.json
|
api/tmr.json
|
||||||
api/wifiscan.json
|
api/wifiscan.json
|
||||||
application.html
|
application.html
|
||||||
favicon.ico
|
favicon.ico
|
||||||
index.html
|
index.html
|
||||||
info.html
|
info.html
|
||||||
reboot.html
|
reboot.html
|
||||||
res
|
res
|
||||||
res/appstyles.css
|
res/appstyles.css
|
||||||
res/ca_cert.pem
|
res/ca_cert.pem
|
||||||
res/cron.js
|
res/cron.js
|
||||||
res/iconsfont.css
|
res/iconsfont.css
|
||||||
res/iconsfont.woff2
|
res/iconsfont.woff2
|
||||||
res/logo.png
|
res/logo.png
|
||||||
res/main.js
|
res/main.js
|
||||||
res/res.js
|
res/res.js
|
||||||
res/styles.css
|
res/styles.css
|
||||||
services.html
|
services.html
|
||||||
system.html
|
system.html
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
dependencies:
|
dependencies:
|
||||||
idf:
|
idf:
|
||||||
component_hash: null
|
component_hash: null
|
||||||
source:
|
source:
|
||||||
type: idf
|
type: idf
|
||||||
version: 4.4.4
|
version: 4.4.4
|
||||||
manifest_hash: f9b3d78d7d56685d1c543701158a0fab7a56c908117ed70644f77e4247c831ae
|
manifest_hash: 31dd4ec84ade1450fc168388f4adce2efacd1516170670735140bc772e9d72bd
|
||||||
target: esp32
|
target: esp32
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,15 @@
|
||||||
# See the build system documentation in IDF programming guide
|
# See the build system documentation in IDF programming guide
|
||||||
# for more information about component CMakeLists.txt files.
|
# for more information about component CMakeLists.txt files.
|
||||||
|
|
||||||
|
set(srcs main.c
|
||||||
|
src/HTTPPrintCustom.c
|
||||||
|
src/HTTPPostCustom.c
|
||||||
|
src/MQTTCustom.c
|
||||||
|
src/AppConfiguration.c
|
||||||
|
)
|
||||||
|
set(include "include")
|
||||||
|
|
||||||
idf_component_register(
|
idf_component_register(
|
||||||
SRCS main.c
|
SRCS "${srcs}"
|
||||||
HTTPPrintCustom.c
|
INCLUDE_DIRS ${include}
|
||||||
HTTPPostCustom.c
|
)
|
||||||
MQTTCustom.c
|
|
||||||
)
|
|
||||||
62
main/include/AppConfiguration.h
Normal file
62
main/include/AppConfiguration.h
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*! Copyright 2023 Bogdan Pilyugin
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* \file AppConfiguration.h
|
||||||
|
* \version 1.0
|
||||||
|
* \date 2023-03-08
|
||||||
|
* \author Bogdan Pilyugin
|
||||||
|
* \brief
|
||||||
|
* \details
|
||||||
|
* \copyright Apache License, Version 2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MAIN_INCLUDE_APPCONFIGURATION_H_
|
||||||
|
#define MAIN_INCLUDE_APPCONFIGURATION_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "esp_netif.h"
|
||||||
|
|
||||||
|
/// Application-dependent structure used to contain address information
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @struct APP_CONFIG
|
||||||
|
* @brief The main configuration structure
|
||||||
|
* @details This structure saving to EEPROM and loading from EEPROM\n
|
||||||
|
* on device boot. On load the checksumm is calculate and compare to \n
|
||||||
|
* saved one. If find difference (due to eeprom memory distortions),\n
|
||||||
|
* the default values will be loaded.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct appconf
|
||||||
|
{
|
||||||
|
int test;
|
||||||
|
} APP_CONFIG;
|
||||||
|
|
||||||
|
void UserInitIO(void);
|
||||||
|
void UserAppInit(void);
|
||||||
|
void InitSPI(void);
|
||||||
|
void InitI2C(void);
|
||||||
|
|
||||||
|
APP_CONFIG* GetAppConf(void);
|
||||||
|
void ResetAppConfig(APP_CONFIG *Conf);
|
||||||
|
esp_err_t WriteNVSAppConfig(APP_CONFIG *AppConf);
|
||||||
|
esp_err_t ReadNVSAppConfig(APP_CONFIG *AppConf);
|
||||||
|
esp_err_t InitAppConfig(void);
|
||||||
|
esp_err_t ResetInitAppConfig(void);
|
||||||
|
|
||||||
|
void LoadDefaultReset(void);
|
||||||
|
void DelayedRestart(void);
|
||||||
|
|
||||||
|
#endif /* MAIN_INCLUDE_APPCONFIGURATION_H_ */
|
||||||
201
main/src/AppConfiguration.c
Normal file
201
main/src/AppConfiguration.c
Normal file
|
|
@ -0,0 +1,201 @@
|
||||||
|
/*! Copyright 2023 Bogdan Pilyugin
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* \file AppConfiguration.c
|
||||||
|
* \version 1.0
|
||||||
|
* \date 2023-03-08
|
||||||
|
* \author Bogdan Pilyugin
|
||||||
|
* \brief
|
||||||
|
* \details
|
||||||
|
* \copyright Apache License, Version 2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "AppConfiguration.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "nvs_flash.h"
|
||||||
|
#include "nvs.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "Helpers.h"
|
||||||
|
#include "esp_intr_alloc.h"
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
#include "webguiapp.h"
|
||||||
|
|
||||||
|
#define STORAGE_NAMESPACE "storage"
|
||||||
|
#define TAG "AppConfiguration"
|
||||||
|
|
||||||
|
static APP_CONFIG AppConfig;
|
||||||
|
|
||||||
|
void UserAppInit(void)
|
||||||
|
{
|
||||||
|
if (GetUserAppNeedReset())
|
||||||
|
{
|
||||||
|
SetUserAppNeedReset(false);
|
||||||
|
ESP_ERROR_CHECK(InitAppConfig());
|
||||||
|
}
|
||||||
|
ESP_ERROR_CHECK(InitAppConfig());
|
||||||
|
}
|
||||||
|
|
||||||
|
void UserInitIO(void)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Application GPIO's initialized OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
void InitSPI(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void InitI2C(void)
|
||||||
|
{
|
||||||
|
#ifdef CONFIG_I2C_ENABLE
|
||||||
|
i2c_config_t i2c_config = {
|
||||||
|
.mode = I2C_MODE_MASTER,
|
||||||
|
.sda_io_num = CONFIG_I2C_SDA_GPIO,
|
||||||
|
.scl_io_num = CONFIG_I2C_SCL_GPIO,
|
||||||
|
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||||
|
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||||
|
.master.clk_speed = CONFIG_I2C_CLOCK
|
||||||
|
};
|
||||||
|
ESP_ERROR_CHECK(i2c_param_config(I2C_NUM_0, &i2c_config));
|
||||||
|
ESP_ERROR_CHECK(i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0));
|
||||||
|
ESP_LOGI(TAG, "I2C initialized OK");
|
||||||
|
#else
|
||||||
|
ESP_LOGI(TAG, "I2C bus disabeled in config");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
APP_CONFIG* GetAppConf(void)
|
||||||
|
{
|
||||||
|
return &AppConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t InitAppConfig(void)
|
||||||
|
{
|
||||||
|
esp_err_t err;
|
||||||
|
err = ReadNVSAppConfig(&AppConfig);
|
||||||
|
if (err == ESP_ERR_INVALID_CRC || err == ESP_ERR_NVS_NOT_FOUND)
|
||||||
|
{
|
||||||
|
ESP_LOGW(TAG, "Reset and write default app configuration");
|
||||||
|
ResetAppConfig(&AppConfig);
|
||||||
|
err = WriteNVSAppConfig(&AppConfig);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
else if (err == ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Read system configuration OK");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ESP_LOGW(TAG, "Error reading NVS app configuration:%s", esp_err_to_name(err));
|
||||||
|
return err;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t ResetInitAppConfig(void)
|
||||||
|
{
|
||||||
|
ESP_LOGI(TAG, "Reset and write default configuration");
|
||||||
|
ResetAppConfig(&AppConfig);
|
||||||
|
return WriteNVSAppConfig(&AppConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ResetAppConfig(APP_CONFIG *Conf)
|
||||||
|
{
|
||||||
|
//default init test param
|
||||||
|
GetAppConf()->test = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t ReadNVSAppConfig(APP_CONFIG *AppConf)
|
||||||
|
{
|
||||||
|
nvs_handle_t my_handle;
|
||||||
|
esp_err_t err;
|
||||||
|
err = nvs_open(STORAGE_NAMESPACE, NVS_READWRITE, &my_handle);
|
||||||
|
if (err != ESP_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
// obtain required memory space to store blob being read from NVS
|
||||||
|
size_t L = (size_t) sizeof(APP_CONFIG);
|
||||||
|
ESP_LOGI(TAG, "Size of APP_CONFIG structure to read is %d", L);
|
||||||
|
err = nvs_get_blob(my_handle, "app_conf", AppConf, &L);
|
||||||
|
if (err != ESP_OK)
|
||||||
|
goto nvs_operation_err;
|
||||||
|
|
||||||
|
unsigned char sha256_saved[32];
|
||||||
|
unsigned char sha256_calculated[32];
|
||||||
|
unsigned char sha_print[32 * 2 + 1];
|
||||||
|
sha_print[32 * 2] = 0x00;
|
||||||
|
L = 32;
|
||||||
|
err = nvs_get_blob(my_handle, "app_conf_sha256", sha256_saved, &L);
|
||||||
|
if (err != ESP_OK)
|
||||||
|
goto nvs_operation_err;
|
||||||
|
|
||||||
|
SHA256Hash((unsigned char*) AppConf, sizeof(APP_CONFIG), sha256_calculated);
|
||||||
|
BytesToStr(sha256_saved, sha_print, 32);
|
||||||
|
ESP_LOGI(TAG, "Saved hash of APP_CONFIG structure is %s", sha_print);
|
||||||
|
BytesToStr(sha256_calculated, sha_print, 32);
|
||||||
|
ESP_LOGI(TAG, "Calculated hash of APP_CONFIG 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);
|
||||||
|
return ESP_OK;
|
||||||
|
|
||||||
|
nvs_operation_err:
|
||||||
|
nvs_close(my_handle);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t WriteNVSAppConfig(APP_CONFIG *AppConf)
|
||||||
|
{
|
||||||
|
nvs_handle_t my_handle;
|
||||||
|
esp_err_t err;
|
||||||
|
// Open
|
||||||
|
err = nvs_open(STORAGE_NAMESPACE, NVS_READWRITE, &my_handle);
|
||||||
|
if (err != ESP_OK)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
size_t L = (size_t) sizeof(APP_CONFIG);
|
||||||
|
ESP_LOGI(TAG, "Size of APP_CONFIG structure to write is %d", L);
|
||||||
|
err = nvs_set_blob(my_handle, "app_conf", AppConf, L);
|
||||||
|
if (err != ESP_OK)
|
||||||
|
goto nvs_wr_oper_err;
|
||||||
|
|
||||||
|
unsigned char sha256[32];
|
||||||
|
unsigned char sha_print[32 * 2 + 1];
|
||||||
|
|
||||||
|
SHA256Hash((unsigned char*) AppConf, sizeof(APP_CONFIG), sha256);
|
||||||
|
BytesToStr(sha256, sha_print, 32);
|
||||||
|
sha_print[32 * 2] = 0x00;
|
||||||
|
ESP_LOGI(TAG, "SHA256 of APP_CONFIG structure to write is %s", sha_print);
|
||||||
|
L = 32;
|
||||||
|
err = nvs_set_blob(my_handle, "app_conf_sha256", sha256, L);
|
||||||
|
if (err != ESP_OK)
|
||||||
|
goto nvs_wr_oper_err;
|
||||||
|
|
||||||
|
// Commit
|
||||||
|
err = nvs_commit(my_handle);
|
||||||
|
if (err != ESP_OK)
|
||||||
|
goto nvs_wr_oper_err;
|
||||||
|
|
||||||
|
nvs_close(my_handle);
|
||||||
|
return ESP_OK;
|
||||||
|
|
||||||
|
nvs_wr_oper_err:
|
||||||
|
nvs_close(my_handle);
|
||||||
|
return err;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user