diff --git a/include/HTTPServer.h b/include/HTTPServer.h index 337df36..2efb5a4 100644 --- a/include/HTTPServer.h +++ b/include/HTTPServer.h @@ -53,7 +53,8 @@ typedef enum HTTP_IO_DONE = 0u, // Finished with procedure HTTP_IO_NEED_DATA, // More data needed to continue, call again later HTTP_IO_WAITING, // Waiting for asynchronous process to complete, call again later - HTTP_IO_REDIRECT + HTTP_IO_REDIRECT, + HTTP_IO_DONE_NOREFRESH } HTTP_IO_RESULT; typedef struct diff --git a/src/HTTPPostSystem.c b/src/HTTPPostSystem.c index 724c4e4..5e56bd0 100644 --- a/src/HTTPPostSystem.c +++ b/src/HTTPPostSystem.c @@ -68,6 +68,9 @@ HTTP_IO_RESULT HTTPPostApp(httpd_req_t *req, const char *filename, char *PostDat case HTTP_IO_REDIRECT: strcpy((char*) filename, PostData); break; + case HTTP_IO_DONE_NOREFRESH: + break; + break; } return res; } @@ -122,17 +125,6 @@ static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData) if (httpd_query_key_value(PostData, "dns3", tmp, 15) == ESP_OK) esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.DNSAddr3); - if (httpd_query_key_value(PostData, "sav", tmp, 4) == ESP_OK) - { - if (!strcmp(tmp, (const char*) "prs")) - { - GetSysConf()->ethSettings.Flags1.bIsETHEnabled = TempIsETHEnabled; - GetSysConf()->ethSettings.Flags1.bIsDHCPEnabled = TempIsETHDHCPEnabled; - WriteNVSSysConfig(GetSysConf()); - memcpy(PostData, "/reboot.html", sizeof "/reboot.html"); - return HTTP_IO_REDIRECT; - } - } #endif #if CONFIG_WEBGUIAPP_WIFI_ENABLE @@ -188,17 +180,6 @@ static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData) if (httpd_query_key_value(PostData, "dns3", tmp, 15) == ESP_OK) esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.DNSAddr3); - if (httpd_query_key_value(PostData, "sav", tmp, 4) == ESP_OK) - { - if (!strcmp(tmp, (const char*) "prs")) - { - GetSysConf()->wifiSettings.Flags1.bIsWiFiEnabled = TempIsWiFiEnabled; - GetSysConf()->wifiSettings.Flags1.bIsDHCPEnabled = TempIsWIFIDHCPEnabled; - WriteNVSSysConfig(GetSysConf()); - memcpy(PostData, "/reboot.html", sizeof "/reboot.html"); - return HTTP_IO_REDIRECT; - } - } #endif #if CONFIG_WEBGUIAPP_GPRS_ENABLE char tmp[32]; @@ -234,6 +215,45 @@ static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData) } } #endif + + if (httpd_query_key_value(PostData, "save", tmp, 5) == ESP_OK || + httpd_query_key_value(PostData, "apply", tmp, 5) == ESP_OK) + { + if (!strcmp(tmp, (const char*) "eth")) + { +#if CONFIG_WEBGUIAPP_ETHERNET_ENABLE + GetSysConf()->ethSettings.Flags1.bIsETHEnabled = TempIsETHEnabled; + GetSysConf()->ethSettings.Flags1.bIsDHCPEnabled = TempIsETHDHCPEnabled; +#endif + } + else if (!strcmp(tmp, (const char*) "wifi")) + { +#if CONFIG_WEBGUIAPP_WIFI_ENABLE + GetSysConf()->wifiSettings.Flags1.bIsWiFiEnabled = TempIsWiFiEnabled; + GetSysConf()->wifiSettings.Flags1.bIsDHCPEnabled = TempIsWIFIDHCPEnabled; +#endif + } + else if (!strcmp(tmp, (const char*) "gprs")) + { +#if CONFIG_WEBGUIAPP_GPRS_ENABLE + GetSysConf()->gsmSettings.Flags1.bIsGSMEnabled = TempIsGSMEnabled; +#endif + } + + if (httpd_query_key_value(PostData, "save", tmp, 5) == ESP_OK) + { + WriteNVSSysConfig(GetSysConf()); + return HTTP_IO_DONE; + } + else if (httpd_query_key_value(PostData, "apply", tmp, 5) == ESP_OK) + { + WriteNVSSysConfig(GetSysConf()); + memcpy(PostData, "/reboot.html", sizeof "/reboot.html"); + return HTTP_IO_REDIRECT; + } + + } + return HTTP_IO_DONE; } diff --git a/src/HTTPServer.c b/src/HTTPServer.c index e38296e..689fa02 100644 --- a/src/HTTPServer.c +++ b/src/HTTPServer.c @@ -1,4 +1,4 @@ - /*! Copyright 2022 Bogdan Pilyugin +/*! Copyright 2022 Bogdan Pilyugin * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,6 @@ #include "HTTPServer.h" #include "sdkconfig.h" - - const char GZIP_SIGN[] = { 0x1f, 0x8b, 0x08 }; static esp_err_t GETHandler(httpd_req_t *req); @@ -180,7 +178,7 @@ static esp_err_t POSTHandler(httpd_req_t *req) int received; int remaining = req->content_len; buf[req->content_len] = 0x00; - + HTTP_IO_RESULT http_res; while (remaining > 0) { #if HTTP_SERVER_DEBUG_LEVEL > 0 @@ -212,16 +210,29 @@ static esp_err_t POSTHandler(httpd_req_t *req) ((struct file_server_data*) req->user_ctx)->base_path, req->uri, sizeof(filepath)); - if (HTTPPostApp(req, filename, buf) == HTTP_IO_REDIRECT) + http_res = HTTPPostApp(req, filename, buf); + + if (http_res == HTTP_IO_DONE) + return GETHandler(req); + + else if (http_res == HTTP_IO_REDIRECT) { httpd_resp_set_status(req, "307 Temporary Redirect"); httpd_resp_set_hdr(req, "Location", filename); httpd_resp_send(req, NULL, 0); // Response body can be empty #if HTTP_SERVER_DEBUG_LEVEL > 0 - ESP_LOGI(TAG, "Redirect request from POST"); - #endif + ESP_LOGI(TAG, "Redirect request from POST"); + #endif return ESP_OK; } + + else if (http_res == HTTP_IO_DONE_NOREFRESH) + { + httpd_resp_set_status(req, HTTPD_204); + httpd_resp_send(req, NULL, 0); // Response body can be empty + return ESP_OK; + } + } /* Keep track of remaining size of @@ -229,7 +240,7 @@ static esp_err_t POSTHandler(httpd_req_t *req) remaining -= received; } - return GETHandler(req); + return ESP_OK; } static esp_err_t GETHandler(httpd_req_t *req) diff --git a/src/SystemConfiguration.c b/src/SystemConfiguration.c index c391ff7..f183294 100644 --- a/src/SystemConfiguration.c +++ b/src/SystemConfiguration.c @@ -82,6 +82,9 @@ esp_err_t WebGuiAppInit(void) } ESP_ERROR_CHECK(InitSysConfig()); + GetSysConf()->wifiSettings.Flags1.bIsWiFiEnabled = true; + GetSysConf()->wifiSettings.Flags1.bIsAP = false; + //init rom file system init_rom_fs("/espfs");