split operations with configuration into SAVE and APPLY, separate
buttons values
This commit is contained in:
parent
876f7dada9
commit
34be6b7dab
|
|
@ -53,7 +53,8 @@ typedef enum
|
||||||
HTTP_IO_DONE = 0u, // Finished with procedure
|
HTTP_IO_DONE = 0u, // Finished with procedure
|
||||||
HTTP_IO_NEED_DATA, // More data needed to continue, call again later
|
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_WAITING, // Waiting for asynchronous process to complete, call again later
|
||||||
HTTP_IO_REDIRECT
|
HTTP_IO_REDIRECT,
|
||||||
|
HTTP_IO_DONE_NOREFRESH
|
||||||
} HTTP_IO_RESULT;
|
} HTTP_IO_RESULT;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,9 @@ HTTP_IO_RESULT HTTPPostApp(httpd_req_t *req, const char *filename, char *PostDat
|
||||||
case HTTP_IO_REDIRECT:
|
case HTTP_IO_REDIRECT:
|
||||||
strcpy((char*) filename, PostData);
|
strcpy((char*) filename, PostData);
|
||||||
break;
|
break;
|
||||||
|
case HTTP_IO_DONE_NOREFRESH:
|
||||||
|
break;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return res;
|
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)
|
if (httpd_query_key_value(PostData, "dns3", tmp, 15) == ESP_OK)
|
||||||
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.DNSAddr3);
|
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
|
#endif
|
||||||
|
|
||||||
#if CONFIG_WEBGUIAPP_WIFI_ENABLE
|
#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)
|
if (httpd_query_key_value(PostData, "dns3", tmp, 15) == ESP_OK)
|
||||||
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.DNSAddr3);
|
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
|
#endif
|
||||||
#if CONFIG_WEBGUIAPP_GPRS_ENABLE
|
#if CONFIG_WEBGUIAPP_GPRS_ENABLE
|
||||||
char tmp[32];
|
char tmp[32];
|
||||||
|
|
@ -234,6 +215,45 @@ static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#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;
|
return HTTP_IO_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/*! Copyright 2022 Bogdan Pilyugin
|
/*! Copyright 2022 Bogdan Pilyugin
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -24,8 +24,6 @@
|
||||||
#include "HTTPServer.h"
|
#include "HTTPServer.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const char GZIP_SIGN[] = { 0x1f, 0x8b, 0x08 };
|
const char GZIP_SIGN[] = { 0x1f, 0x8b, 0x08 };
|
||||||
|
|
||||||
static esp_err_t GETHandler(httpd_req_t *req);
|
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 received;
|
||||||
int remaining = req->content_len;
|
int remaining = req->content_len;
|
||||||
buf[req->content_len] = 0x00;
|
buf[req->content_len] = 0x00;
|
||||||
|
HTTP_IO_RESULT http_res;
|
||||||
while (remaining > 0)
|
while (remaining > 0)
|
||||||
{
|
{
|
||||||
#if HTTP_SERVER_DEBUG_LEVEL > 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,
|
((struct file_server_data*) req->user_ctx)->base_path,
|
||||||
req->uri,
|
req->uri,
|
||||||
sizeof(filepath));
|
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_status(req, "307 Temporary Redirect");
|
||||||
httpd_resp_set_hdr(req, "Location", filename);
|
httpd_resp_set_hdr(req, "Location", filename);
|
||||||
httpd_resp_send(req, NULL, 0); // Response body can be empty
|
httpd_resp_send(req, NULL, 0); // Response body can be empty
|
||||||
#if HTTP_SERVER_DEBUG_LEVEL > 0
|
#if HTTP_SERVER_DEBUG_LEVEL > 0
|
||||||
ESP_LOGI(TAG, "Redirect request from POST");
|
ESP_LOGI(TAG, "Redirect request from POST");
|
||||||
#endif
|
#endif
|
||||||
return ESP_OK;
|
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
|
/* Keep track of remaining size of
|
||||||
|
|
@ -229,7 +240,7 @@ static esp_err_t POSTHandler(httpd_req_t *req)
|
||||||
remaining -= received;
|
remaining -= received;
|
||||||
}
|
}
|
||||||
|
|
||||||
return GETHandler(req);
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static esp_err_t GETHandler(httpd_req_t *req)
|
static esp_err_t GETHandler(httpd_req_t *req)
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,9 @@ esp_err_t WebGuiAppInit(void)
|
||||||
}
|
}
|
||||||
ESP_ERROR_CHECK(InitSysConfig());
|
ESP_ERROR_CHECK(InitSysConfig());
|
||||||
|
|
||||||
|
GetSysConf()->wifiSettings.Flags1.bIsWiFiEnabled = true;
|
||||||
|
GetSysConf()->wifiSettings.Flags1.bIsAP = false;
|
||||||
|
|
||||||
//init rom file system
|
//init rom file system
|
||||||
init_rom_fs("/espfs");
|
init_rom_fs("/espfs");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user