fix pass dynamic variable with parameter to the custom handler

This commit is contained in:
Bogdan Pilyugin 2022-10-11 14:48:14 +02:00
parent 88ac20f673
commit 29b49efdab
4 changed files with 1303 additions and 1306 deletions

View File

@ -1,74 +1,74 @@
/*! 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.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
* \file HTTPServer.h * \file HTTPServer.h
* \version 1.0 * \version 1.0
* \date 2022-08-14 * \date 2022-08-14
* \author Bogdan Pilyugin * \author Bogdan Pilyugin
* \brief * \brief
* \details * \details
* \copyright Apache License, Version 2.0 * \copyright Apache License, Version 2.0
*/ */
#ifndef COMPONENTS_WEB_GUI_APPLICATION_INCLUDE_HTTPSERVER_H_ #ifndef COMPONENTS_WEB_GUI_APPLICATION_INCLUDE_HTTPSERVER_H_
#define COMPONENTS_WEB_GUI_APPLICATION_INCLUDE_HTTPSERVER_H_ #define COMPONENTS_WEB_GUI_APPLICATION_INCLUDE_HTTPSERVER_H_
#include "esp_err.h" #include "esp_err.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_vfs.h" #include "esp_vfs.h"
#include <esp_http_server.h> #include <esp_http_server.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/unistd.h> #include <sys/unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "Helpers.h" #include "Helpers.h"
#include "SystemConfiguration.h" #include "SystemConfiguration.h"
#include "romfs.h" #include "romfs.h"
#include "NetTransport.h" #include "NetTransport.h"
#include <esp_event.h> #include <esp_event.h>
#include "esp_netif.h" #include "esp_netif.h"
#include "esp_eth.h" #include "esp_eth.h"
#include "mbedtls/base64.h" #include "mbedtls/base64.h"
#define MAX_DYNVAR_LENGTH 256 #define MAX_DYNVAR_LENGTH 256
#define MAX_INCFILE_LENGTH 1024 #define MAX_INCFILE_LENGTH 1024
#define HTTP_SERVER_DEBUG_LEVEL 0 #define HTTP_SERVER_DEBUG_LEVEL 0
typedef enum 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_DONE_NOREFRESH
} HTTP_IO_RESULT; } HTTP_IO_RESULT;
typedef struct typedef struct
{ {
const char tag[16]; const char tag[16];
const int taglen; const int taglen;
void (*HandlerRoutine)(char *VarData, void *arg); void (*HandlerRoutine)(char *VarData, void *arg);
} dyn_var_handler_t; } dyn_var_handler_t;
void regHTTPPrintCustom(int (*print_handler)(httpd_req_t *req, char *buf, char *var)); void regHTTPPrintCustom(int (*print_handler)(httpd_req_t *req, char *buf, char *var, int arg));
void regAfterPostHandlerCustom(HTTP_IO_RESULT (*post_handler)(httpd_req_t *req, const char *filename, char *PostData)); void regAfterPostHandlerCustom(HTTP_IO_RESULT (*post_handler)(httpd_req_t *req, const char *filename, char *PostData));
esp_err_t start_file_server(void); esp_err_t start_file_server(void);
HTTP_IO_RESULT HTTPPostApp(httpd_req_t *req, const char *filename, char *PostData); HTTP_IO_RESULT HTTPPostApp(httpd_req_t *req, const char *filename, char *PostData);
int HTTPPrint(httpd_req_t *req, char* buf, char* var); int HTTPPrint(httpd_req_t *req, char* buf, char* var);
#endif /* COMPONENTS_WEB_GUI_APPLICATION_INCLUDE_HTTPSERVER_H_ */ #endif /* COMPONENTS_WEB_GUI_APPLICATION_INCLUDE_HTTPSERVER_H_ */

View File

