From 46ee77e723fc43b99d027d77b4936861c9af3d7c Mon Sep 17 00:00:00 2001 From: Christian Herzog Date: Thu, 5 Sep 2019 21:22:39 +0200 Subject: [PATCH] Wi fi manager (#14) * build command line from website form * fix autoexec1 length problem --- components/wifi-manager/http_server.c | 5 ----- components/wifi-manager/wifi_manager.c | 8 +++++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/components/wifi-manager/http_server.c b/components/wifi-manager/http_server.c index 34152dd9..74cd7cdd 100644 --- a/components/wifi-manager/http_server.c +++ b/components/wifi-manager/http_server.c @@ -35,9 +35,6 @@ function to process requests, decode URLs, serve files, etc. etc. #include "cmd_system.h" -// todo: resolve the restrict error below -#pragma GCC diagnostic warning "-Wrestrict" - /* @brief tag used for ESP serial console messages */ static const char TAG[] = "http_server"; static const char json_start[] = "{ \"autoexec\": %u, \"list\": ["; @@ -309,8 +306,6 @@ void http_server_netconn_serve(struct netconn *conn) { if(autoexec_value ){ - // todo: replace line below, as it causes an error during compile. - snprintf(autoexec_value, lenS+1, autoexec_value); if(lenS < MAX_COMMAND_LINE_SIZE ){ ESP_LOGD(TAG, "http_server_netconn_serve: config.json/ call, with %s: %s, length %i", autoexec_key, autoexec_value, lenS); wifi_manager_save_autoexec_config(autoexec_value,autoexec_key,lenS); diff --git a/components/wifi-manager/wifi_manager.c b/components/wifi-manager/wifi_manager.c index 7d997700..9fde0f95 100644 --- a/components/wifi-manager/wifi_manager.c +++ b/components/wifi-manager/wifi_manager.c @@ -242,7 +242,9 @@ esp_err_t wifi_manager_save_autoexec_flag(uint8_t flag){ } esp_err_t wifi_manager_save_autoexec_config(char * value, char * name, int len){ nvs_handle handle; + char val[len+1]; esp_err_t esp_err; + if (len) { *val = '\0'; strncat(val, value, len); } ESP_LOGI(TAG, "About to save config to flash"); esp_err = nvs_open(wifi_manager_nvs_namespace, NVS_READWRITE, &handle); if (esp_err != ESP_OK) { @@ -250,9 +252,9 @@ esp_err_t wifi_manager_save_autoexec_config(char * value, char * name, int len){ return esp_err; } - esp_err = nvs_set_str(handle, name, value); + esp_err = nvs_set_str(handle, name, val); if (esp_err != ESP_OK){ - ESP_LOGE(TAG,"Unable to save value %s=%s",name,value); + ESP_LOGE(TAG,"Unable to save value %s=%s",name,val); nvs_close(handle); return esp_err; } @@ -265,7 +267,7 @@ esp_err_t wifi_manager_save_autoexec_config(char * value, char * name, int len){ nvs_close(handle); - ESP_LOGD(TAG, "wifi_manager_wrote %s=%s with length %i", name, value, len); + ESP_LOGD(TAG, "wifi_manager_wrote %s=%s with length %i", name, val, len); return ESP_OK;