autoexec config settings working (#10)

* autoexec config settings working

* small fixes

* working autoexec* saving
This commit is contained in:
Christian Herzog
2019-09-01 22:45:28 +02:00
committed by sle118
parent daeb4dcd11
commit 5e34f65e5e
6 changed files with 200 additions and 130 deletions

View File

@@ -38,9 +38,9 @@ function to process requests, decode URLs, serve files, etc. etc.
/* @brief tag used for ESP serial console messages */
static const char TAG[] = "http_server";
static const char json_start[] = "{ \"autoexec\" : %u, \"list\" : [";
static const char json_start[] = "{ \"autoexec\": %u, \"list\": [";
static const char json_end[] = "]}";
static const char template[] = "{ '%s' : '%s' }";
static const char template[] = "{ \"%s\": \"%s\" }";
static const char array_separator[]=",";
/* @brief task handle for the http server */
@@ -222,7 +222,6 @@ void http_server_netconn_serve(struct netconn *conn) {
ESP_LOGI(TAG,"Serving config.json");
char autoexec_name[21]={0};
char * autoexec_value=NULL;
char * autoexec_flag_s=NULL;
uint8_t autoexec_flag=0;
int buflen=MAX_COMMAND_LINE_SIZE+strlen(template)+1;
char * buff = malloc(buflen);
@@ -251,7 +250,7 @@ void http_server_netconn_serve(struct netconn *conn) {
ESP_LOGD(TAG,"%s", array_separator);
}
ESP_LOGI(TAG,"found command %s = %s", autoexec_name, autoexec_value);
snprintf(buff,buflen-1,template, autoexec_name,autoexec_value);
snprintf(buff, buflen-1, template, autoexec_name, autoexec_value);
netconn_write(conn, buff, strlen(buff), NETCONN_NOCOPY);
ESP_LOGD(TAG,"%s", buff);
ESP_LOGD(TAG,"Freeing memory for command %s name", autoexec_name);
@@ -277,7 +276,8 @@ void http_server_netconn_serve(struct netconn *conn) {
if(wifi_manager_lock_json_buffer(( TickType_t ) 10)){
int i=1;
int lenS = 0, lenA=0;
char autoexec_name[21]={0};
char autoexec_name[22]={0};
char autoexec_key[12]={0};
char * autoexec_value=NULL;
char * autoexec_flag_s=NULL;
uint8_t autoexec_flag=0;
@@ -289,14 +289,16 @@ void http_server_netconn_serve(struct netconn *conn) {
}
do {
snprintf(autoexec_name,sizeof(autoexec_name)-1,"X-Custom-autoexec%u:",i++);
ESP_LOGD(TAG,"Looking for command name %s", autoexec_name);
snprintf(autoexec_name,sizeof(autoexec_name)-1,"X-Custom-autoexec%u: ",i);
snprintf(autoexec_key,sizeof(autoexec_key)-1,"autoexec%u",i++);
ESP_LOGD(TAG,"Looking for command name %s.", autoexec_name);
autoexec_value = http_server_get_header(save_ptr, autoexec_name, &lenS);
snprintf(autoexec_value, lenS+1, autoexec_value);
if(autoexec_value ){
if(lenS < MAX_COMMAND_LINE_SIZE ){
ESP_LOGD(TAG, "http_server_netconn_serve: config.json/ call, with %s: %s", autoexec_name, autoexec_value);
wifi_manager_save_autoexec_config(autoexec_value,autoexec_name,lenS);
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);
}
else
{