diff --git a/.cproject b/.cproject
index 432793b8..7792b1c8 100644
--- a/.cproject
+++ b/.cproject
@@ -3,9 +3,15 @@
-
+
-
+
+
+
+
+
+
+
@@ -29,31 +35,57 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
+
+
+
+
@@ -66,6 +98,390 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ make
+
+ -j8 EXTRA_CPPFLAGS="-DRECOVERY_APPLICATION=1"
+
+ all
+
+ true
+
+ true
+
+ true
+
+
+
+
+
+ make
+
+ -j8 EXTRA_CPPFLAGS="-DRECOVERY_APPLICATION=1"
+
+ app
+
+ true
+
+ true
+
+ true
+
+
+
+
+
+ make
+
+ -j8 EXTRA_CPPFLAGS="-DRECOVERY_APPLICATION=1"
+
+ clean
+
+ true
+
+ true
+
+ true
+
+
+
+
@@ -122,13 +538,5 @@
-
-
-
-
-
-
-
-
diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml
index a2c3d31c..70f9cf9d 100644
--- a/.settings/language.settings.xml
+++ b/.settings/language.settings.xml
@@ -1,7 +1,7 @@
-
+
@@ -11,7 +11,79 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/components/squeezelite-ota/squeezelite-ota.c b/components/squeezelite-ota/squeezelite-ota.c
index e0d2bc78..e3e6c641 100644
--- a/components/squeezelite-ota/squeezelite-ota.c
+++ b/components/squeezelite-ota/squeezelite-ota.c
@@ -314,32 +314,17 @@ void ota_task(void *pvParameter)
}
esp_err_t process_recovery_ota(const char * bin_url){
-
- // Initialize NVS.
- int ret=0;
- esp_err_t err = nvs_flash_init();
+ int ret = 0;
if(ota_status.bOTAThreadStarted){
ESP_LOGE(TAG,"OTA Already started. ");
return ESP_FAIL;
}
memset(&ota_status, 0x00, sizeof(ota_status));
ota_status.bOTAThreadStarted=true;
- if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
- // todo: If we ever change the size of the nvs partition, we need to figure out a mechanism to enlarge the nvs.
- // 1.OTA app partition table has a smaller NVS partition size than the non-OTA
- // partition table. This size mismatch may cause NVS initialization to fail.
- // 2.NVS partition contains data in new format and cannot be recognized by this version of code.
- // If this happens, we erase NVS partition and initialize NVS again.
- ESP_LOGW(TAG,"NVS flash size has changed. Formatting nvs");
- ESP_ERROR_CHECK(nvs_flash_erase());
- err = nvs_flash_init();
- }
- ESP_ERROR_CHECK(err);
char * urlPtr=strdup(bin_url);
// the first thing we need to do here is to erase the firmware url
// to avoid a boot loop
-
#ifdef CONFIG_ESP32_WIFI_TASK_PINNED_TO_CORE_1
#define OTA_CORE 0
#warning "OTA will run on core 0"
@@ -348,13 +333,11 @@ esp_err_t process_recovery_ota(const char * bin_url){
#define OTA_CORE 1
#endif
ESP_LOGI(TAG, "Starting ota on core %u for : %s", OTA_CORE,urlPtr);
-
ret=xTaskCreatePinnedToCore(&ota_task, "ota_task", 1024*20, (void *)urlPtr, ESP_TASK_MAIN_PRIO+1, NULL, OTA_CORE);
if (ret != pdPASS) {
ESP_LOGI(TAG, "create thread %s failed", "ota_task");
return ESP_FAIL;
}
-
return ESP_OK;
}
diff --git a/components/wifi-manager/code.js b/components/wifi-manager/code.js
index 17410ace..9aa6e85e 100644
--- a/components/wifi-manager/code.js
+++ b/components/wifi-manager/code.js
@@ -162,10 +162,12 @@ $(document).ready(function(){
$.ajax({
url: '/connect.json',
- dataType: 'json',
+ dataType: 'text',
method: 'DELETE',
cache: false,
- data: { 'timestamp': Date.now()}
+ contentType: 'application/json; charset=utf-8',
+ data: JSON.stringify({ 'timestamp': Date.now()})
+
});
startCheckStatusInterval();
@@ -181,11 +183,12 @@ $(document).ready(function(){
showMessage('please wait for the ESP32 to reboot', 'WARNING');
$.ajax({
url: '/config.json',
- dataType: 'json',
+ dataType: 'text',
method: 'POST',
cache: false,
headers: { "X-Custom-autoexec": autoexec },
- data: data,
+ contentType: 'application/json; charset=utf-8',
+ data: JSON.stringify(data),
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(thrownError);
@@ -196,10 +199,11 @@ $(document).ready(function(){
console.log('now triggering reboot');
$.ajax({
url: '/reboot.json',
- dataType: 'json',
+ dataType: 'text',
method: 'POST',
cache: false,
- data: { 'timestamp': Date.now()},
+ contentType: 'application/json; charset=utf-8',
+ data: JSON.stringify({ 'timestamp': Date.now()}),
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(thrownError);
@@ -215,11 +219,12 @@ $(document).ready(function(){
$.ajax({
url: '/config.json',
- dataType: 'json',
+ dataType: 'text',
method: 'POST',
cache: false,
headers: { "X-Custom-autoexec1": autoexec1 },
- data: data,
+ contentType: 'application/json; charset=utf-8',
+ data: JSON.stringify(data),
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(thrownError);
@@ -227,6 +232,7 @@ $(document).ready(function(){
}
});
console.log('sent config JSON with headers:', autoexec1);
+ console.log('sent data:', JSON.stringify(data));
});
$("input#save-gpio").on("click", function() {
@@ -242,11 +248,12 @@ $(document).ready(function(){
});
$.ajax({
url: '/config.json',
- dataType: 'json',
+ dataType: 'text',
method: 'POST',
cache: false,
headers: headers,
- data: data,
+ contentType: 'application/json; charset=utf-8',
+ data: JSON.stringify(data),
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(thrownError);
@@ -254,6 +261,7 @@ $(document).ready(function(){
}
});
console.log('sent config JSON with headers:', JSON.stringify(headers));
+ console.log('sent config JSON with data:', JSON.stringify(data));
});
$("#save-nvs").on("click", function() {
@@ -275,11 +283,12 @@ $(document).ready(function(){
}
$.ajax({
url: '/config.json',
- dataType: 'json',
+ dataType: 'text',
method: 'POST',
cache: false,
headers: headers,
- data: data,
+ contentType: 'application/json; charset=utf-8',
+ data: JSON.stringify(data),
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(thrownError);
@@ -287,6 +296,7 @@ $(document).ready(function(){
}
});
console.log('sent config JSON with headers:', JSON.stringify(headers));
+ console.log('sent config JSON with data:', JSON.stringify(data));
});
$("#flash").on("click", function() {
@@ -297,11 +307,12 @@ $(document).ready(function(){
data['fwurl'] = url;
$.ajax({
url: '/config.json',
- dataType: 'json',
+ dataType: 'text',
method: 'POST',
cache: false,
headers: { "X-Custom-fwurl": url },
- data: data,
+ contentType: 'application/json; charset=utf-8',
+ data: JSON.stringify(data),
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(thrownError);
@@ -463,10 +474,11 @@ function performConnect(conntype){
$.ajax({
url: '/connect.json',
- dataType: 'json',
+ dataType: 'text',
method: 'POST',
cache: false,
headers: { 'X-Custom-ssid': selectedSSID, 'X-Custom-pwd': pwd, 'X-Custom-host_name': dhcpname },
+ contentType: 'application/json; charset=utf-8',
data: { 'timestamp': Date.now()},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
diff --git a/components/wifi-manager/http_server.c b/components/wifi-manager/http_server.c
index 071b8f69..0259e44c 100644
--- a/components/wifi-manager/http_server.c
+++ b/components/wifi-manager/http_server.c
@@ -75,13 +75,13 @@ extern const uint8_t index_html_end[] asm("_binary_index_html_end");
/* const http headers stored in ROM */
const static char http_hdr_template[] = "HTTP/1.1 200 OK\nContent-type: %s\nAccept-Ranges: bytes\nContent-Length: %d\nContent-Encoding: %s\nAccess-Control-Allow-Origin: *\n\n";
-const static char http_html_hdr[] = "HTTP/1.1 200 OK\nContent-type: text/html\nAccess-Control-Allow-Origin: *\n\n";
+const static char http_html_hdr[] = "HTTP/1.1 200 OK\nContent-type: text/html\nAccess-Control-Allow-Origin: *\nAccept-Encoding: identity\n\n";
const static char http_css_hdr[] = "HTTP/1.1 200 OK\nContent-type: text/css\nCache-Control: public, max-age=31536000\nAccess-Control-Allow-Origin: *\n\n";
const static char http_js_hdr[] = "HTTP/1.1 200 OK\nContent-type: text/javascript\nAccess-Control-Allow-Origin: *\n\n";
const static char http_400_hdr[] = "HTTP/1.1 400 Bad Request\nContent-Length: 0\n\n";
const static char http_404_hdr[] = "HTTP/1.1 404 Not Found\nContent-Length: 0\n\n";
const static char http_503_hdr[] = "HTTP/1.1 503 Service Unavailable\nContent-Length: 0\n\n";
-const static char http_ok_json_no_cache_hdr[] = "HTTP/1.1 200 OK\nContent-type: application/json\nCache-Control: no-store, no-cache, must-revalidate, max-age=0\nPragma: no-cache\nAccess-Control-Allow-Origin: *\n\n";
+const static char http_ok_json_no_cache_hdr[] = "HTTP/1.1 200 OK\nContent-type: application/json\nCache-Control: no-store, no-cache, must-revalidate, max-age=0\nPragma: no-cache\nAccess-Control-Allow-Origin: *\nAccept-Encoding: identity\n\n";
const static char http_redirect_hdr_start[] = "HTTP/1.1 302 Found\nLocation: http://";
const static char http_redirect_hdr_end[] = "/\n\n";
@@ -119,7 +119,7 @@ void http_server(void *pvParameters) {
netconn_close(conn);
netconn_delete(conn);
vSemaphoreDelete(http_server_config_mutex);
- wifi_manager_json_mutex = NULL;
+ http_server_config_mutex = NULL;
vTaskDelete( NULL );
}
@@ -213,12 +213,12 @@ void http_server_send_resource_file(struct netconn *conn,const uint8_t * start,
}
}
-err_t http_server_nvs_dump(struct netconn *conn, nvs_type_t nvs_type, bool * bFirst){
+err_t http_server_nvs_dump(struct netconn *conn, nvs_type_t nvs_type){
nvs_entry_info_t info;
char * num_buffer = NULL;
cJSON * nvs_json = cJSON_CreateObject();
num_buffer = malloc(NUM_BUFFER_LEN);
- nvs_iterator_t it = nvs_entry_find(NVS_PARTITION_NAME, NULL, nvs_type);
+ nvs_iterator_t it = nvs_entry_find(settings_partition, NULL, nvs_type);
if (it == NULL) {
ESP_LOGW(TAG, "No nvs entry found in %s",NVS_PARTITION_NAME );
}
@@ -277,7 +277,7 @@ err_t http_server_nvs_dump(struct netconn *conn, nvs_type_t nvs_type, bool * bFi
return ESP_OK;
}
-void http_server_process_config(struct netconn *conn, struct netbuf *inbuf){
+void http_server_process_config(struct netconn *conn, char *inbuf){
// Here, we are passed a buffer which contains the http request
@@ -289,7 +289,7 @@ void http_server_process_config(struct netconn *conn, struct netbuf *inbuf){
// char *save_ptr = buf;
// char *line = strtok_r(save_ptr, new_line, &save_ptr);
// ESP_LOGD(TAG,"Processing line %s",line);
-
+ ESP_LOGD(TAG,"Processing request buffer: \n%s",inbuf);
char *last = NULL;
char *ptr = NULL;
last = ptr = inbuf;
@@ -301,12 +301,19 @@ void http_server_process_config(struct netconn *conn, struct netbuf *inbuf){
ptr++;
}
// terminate the header string
+ if( *(ptr) == '\0' ) {
+ ESP_LOGD(TAG, "End of buffer found");
+ return;
+ }
*ptr = '\0';
- if( *ptr+1 == '\n' ) {
- *ptr+1='\0';
+ if( *(ptr+1) == '\n' ) {
+ *(ptr+1)='\0';
ptr+=2;
}
- if(ptr==last) break;
+ if(ptr==last) {
+ ESP_LOGD(TAG,"Processing body. ");
+ break;
+ }
if(strlen(last)>0){
ESP_LOGD(TAG,"Found Header Line %s ", last);
//Content-Type: application/json
@@ -318,9 +325,12 @@ void http_server_process_config(struct netconn *conn, struct netbuf *inbuf){
last=ptr;
}
else {
- ESP_LOGD(TAG,"Body content: %s", last);
- cJSON * json = cJSON_Parse(last);
- cJSON_Delete(json);
+ //ESP_LOGD(TAG,"Body content: %s", last);
+ //cJSON * json = cJSON_Parse(last);
+ //cJSON_Delete(json);
+ //todo: implement body json parsing
+ // right now, body is coming as compressed, so we need some type of decompression to happen.
+ return;
}
}
return ;
@@ -345,7 +355,7 @@ void http_server_netconn_serve(struct netconn *conn) {
/* extract the first line of the request */
char *save_ptr = buf;
char *line = strtok_r(save_ptr, new_line, &save_ptr);
- ESP_LOGD(TAG,"Processing line %s",line);
+ ESP_LOGD(TAG,"http_server_netconn_serve Processing line %s, socket: %u",line, conn->socket);
if(line) {
@@ -401,7 +411,7 @@ void http_server_netconn_serve(struct netconn *conn) {
//dynamic stuff
else if(strstr(line, "GET /ap.json ")) {
/* if we can get the mutex, write the last version of the AP list */
- ESP_LOGI(TAG,"Processing ap.json request");
+ ESP_LOGI(TAG,"Processing ap.json request for socket %u",conn->socket);
if(wifi_manager_lock_json_buffer(( TickType_t ) 10)){
netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY);
char *buff = wifi_manager_get_ap_list_json();
@@ -415,15 +425,16 @@ void http_server_netconn_serve(struct netconn *conn) {
/* request a wifi scan */
ESP_LOGI(TAG,"Starting wifi scan");
wifi_manager_scan_async();
+ ESP_LOGI(TAG,"Done serving ap.json for socket %u",conn->socket);
}
else if(strstr(line, "GET /config.json ")){
- ESP_LOGI(TAG,"Serving config.json");
+ ESP_LOGI(TAG,"Serving config.json for socket %u",conn->socket);
ESP_LOGI(TAG, "About to get config from flash");
http_server_nvs_dump(conn,NVS_TYPE_STR);
- ESP_LOGD(TAG,"Done serving config.json");
+ ESP_LOGD(TAG,"Done serving config.json for socket %u",conn->socket);
}
else if(strstr(line, "POST /config.json ")){
- ESP_LOGI(TAG,"Serving POST config.json");
+ ESP_LOGI(TAG,"Serving POST config.json for socket %u",conn->socket);
int lenA=0;
char * last_parm=save_ptr;
@@ -435,7 +446,8 @@ void http_server_netconn_serve(struct netconn *conn) {
// make sure we terminate the netconn string
save_ptr[buflen-1]='\0';
- http_server_process_config(conn);
+ // todo: implement json body parsing
+ //http_server_process_config(conn,save_ptr);
while(last_parm!=NULL){
// Search will return
@@ -471,10 +483,11 @@ void http_server_netconn_serve(struct netconn *conn) {
free(otaURL);
}
}
+ ESP_LOGI(TAG,"Done Serving POST config.json for socket %u",conn->socket);
}
else if(strstr(line, "POST /connect.json ")) {
- ESP_LOGI(TAG, "http_server_netconn_serve: POST /connect.json");
+ ESP_LOGI(TAG, "http_server_netconn_serve: POST /connect.json for socket %u",conn->socket);
bool found = false;
int lenS = 0, lenP = 0;
char *ssid = NULL, *password = NULL;
@@ -498,21 +511,27 @@ void http_server_netconn_serve(struct netconn *conn) {
ESP_LOGE(TAG, "bad request the authentification header is not complete/not the correct format");
}
+ ESP_LOGI(TAG, "http_server_netconn_serve: done serving connect.json for socket %u",conn->socket);
}
else if(strstr(line, "DELETE /connect.json ")) {
- ESP_LOGI(TAG, "http_server_netconn_serve: DELETE /connect.json");
+ ESP_LOGI(TAG, "http_server_netconn_serve: DELETE /connect.json for socket %u",conn->socket);
/* request a disconnection from wifi and forget about it */
wifi_manager_disconnect_async();
netconn_write(conn, http_ok_json_no_cache_hdr, sizeof(http_ok_json_no_cache_hdr) - 1, NETCONN_NOCOPY); /* 200 ok */
+ ESP_LOGI(TAG, "http_server_netconn_serve: done serving DELETE /connect.json for socket %u",conn->socket);
}
else if(strstr(line, "POST /reboot.json ")){
+ ESP_LOGI(TAG, "http_server_netconn_serve: POST reboot.json for socket %u",conn->socket);
guided_restart_ota();
+ ESP_LOGI(TAG, "http_server_netconn_serve: done serving POST reboot.json for socket %u",conn->socket);
}
else if(strstr(line, "POST /recovery.json ")){
+ ESP_LOGI(TAG, "http_server_netconn_serve: POST recovery.json for socket %u",conn->socket);
guided_factory();
+ ESP_LOGI(TAG, "http_server_netconn_serve: done serving POST recovery.json for socket %u",conn->socket);
}
else if(strstr(line, "GET /status.json ")){
- ESP_LOGI(TAG,"Serving status.json");
+ ESP_LOGI(TAG,"Serving status.json for socket %u",conn->socket);
if(wifi_manager_lock_json_buffer(( TickType_t ) 10)){
char *buff = wifi_manager_get_ip_info_json();
if(buff){
@@ -528,15 +547,16 @@ void http_server_netconn_serve(struct netconn *conn) {
netconn_write(conn, http_503_hdr, sizeof(http_503_hdr) - 1, NETCONN_NOCOPY);
ESP_LOGE(TAG, "http_server_netconn_serve: GET /status failed to obtain mutex");
}
+ ESP_LOGI(TAG,"Done Serving status.json for socket %u",conn->socket);
}
else{
netconn_write(conn, http_400_hdr, sizeof(http_400_hdr) - 1, NETCONN_NOCOPY);
- ESP_LOGE(TAG, "bad request");
+ ESP_LOGE(TAG, "bad request for socket %u",conn->socket);
}
}
}
else{
- ESP_LOGE(TAG, "URL Not found. Sending 404.");
+ ESP_LOGE(TAG, "URL Not found. Sending 404. for socket %u",conn->socket);
netconn_write(conn, http_404_hdr, sizeof(http_404_hdr) - 1, NETCONN_NOCOPY);
}
}
@@ -563,7 +583,7 @@ bool http_server_lock_json_object(TickType_t xTicksToWait){
}
-void http_server__unlock_json_object(){
+void http_server_unlock_json_object(){
ESP_LOGD(TAG,"Unlocking json buffer!");
xSemaphoreGive( http_server_config_mutex );
}
diff --git a/components/wifi-manager/http_server.h b/components/wifi-manager/http_server.h
index cb9b88e3..89542f24 100644
--- a/components/wifi-manager/http_server.h
+++ b/components/wifi-manager/http_server.h
@@ -92,7 +92,7 @@ void CODE_RAM_LOCATION strreplace(char *src, char *str, char *rep);
/* @brief lock the json config object */
bool http_server_lock_json_object(TickType_t xTicksToWait);
/* @brief unlock the json config object */
-void http_server__unlock_json_object()
+void http_server_unlock_json_object();
#define PROTECTED_JSON_CALL(a) if(http_server_lock_json_object( portMAX_DELAY )){ \ a; http_server_unlocklock_json_object(); } else{ ESP_LOGE(TAG, "could not get access to json mutex in wifi_scan"); }
diff --git a/components/wifi-manager/wifi_manager.c b/components/wifi-manager/wifi_manager.c
index f724161e..5c4f9619 100644
--- a/components/wifi-manager/wifi_manager.c
+++ b/components/wifi-manager/wifi_manager.c
@@ -164,8 +164,6 @@ void wifi_manager_start(){
/* disable the default wifi logging */
esp_log_level_set("wifi", ESP_LOG_NONE);
- /* initialize flash memory */
- nvs_flash_init();
/* memory allocation */
wifi_manager_queue = xQueueCreate( 3, sizeof( queue_message) );
diff --git a/main/console.c b/main/console.c
index 68ad2b98..f985ece2 100644
--- a/main/console.c
+++ b/main/console.c
@@ -89,14 +89,6 @@ void process_autoexec(){
}
}
-static void initialize_nvs() {
- esp_err_t err = nvs_flash_init();
- if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
- ESP_ERROR_CHECK(nvs_flash_erase());
- err = nvs_flash_init();
- }
- ESP_ERROR_CHECK(err);
-}
void initialize_console() {
@@ -151,8 +143,7 @@ void initialize_console() {
}
void console_start() {
- initialize_nvs();
- //initialize_filesystem();
+
initialize_console();
/* Register commands */
diff --git a/main/esp_app_main.c b/main/esp_app_main.c
index b6140049..915d2517 100644
--- a/main/esp_app_main.c
+++ b/main/esp_app_main.c
@@ -101,6 +101,14 @@ static void initialize_nvs() {
err = nvs_flash_init();
}
ESP_ERROR_CHECK(err);
+
+ err = nvs_flash_init_partition(settings_partition);
+ if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
+ ESP_ERROR_CHECK(nvs_flash_erase_partition(settings_partition));
+ err = nvs_flash_init_partition(settings_partition);
+ }
+ ESP_ERROR_CHECK(err);
+
}
char * process_ota_url(){
nvs_handle nvs;
diff --git a/main/nvs_utilities.c b/main/nvs_utilities.c
index 3ba48c00..15fc1548 100644
--- a/main/nvs_utilities.c
+++ b/main/nvs_utilities.c
@@ -18,40 +18,6 @@ const char current_namespace[] = "config";
const char settings_partition[] = "settings";
static const char * TAG = "platform_esp32";
-bool isNameValid(char * key){
- bool bFound=false;
- nvs_handle nvs;
- esp_err_t err;
- int8_t val=0;
-
- err = nvs_open(current_namespace, NVS_READONLY, &nvs);
- if (err != ESP_OK) {
- ESP_LOGE(TAG,"Error opening nvs storage for namespace %s",current_namespace);
- return false;
- }
- err = nvs_get_i8(nvs, key, &val);
- if(err==ESP_OK || err== ESP_ERR_NVS_INVALID_LENGTH){
- bFound=true;
- }
- else {
- ESP_LOGD(TAG,"Search for key %s in namespace %s returned %#08X",key,current_namespace,err);
- }
-// nvs_iterator_t it = nvs_entry_find(NVS_DEFAULT_PART_NAME, current_namespace, NVS_TYPE_ANY);
-// while (it != NULL) {
-// nvs_entry_info_t info;
-// nvs_entry_info(it, &info);
-// it = nvs_entry_next(it);
-// if(!strcmp(info.key,key)){
-// bFound=true;
-// }
-// printf("key '%s', type '%d' \n", info.key, info.type);
-// };
-// // Note: no need to release iterator obtained from nvs_entry_find function when
-// // nvs_entry_find or nvs_entry_next function return NULL, indicating no other
-// // element for specified criteria was found.
- nvs_close(nvs);
- return bFound;
-}
esp_err_t store_nvs_value(nvs_type_t type, const char *key, void * data) {
if (type == NVS_TYPE_BLOB)
return ESP_ERR_NVS_TYPE_MISMATCH;
@@ -66,7 +32,7 @@ esp_err_t store_nvs_value_len(nvs_type_t type, const char *key, void * data,
return ESP_ERR_NVS_TYPE_MISMATCH;
}
- err = nvs_open(current_namespace, NVS_READWRITE, &nvs);
+ err = nvs_open_from_partition(settings_partition, current_namespace, NVS_READWRITE, &nvs);
if (err != ESP_OK) {
return err;
}
@@ -133,7 +99,7 @@ void * get_nvs_value_alloc(nvs_type_t type, const char *key) {
esp_err_t err;
void * value=NULL;
- err = nvs_open(current_namespace, NVS_READONLY, &nvs);
+ err = nvs_open_from_partition(settings_partition, current_namespace, NVS_READONLY, &nvs);
if (err != ESP_OK) {
ESP_LOGE(TAG,"Could not open the nvs storage.");
return NULL;
@@ -191,7 +157,7 @@ esp_err_t get_nvs_value(nvs_type_t type, const char *key, void*value, const uint
nvs_handle nvs;
esp_err_t err;
- err = nvs_open(current_namespace, NVS_READONLY, &nvs);
+ err = nvs_open_from_partition(settings_partition, current_namespace, NVS_READONLY, &nvs);
if (err != ESP_OK) {
return err;
}
diff --git a/main/nvs_utilities.h b/main/nvs_utilities.h
index ad1a06c7..885fca48 100644
--- a/main/nvs_utilities.h
+++ b/main/nvs_utilities.h
@@ -7,7 +7,6 @@ extern "C" {
#endif
extern const char current_namespace[];
extern const char settings_partition[];
-bool isNameValid(char * key);
esp_err_t store_nvs_value_len(nvs_type_t type, const char *key, void * data, size_t data_len);
esp_err_t store_nvs_value(nvs_type_t type, const char *key, void * data);
esp_err_t get_nvs_value(nvs_type_t type, const char *key, void*value, const uint8_t buf_size);