@ -1,463 +1,463 @@
/*! 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.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* *
* \file HTTPPostSystem.c * \file HTTPPostSystem.c
* \version 1.0 * \version 1.0
* \date 2022-08-14 * \date 2022-08-14
* \author Bogdan Pilyugin * \author Bogdan Pilyugin
* \brief * \brief
* \details * \details
* \copyright Apache License, Version 2.0 * \copyright Apache License, Version 2.0
*/ */
#include "HTTPServer.h" #include "HTTPServer.h"
static const char *TAG = "HTTPServerPost"; static const char *TAG = "HTTPServerPost";
#define FILE_PATH_MAX (ESP_VFS_PATH_MAX + CONFIG_SPIFFS_OBJ_NAME_LEN) #define FILE_PATH_MAX (ESP_VFS_PATH_MAX + CONFIG_SPIFFS_OBJ_NAME_LEN)
const char url_adapters[] = "adapters.html"; const char url_adapters[] = "adapters.html";
const char url_services[] = "services.html"; const char url_services[] = "services.html";
const char url_system[] = "system.html"; const char url_system[] = "system.html";
const char url_reboot[] = "reboot.html"; const char url_reboot[] = "reboot.html";
static HTTP_IO_RESULT AfterPostHandler(httpd_req_t *req, const char *filename, char *PostData); static HTTP_IO_RESULT AfterPostHandler(httpd_req_t *req, const char *filename, char *PostData);
static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData); static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData);
static HTTP_IO_RESULT HTTPPostServicesSettings(httpd_req_t *req, char *PostData); static HTTP_IO_RESULT HTTPPostServicesSettings(httpd_req_t *req, char *PostData);
static HTTP_IO_RESULT HTTPPostSystemSettings(httpd_req_t *req, char *PostData); static HTTP_IO_RESULT HTTPPostSystemSettings(httpd_req_t *req, char *PostData);
static HTTP_IO_RESULT HTTPPostReboot(httpd_req_t *req, char *PostData); static HTTP_IO_RESULT HTTPPostReboot(httpd_req_t *req, char *PostData);
HTTP_IO_RESULT (*AfterPostHandlerCust)(httpd_req_t *req, const char *filename, char *PostData); HTTP_IO_RESULT (*AfterPostHandlerCust)(httpd_req_t *req, const char *filename, char *PostData);
void regAfterPostHandlerCustom(HTTP_IO_RESULT (*post_handler)(httpd_req_t *req, const char *filename, char *PostData)) void regAfterPostHandlerCustom(HTTP_IO_RESULT (*post_handler)(httpd_req_t *req, const char *filename, char *PostData))
{ {
AfterPostHandlerCust = post_handler; AfterPostHandlerCust = post_handler;
} }
HTTP_IO_RESULT HTTPPostApp(httpd_req_t *req, const char *filename, char *PostData) HTTP_IO_RESULT HTTPPostApp(httpd_req_t *req, const char *filename, char *PostData)
{ {
const char *pt = filename + 1; const char *pt = filename + 1;
#if HTTP_SERVER_DEBUG_LEVEL > 0 #if HTTP_SERVER_DEBUG_LEVEL > 0
ESP_LOGI(TAG, "URI for POST processing:%s", req->uri); ESP_LOGI(TAG, "URI for POST processing:%s", req->uri);
ESP_LOGI(TAG, "Filename:%s", pt); ESP_LOGI(TAG, "Filename:%s", pt);
ESP_LOGI(TAG, "DATA for POST processing:%s", PostData); ESP_LOGI(TAG, "DATA for POST processing:%s", PostData);
#endif #endif
HTTP_IO_RESULT res = AfterPostHandler(req, pt, PostData); HTTP_IO_RESULT res = AfterPostHandler(req, pt, PostData);
switch (res) switch (res)
{ {
case HTTP_IO_DONE: case HTTP_IO_DONE:
break; break;
case HTTP_IO_WAITING: case HTTP_IO_WAITING:
break; break;
case HTTP_IO_NEED_DATA: case HTTP_IO_NEED_DATA:
break; break;
case HTTP_IO_REDIRECT: case HTTP_IO_REDIRECT:
strcpy((char*) filename, PostData); strcpy((char*) filename, PostData);
break; break;
case HTTP_IO_DONE_NOREFRESH: case HTTP_IO_DONE_NOREFRESH:
break; break;
break; break;
} }
return res; return res;
} }
static HTTP_IO_RESULT AfterPostHandler(httpd_req_t *req, const char *filename, char *PostData) static HTTP_IO_RESULT AfterPostHandler(httpd_req_t *req, const char *filename, char *PostData)
{ {
if (!memcmp(filename, url_adapters, sizeof(url_adapters))) if (!memcmp(filename, url_adapters, sizeof(url_adapters)))
return HTTPPostAdaptersSettings(req, PostData); return HTTPPostAdaptersSettings(req, PostData);
if (!memcmp(filename, url_services, sizeof(url_services))) if (!memcmp(filename, url_services, sizeof(url_services)))
return HTTPPostServicesSettings(req, PostData); return HTTPPostServicesSettings(req, PostData);
if (!memcmp(filename, url_system, sizeof(url_system))) if (!memcmp(filename, url_system, sizeof(url_system)))
return HTTPPostSystemSettings(req, PostData); return HTTPPostSystemSettings(req, PostData);
if (!memcmp(filename, url_reboot, sizeof(url_reboot))) if (!memcmp(filename, url_reboot, sizeof(url_reboot)))
return HTTPPostReboot(req, PostData); return HTTPPostReboot(req, PostData);
// If not found target URL here, try to call custom code // If not found target URL here, try to call custom code
if (AfterPostHandlerCust != NULL) if (AfterPostHandlerCust != NULL)
AfterPostHandlerCust(req, filename, PostData); AfterPostHandlerCust(req, filename, PostData);
return HTTP_IO_DONE; return HTTP_IO_DONE;
} }
static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData) static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData)
{ {
char tmp[32]; char tmp[32];
#if CONFIG_WEBGUIAPP_ETHERNET_ENABLE #if CONFIG_WEBGUIAPP_ETHERNET_ENABLE
bool TempIsETHEnabled = false; bool TempIsETHEnabled = false;
bool TempIsETHDHCPEnabled = false; bool TempIsETHDHCPEnabled = false;
if (httpd_query_key_value(PostData, "ethen", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "ethen", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (!strcmp((const char*) tmp, (const char*) "1")) if (!strcmp((const char*) tmp, (const char*) "1"))
TempIsETHEnabled = true; TempIsETHEnabled = true;
} }
if (httpd_query_key_value(PostData, "dhcp", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "dhcp", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (!strcmp((const char*) tmp, (const char*) "1")) if (!strcmp((const char*) tmp, (const char*) "1"))
TempIsETHDHCPEnabled = true; TempIsETHDHCPEnabled = true;
} }
if (httpd_query_key_value(PostData, "ipa", tmp, 15) == ESP_OK) if (httpd_query_key_value(PostData, "ipa", tmp, 15) == ESP_OK)
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.IPAddr); esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.IPAddr);
if (httpd_query_key_value(PostData, "mas", tmp, 15) == ESP_OK) if (httpd_query_key_value(PostData, "mas", tmp, 15) == ESP_OK)
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.Mask); esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.Mask);
if (httpd_query_key_value(PostData, "gte", tmp, 15) == ESP_OK) if (httpd_query_key_value(PostData, "gte", tmp, 15) == ESP_OK)
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.Gateway); esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.Gateway);
if (httpd_query_key_value(PostData, "dns1", tmp, 15) == ESP_OK) if (httpd_query_key_value(PostData, "dns1", tmp, 15) == ESP_OK)
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.DNSAddr1); esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.DNSAddr1);
if (httpd_query_key_value(PostData, "dns2", tmp, 15) == ESP_OK) if (httpd_query_key_value(PostData, "dns2", tmp, 15) == ESP_OK)
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.DNSAddr2); esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->ethSettings.DNSAddr2);
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);
#endif #endif
#if CONFIG_WEBGUIAPP_WIFI_ENABLE #if CONFIG_WEBGUIAPP_WIFI_ENABLE
bool TempIsWiFiEnabled = false; bool TempIsWiFiEnabled = false;
bool TempIsWIFIDHCPEnabled = false; bool TempIsWIFIDHCPEnabled = false;
if (httpd_query_key_value(PostData, "wifien", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "wifien", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (!strcmp((const char*) tmp, (const char*) "1")) if (!strcmp((const char*) tmp, (const char*) "1"))
TempIsWiFiEnabled = true; TempIsWiFiEnabled = true;
} }
if (httpd_query_key_value(PostData, "netm", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "netm", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (!strcmp((const char*) tmp, (const char*) "1")) if (!strcmp((const char*) tmp, (const char*) "1"))
GetSysConf()->wifiSettings.Flags1.bIsAP = true; GetSysConf()->wifiSettings.Flags1.bIsAP = true;
else if (!strcmp((const char*) tmp, (const char*) "2")) else if (!strcmp((const char*) tmp, (const char*) "2"))
GetSysConf()->wifiSettings.Flags1.bIsAP = false; GetSysConf()->wifiSettings.Flags1.bIsAP = false;
} }
/*AP section*/ /*AP section*/
httpd_query_key_value(PostData, "wfiap", GetSysConf()->wifiSettings.ApSSID, httpd_query_key_value(PostData, "wfiap", GetSysConf()->wifiSettings.ApSSID,
sizeof(GetSysConf()->wifiSettings.ApSSID)); sizeof(GetSysConf()->wifiSettings.ApSSID));
if (httpd_query_key_value(PostData, "wfpap", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "wfpap", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (strcmp(tmp, (const char*) "********")) if (strcmp(tmp, (const char*) "********"))
strcpy(GetSysConf()->wifiSettings.ApSecurityKey, tmp); strcpy(GetSysConf()->wifiSettings.ApSecurityKey, tmp);
} }
if (httpd_query_key_value(PostData, "ipaap", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "ipaap", tmp, sizeof(tmp)) == ESP_OK)
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.ApIPAddr); esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.ApIPAddr);
httpd_query_key_value(PostData, "wfi", GetSysConf()->wifiSettings.InfSSID, httpd_query_key_value(PostData, "wfi", GetSysConf()->wifiSettings.InfSSID,
sizeof(GetSysConf()->wifiSettings.InfSSID)); sizeof(GetSysConf()->wifiSettings.InfSSID));
if (httpd_query_key_value(PostData, "wfp", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "wfp", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (strcmp(tmp, (const char*) "********")) if (strcmp(tmp, (const char*) "********"))
strcpy(GetSysConf()->wifiSettings.InfSecurityKey, tmp); strcpy(GetSysConf()->wifiSettings.InfSecurityKey, tmp);
} }
/*STATION section*/ /*STATION section*/
if (httpd_query_key_value(PostData, "dhcp", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "dhcp", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (!strcmp((const char*) tmp, (const char*) "1")) if (!strcmp((const char*) tmp, (const char*) "1"))
TempIsWIFIDHCPEnabled = true; TempIsWIFIDHCPEnabled = true;
} }
if (httpd_query_key_value(PostData, "ipa", tmp, 15) == ESP_OK) if (httpd_query_key_value(PostData, "ipa", tmp, 15) == ESP_OK)
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.InfIPAddr); esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.InfIPAddr);
if (httpd_query_key_value(PostData, "mas", tmp, 15) == ESP_OK) if (httpd_query_key_value(PostData, "mas", tmp, 15) == ESP_OK)
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.InfMask); esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.InfMask);
if (httpd_query_key_value(PostData, "gte", tmp, 15) == ESP_OK) if (httpd_query_key_value(PostData, "gte", tmp, 15) == ESP_OK)
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.InfGateway); esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.InfGateway);
if (httpd_query_key_value(PostData, "dns", tmp, 15) == ESP_OK) if (httpd_query_key_value(PostData, "dns", tmp, 15) == ESP_OK)
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.DNSAddr1); esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.DNSAddr1);
if (httpd_query_key_value(PostData, "dns2", tmp, 15) == ESP_OK) if (httpd_query_key_value(PostData, "dns2", tmp, 15) == ESP_OK)
esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.DNSAddr2); esp_netif_str_to_ip4(tmp, (esp_ip4_addr_t*) &GetSysConf()->wifiSettings.DNSAddr2);
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);
#endif #endif
#if CONFIG_WEBGUIAPP_GPRS_ENABLE #if CONFIG_WEBGUIAPP_GPRS_ENABLE
bool TempIsGSMEnabled = false; bool TempIsGSMEnabled = false;
if (httpd_query_key_value(PostData, "gsmen", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "gsmen", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (!strcmp((const char*) tmp, (const char*) "1")) if (!strcmp((const char*) tmp, (const char*) "1"))
TempIsGSMEnabled = true; TempIsGSMEnabled = true;
} }
if (httpd_query_key_value(PostData, "sav", tmp, 4) == ESP_OK) if (httpd_query_key_value(PostData, "sav", tmp, 4) == ESP_OK)
{ {
if (!strcmp(tmp, (const char*) "prs")) if (!strcmp(tmp, (const char*) "prs"))
{ {
GetSysConf()->gsmSettings.Flags1.bIsGSMEnabled = TempIsGSMEnabled; GetSysConf()->gsmSettings.Flags1.bIsGSMEnabled = TempIsGSMEnabled;
WriteNVSSysConfig(GetSysConf()); WriteNVSSysConfig(GetSysConf());
memcpy(PostData, "/reboot.html", sizeof "/reboot.html"); memcpy(PostData, "/reboot.html", sizeof "/reboot.html");
return HTTP_IO_REDIRECT; return HTTP_IO_REDIRECT;
} }
} }
if (httpd_query_key_value(PostData, "restart", tmp, 4) == ESP_OK) if (httpd_query_key_value(PostData, "restart", tmp, 4) == ESP_OK)
{ {
if (!strcmp(tmp, (const char*) "prs")) if (!strcmp(tmp, (const char*) "prs"))
{ {
//PPPModemSoftRestart(); //PPPModemSoftRestart();
} }
} }
if (httpd_query_key_value(PostData, "hdrst", tmp, 4) == ESP_OK) if (httpd_query_key_value(PostData, "hdrst", tmp, 4) == ESP_OK)
{ {
if (!strcmp(tmp, (const char*) "prs")) if (!strcmp(tmp, (const char*) "prs"))
{ {
//PPPModemColdStart(); //PPPModemColdStart();
} }
} }
#endif #endif
if (httpd_query_key_value(PostData, "save", tmp, 5) == ESP_OK || if (httpd_query_key_value(PostData, "save", tmp, 5) == ESP_OK ||
httpd_query_key_value(PostData, "apply", tmp, 5) == ESP_OK) httpd_query_key_value(PostData, "apply", tmp, 5) == ESP_OK)
{ {
if (!strcmp(tmp, (const char*) "eth")) if (!strcmp(tmp, (const char*) "eth"))
{ {
#if CONFIG_WEBGUIAPP_ETHERNET_ENABLE #if CONFIG_WEBGUIAPP_ETHERNET_ENABLE
GetSysConf()->ethSettings.Flags1.bIsETHEnabled = TempIsETHEnabled; GetSysConf()->ethSettings.Flags1.bIsETHEnabled = TempIsETHEnabled;
GetSysConf()->ethSettings.Flags1.bIsDHCPEnabled = TempIsETHDHCPEnabled; GetSysConf()->ethSettings.Flags1.bIsDHCPEnabled = TempIsETHDHCPEnabled;
#endif #endif
} }
else if (!strcmp(tmp, (const char*) "wifi")) else if (!strcmp(tmp, (const char*) "wifi"))
{ {
#if CONFIG_WEBGUIAPP_WIFI_ENABLE #if CONFIG_WEBGUIAPP_WIFI_ENABLE
GetSysConf()->wifiSettings.Flags1.bIsWiFiEnabled = TempIsWiFiEnabled; GetSysConf()->wifiSettings.Flags1.bIsWiFiEnabled = TempIsWiFiEnabled;
GetSysConf()->wifiSettings.Flags1.bIsDHCPEnabled = TempIsWIFIDHCPEnabled; GetSysConf()->wifiSettings.Flags1.bIsDHCPEnabled = TempIsWIFIDHCPEnabled;
#endif #endif
} }
else if (!strcmp(tmp, (const char*) "gprs")) else if (!strcmp(tmp, (const char*) "gprs"))
{ {
#if CONFIG_WEBGUIAPP_GPRS_ENABLE #if CONFIG_WEBGUIAPP_GPRS_ENABLE
GetSysConf()->gsmSettings.Flags1.bIsGSMEnabled = TempIsGSMEnabled; GetSysConf()->gsmSettings.Flags1.bIsGSMEnabled = TempIsGSMEnabled;
#endif #endif
} }
if (httpd_query_key_value(PostData, "apply", tmp, 5) == ESP_OK) if (httpd_query_key_value(PostData, "apply", tmp, 5) == ESP_OK)
{ {
WriteNVSSysConfig(GetSysConf()); WriteNVSSysConfig(GetSysConf());
return HTTP_IO_DONE; return HTTP_IO_DONE;
} }
else if (httpd_query_key_value(PostData, "save", tmp, 5) == ESP_OK) else if (httpd_query_key_value(PostData, "save", tmp, 5) == ESP_OK)
{ {
WriteNVSSysConfig(GetSysConf()); WriteNVSSysConfig(GetSysConf());
memcpy(PostData, "/reboot.html", sizeof "/reboot.html"); memcpy(PostData, "/reboot.html", sizeof "/reboot.html");
return HTTP_IO_REDIRECT; return HTTP_IO_REDIRECT;
} }
} }
return HTTP_IO_DONE; return HTTP_IO_DONE;
} }
static HTTP_IO_RESULT HTTPPostServicesSettings(httpd_req_t *req, char *PostData) static HTTP_IO_RESULT HTTPPostServicesSettings(httpd_req_t *req, char *PostData)
{ {
char tmp[33]; char tmp[33];
#if CONFIG_WEBGUIAPP_MQTT_ENABLE #if CONFIG_WEBGUIAPP_MQTT_ENABLE
bool TempIsMQTT1Enabled = false; bool TempIsMQTT1Enabled = false;
#if CONFIG_WEBGUIAPP_MQTT_CLIENTS_NUM == 2 #if CONFIG_WEBGUIAPP_MQTT_CLIENTS_NUM == 2
bool TempIsMQTT2Enabled = false; bool TempIsMQTT2Enabled = false;
#endif #endif
httpd_query_key_value(PostData, "mqurl1", GetSysConf()->mqttStation[0].ServerAddr, httpd_query_key_value(PostData, "mqurl1", GetSysConf()->mqttStation[0].ServerAddr,
sizeof(GetSysConf()->mqttStation[0].ServerAddr)); sizeof(GetSysConf()->mqttStation[0].ServerAddr));
httpd_query_key_value(PostData, "mqid1", GetSysConf()->mqttStation[0].ClientID, httpd_query_key_value(PostData, "mqid1", GetSysConf()->mqttStation[0].ClientID,
sizeof(GetSysConf()->mqttStation[0].ClientID)); sizeof(GetSysConf()->mqttStation[0].ClientID));
httpd_query_key_value(PostData, "mqsys1", GetSysConf()->mqttStation[0].SystemName, httpd_query_key_value(PostData, "mqsys1", GetSysConf()->mqttStation[0].SystemName,
sizeof(GetSysConf()->mqttStation[0].SystemName)); sizeof(GetSysConf()->mqttStation[0].SystemName));
httpd_query_key_value(PostData, "mqgrp1", GetSysConf()->mqttStation[0].GroupName, httpd_query_key_value(PostData, "mqgrp1", GetSysConf()->mqttStation[0].GroupName,
sizeof(GetSysConf()->mqttStation[0].GroupName)); sizeof(GetSysConf()->mqttStation[0].GroupName));
httpd_query_key_value(PostData, "mqname1", GetSysConf()->mqttStation[0].UserName, httpd_query_key_value(PostData, "mqname1", GetSysConf()->mqttStation[0].UserName,
sizeof(GetSysConf()->mqttStation[0].UserName)); sizeof(GetSysConf()->mqttStation[0].UserName));
if (httpd_query_key_value(PostData, "mqen1", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "mqen1", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (!strcmp((const char*) tmp, (const char*) "1")) if (!strcmp((const char*) tmp, (const char*) "1"))
TempIsMQTT1Enabled = true; TempIsMQTT1Enabled = true;
} }
if (httpd_query_key_value(PostData, "mqport1", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "mqport1", tmp, sizeof(tmp)) == ESP_OK)
if (httpd_query_key_value(PostData, "mqport1", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "mqport1", tmp, sizeof(tmp)) == ESP_OK)
{ {
uint16_t tp = atoi((const char*) tmp); uint16_t tp = atoi((const char*) tmp);
if (tp < 65535 && tp >= 1000) if (tp < 65535 && tp >= 1000)
GetSysConf()->mqttStation[0].ServerPort = tp; GetSysConf()->mqttStation[0].ServerPort = tp;
} }
if (httpd_query_key_value(PostData, "mqpass1", tmp, sizeof(tmp)) == ESP_OK && if (httpd_query_key_value(PostData, "mqpass1", tmp, sizeof(tmp)) == ESP_OK &&
strcmp(tmp, (const char*) "******")) strcmp(tmp, (const char*) "******"))
{ {
strcpy(GetSysConf()->mqttStation[0].UserPass, tmp); strcpy(GetSysConf()->mqttStation[0].UserPass, tmp);
} }
#if CONFIG_WEBGUIAPP_MQTT_CLIENTS_NUM == 2 #if CONFIG_WEBGUIAPP_MQTT_CLIENTS_NUM == 2
httpd_query_key_value(PostData, "mqurl2", GetSysConf()->mqttStation[1].ServerAddr, httpd_query_key_value(PostData, "mqurl2", GetSysConf()->mqttStation[1].ServerAddr,
sizeof(GetSysConf()->mqttStation[1].ServerAddr)); sizeof(GetSysConf()->mqttStation[1].ServerAddr));
httpd_query_key_value(PostData, "mqid2", GetSysConf()->mqttStation[1].ClientID, httpd_query_key_value(PostData, "mqid2", GetSysConf()->mqttStation[1].ClientID,
sizeof(GetSysConf()->mqttStation[1].ClientID)); sizeof(GetSysConf()->mqttStation[1].ClientID));
httpd_query_key_value(PostData, "mqsys2", GetSysConf()->mqttStation[1].SystemName, httpd_query_key_value(PostData, "mqsys2", GetSysConf()->mqttStation[1].SystemName,
sizeof(GetSysConf()->mqttStation[1].SystemName)); sizeof(GetSysConf()->mqttStation[1].SystemName));
httpd_query_key_value(PostData, "mqgrp2", GetSysConf()->mqttStation[1].GroupName, httpd_query_key_value(PostData, "mqgrp2", GetSysConf()->mqttStation[1].GroupName,
sizeof(GetSysConf()->mqttStation[1].GroupName)); sizeof(GetSysConf()->mqttStation[1].GroupName));
httpd_query_key_value(PostData, "mqname2", GetSysConf()->mqttStation[1].UserName, httpd_query_key_value(PostData, "mqname2", GetSysConf()->mqttStation[1].UserName,
sizeof(GetSysConf()->mqttStation[1].UserName)); sizeof(GetSysConf()->mqttStation[1].UserName));
if (httpd_query_key_value(PostData, "mqen2", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "mqen2", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (!strcmp((const char*) tmp, (const char*) "1")) if (!strcmp((const char*) tmp, (const char*) "1"))
TempIsMQTT2Enabled = true; TempIsMQTT2Enabled = true;
} }
if (httpd_query_key_value(PostData, "mqport2", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "mqport2", tmp, sizeof(tmp)) == ESP_OK)
if (httpd_query_key_value(PostData, "mqport2", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "mqport2", tmp, sizeof(tmp)) == ESP_OK)
{ {
uint16_t tp = atoi((const char*) tmp); uint16_t tp = atoi((const char*) tmp);
if (tp < 65535 && tp >= 1000) if (tp < 65535 && tp >= 1000)
GetSysConf()->mqttStation[1].ServerPort = tp; GetSysConf()->mqttStation[1].ServerPort = tp;
} }
if (httpd_query_key_value(PostData, "mqpass2", tmp, sizeof(tmp)) == ESP_OK && if (httpd_query_key_value(PostData, "mqpass2", tmp, sizeof(tmp)) == ESP_OK &&
strcmp(tmp, (const char*) "******")) strcmp(tmp, (const char*) "******"))
{ {
strcpy(GetSysConf()->mqttStation[1].UserPass, tmp); strcpy(GetSysConf()->mqttStation[1].UserPass, tmp);
} }
#endif #endif
/*SNTP*/ /*SNTP*/
bool TempIsSNTPEnabled = false; bool TempIsSNTPEnabled = false;
if (httpd_query_key_value(PostData, "sntpen", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "sntpen", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (!strcmp((const char*) tmp, (const char*) "1")) if (!strcmp((const char*) tmp, (const char*) "1"))
TempIsSNTPEnabled = true; TempIsSNTPEnabled = true;
} }
httpd_query_key_value(PostData, "tsr", GetSysConf()->sntpClient.SntpServerAdr, httpd_query_key_value(PostData, "tsr", GetSysConf()->sntpClient.SntpServerAdr,
sizeof(GetSysConf()->sntpClient.SntpServerAdr)); sizeof(GetSysConf()->sntpClient.SntpServerAdr));
if (httpd_query_key_value(PostData, "save", tmp, 6) == ESP_OK || if (httpd_query_key_value(PostData, "save", tmp, 6) == ESP_OK ||
httpd_query_key_value(PostData, "apply", tmp, 6) == ESP_OK) httpd_query_key_value(PostData, "apply", tmp, 6) == ESP_OK)
{ {
if (!strcmp(tmp, (const char*) "mqtt1")) if (!strcmp(tmp, (const char*) "mqtt1"))
{ {
GetSysConf()->mqttStation[0].Flags1.bIsGlobalEnabled = TempIsMQTT1Enabled; GetSysConf()->mqttStation[0].Flags1.bIsGlobalEnabled = TempIsMQTT1Enabled;
} }
else if (!strcmp(tmp, (const char*) "mqtt2")) else if (!strcmp(tmp, (const char*) "mqtt2"))
{ {
#if CONFIG_WEBGUIAPP_MQTT_CLIENTS_NUM == 2 #if CONFIG_WEBGUIAPP_MQTT_CLIENTS_NUM == 2
GetSysConf()->mqttStation[1].Flags1.bIsGlobalEnabled = TempIsMQTT2Enabled; GetSysConf()->mqttStation[1].Flags1.bIsGlobalEnabled = TempIsMQTT2Enabled;
#endif #endif
} }
else if (!strcmp(tmp, (const char*) "sntp")) else if (!strcmp(tmp, (const char*) "sntp"))
{ {
GetSysConf()->sntpClient.Flags1.bIsGlobalEnabled = TempIsSNTPEnabled; GetSysConf()->sntpClient.Flags1.bIsGlobalEnabled = TempIsSNTPEnabled;
} }
if (httpd_query_key_value(PostData, "apply", tmp, 5) == ESP_OK) if (httpd_query_key_value(PostData, "apply", tmp, 6) == ESP_OK)
{ {
WriteNVSSysConfig(GetSysConf()); WriteNVSSysConfig(GetSysConf());
return HTTP_IO_DONE; return HTTP_IO_DONE;
} }
else if (httpd_query_key_value(PostData, "save", tmp, 5) == ESP_OK) else if (httpd_query_key_value(PostData, "save", tmp, 6) == ESP_OK)
{ {
WriteNVSSysConfig(GetSysConf()); WriteNVSSysConfig(GetSysConf());
memcpy(PostData, "/reboot.html", sizeof "/reboot.html"); memcpy(PostData, "/reboot.html", sizeof "/reboot.html");
return HTTP_IO_REDIRECT; return HTTP_IO_REDIRECT;
} }
} }
#endif #endif
return HTTP_IO_DONE; return HTTP_IO_DONE;
} }
static HTTP_IO_RESULT HTTPPostSystemSettings(httpd_req_t *req, char *PostData) static HTTP_IO_RESULT HTTPPostSystemSettings(httpd_req_t *req, char *PostData)
{ {
char tmp[64]; char tmp[64];
bool TempIsOTAEnabled = false; bool TempIsOTAEnabled = false;
if (httpd_query_key_value(PostData, "nam", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "nam", tmp, sizeof(tmp)) == ESP_OK)
{ {
UnencodeURL(tmp); UnencodeURL(tmp);
strcpy(GetSysConf()->NetBIOSName, tmp); strcpy(GetSysConf()->NetBIOSName, tmp);
} }
httpd_query_key_value(PostData, "lgn", GetSysConf()->SysName, sizeof(GetSysConf()->SysName)); httpd_query_key_value(PostData, "lgn", GetSysConf()->SysName, sizeof(GetSysConf()->SysName));
if (httpd_query_key_value(PostData, "psn", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "psn", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (strcmp(tmp, (const char*) "******")) if (strcmp(tmp, (const char*) "******"))
strcpy(GetSysConf()->SysPass, tmp); strcpy(GetSysConf()->SysPass, tmp);
} }
if (httpd_query_key_value(PostData, "ota", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "ota", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (!strcmp((const char*) tmp, (const char*) "1")) if (!strcmp((const char*) tmp, (const char*) "1"))
TempIsOTAEnabled = true; TempIsOTAEnabled = true;
} }
if (httpd_query_key_value(PostData, "otaurl", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "otaurl", tmp, sizeof(tmp)) == ESP_OK)
{ {
UnencodeURL(tmp); UnencodeURL(tmp);
strcpy(GetSysConf()->OTAURL, tmp); strcpy(GetSysConf()->OTAURL, tmp);
} }
if (httpd_query_key_value(PostData, "upd", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "upd", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (!strcmp(tmp, (const char*) "prs")) if (!strcmp(tmp, (const char*) "prs"))
{ {
//StartOTA(); //StartOTA();
} }
} }
if (httpd_query_key_value(PostData, "rst", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "rst", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (!strcmp(tmp, (const char*) "prs")) if (!strcmp(tmp, (const char*) "prs"))
{ {
memcpy(PostData, "/reboot.html", sizeof "/reboot.html"); memcpy(PostData, "/reboot.html", sizeof "/reboot.html");
return HTTP_IO_REDIRECT; return HTTP_IO_REDIRECT;
} }
} }
if (httpd_query_key_value(PostData, "save", tmp, sizeof(tmp)) == ESP_OK || if (httpd_query_key_value(PostData, "save", tmp, sizeof(tmp)) == ESP_OK ||
httpd_query_key_value(PostData, "apply", tmp, sizeof(tmp)) == ESP_OK) httpd_query_key_value(PostData, "apply", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (!strcmp(tmp, (const char*) "syst")) if (!strcmp(tmp, (const char*) "syst"))
{ {
GetSysConf()->Flags1.bIsOTAEnabled = TempIsOTAEnabled; GetSysConf()->Flags1.bIsOTAEnabled = TempIsOTAEnabled;
} }
if (httpd_query_key_value(PostData, "apply", tmp, 5) == ESP_OK) if (httpd_query_key_value(PostData, "apply", tmp, 5) == ESP_OK)
{ {
WriteNVSSysConfig(GetSysConf()); WriteNVSSysConfig(GetSysConf());
return HTTP_IO_DONE; return HTTP_IO_DONE;
} }
else if (httpd_query_key_value(PostData, "save", tmp, 5) == ESP_OK) else if (httpd_query_key_value(PostData, "save", tmp, 5) == ESP_OK)
{ {
WriteNVSSysConfig(GetSysConf()); WriteNVSSysConfig(GetSysConf());
memcpy(PostData, "/reboot.html", sizeof "/reboot.html"); memcpy(PostData, "/reboot.html", sizeof "/reboot.html");
return HTTP_IO_REDIRECT; return HTTP_IO_REDIRECT;
} }
} }
return HTTP_IO_DONE; return HTTP_IO_DONE;
} }
static HTTP_IO_RESULT HTTPPostReboot(httpd_req_t *req, char *PostData) static HTTP_IO_RESULT HTTPPostReboot(httpd_req_t *req, char *PostData)
{ {
char tmp[33]; char tmp[33];
if (httpd_query_key_value(PostData, "rbt", tmp, sizeof(tmp)) == ESP_OK) if (httpd_query_key_value(PostData, "rbt", tmp, sizeof(tmp)) == ESP_OK)
{ {
if (!strcmp(tmp, (const char*) "prs")) if (!strcmp(tmp, (const char*) "prs"))
{ {
DelayedRestart(); DelayedRestart();
} }
} }
return HTTP_IO_DONE; return HTTP_IO_DONE;
} }

File diff suppressed because it is too large Load Diff

View File

@ -183,9 +183,6 @@ static void InitSysIO(void)
static void InitSysSPI(void) static void InitSysSPI(void)
{ {
#ifdef CONFIG_WEBGUIAPP_SPI_ENABLE #ifdef CONFIG_WEBGUIAPP_SPI_ENABLE
//spi_device_init_custom();
spi_bus_config_t buscfg = { spi_bus_config_t buscfg = {
.miso_io_num = CONFIG_SPI_MISO_GPIO, .miso_io_num = CONFIG_SPI_MISO_GPIO,
.mosi_io_num = CONFIG_SPI_MOSI_GPIO, .mosi_io_num = CONFIG_SPI_MOSI_GPIO,