From 1f40da076afade97f9bb93112d16bb7a76fe6c99 Mon Sep 17 00:00:00 2001
From: fvanroie
");
- #if HASP_USE_WIFI > 0
+ #if HASP_USE_WIFI > 0
httpMessage +=
F("
Backlight Control
"); httpMessage += F(""); @@ -1124,8 +1125,8 @@ void webHandleGuiConfig() if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); } - //////////////////////////////////////////////////////////////////////////////////////////////////// - #if HASP_USE_WIFI > 0 + //////////////////////////////////////////////////////////////////////////////////////////////////// + #if HASP_USE_WIFI > 0 void webHandleWifiConfig() { // http://plate01/config/wifi if(!httpIsAuthenticated(F("config/wifi"))) return; @@ -1150,26 +1151,26 @@ void webHandleWifiConfig() } httpMessage += F("'>"); - #if HASP_USE_WIFI > 0 && !defined(STM32F4xx) + #if HASP_USE_WIFI > 0 && !defined(STM32F4xx) if(WiFi.getMode() == WIFI_STA) { httpMessage += PSTR(""); } - #endif + #endif webSendPage(httpGetNodename(), httpMessage.length(), false); webServer.sendContent(httpMessage); - #if defined(STM32F4xx) + #if defined(STM32F4xx) httpMessage = ""; - #else + #else httpMessage.clear(); - #endif + #endif webSendFooter(); } - #endif + #endif - //////////////////////////////////////////////////////////////////////////////////////////////////// - #if HASP_USE_HTTP > 0 + //////////////////////////////////////////////////////////////////////////////////////////////////// + #if HASP_USE_HTTP > 0 void webHandleHttpConfig() { // http://plate01/config/http if(!httpIsAuthenticated(F("config/http"))) return; @@ -1204,10 +1205,10 @@ void webHandleHttpConfig() // httpMessage.clear(); webSendFooter(); } - #endif + #endif - //////////////////////////////////////////////////////////////////////////////////////////////////// - #if defined(HASP_USE_GPIO) && (HASP_USE_GPIO > 0) + //////////////////////////////////////////////////////////////////////////////////////////////////// + #if defined(HASP_USE_GPIO) && (HASP_USE_GPIO > 0) void webHandleGpioConfig() { // http://plate01/config/gpio if(!httpIsAuthenticated(F("config/gpio"))) return; @@ -1407,7 +1408,7 @@ void webHandleGpioOptions() if(webServer.hasArg(F("action"))) dispatch_text_line(webServer.arg(F("action")).c_str()); // Security check } - #endif // HASP_USE_GPIO + #endif // HASP_USE_GPIO //////////////////////////////////////////////////////////////////////////////////////////////////// void webHandleDebugConfig() @@ -1440,7 +1441,7 @@ void webHandleDebugConfig() httpMessage += settings[FPSTR(F_DEBUG_TELEPERIOD)].asUI Theme (required)"); httpMessage += F("Hue
"); httpMessage += F("Default Font
"); httpMessage += F("Startup Layout (optional) 0
+void webHandleSaveConfig()
+{
+ if(!httpIsAuthenticated(F("saveConfig"))) return;
+
+ configWriteConfig();
+}
+
////////////////////////////////////////////////////////////////////////////////////////////////////
void httpHandleResetConfig()
{ // http://plate01/resetConfig
@@ -1713,6 +1716,7 @@ void httpHandleResetConfig()
dispatch_reboot(false); // Do not save the current config
}
}
+ #endif // HASP_USE_CONFIG
void httpStart()
{
@@ -1750,109 +1754,96 @@ void httpSetup()
{
// httpSetConfig(settings);
- #if HASP_USE_WIFI > 0
- #if !defined(STM32F4xx)
- if(WiFi.getMode() != WIFI_STA) {
- Log.notice(TAG_HTTP, F("Wifi access point"));
- webServer.on(F("/"), webHandleWifiConfig);
- } else {
- #endif
- #endif
-
- webServer.on(F("/page/"), []() {
- String pageid = webServer.arg(F("page"));
- webServer.send(200, PSTR("text/plain"), "Page: '" + pageid + "'");
- haspSetPage(pageid.toInt());
- });
-
- #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
- webServer.on(F("/list"), HTTP_GET, handleFileList);
- // load editor
- webServer.on(F("/edit"), HTTP_GET, []() {
- if(!handleFileRead("/edit.htm")) {
- char mimetype[16];
- snprintf(mimetype, sizeof(mimetype), PSTR("text/plain"));
- webServer.send_P(404, mimetype, PSTR("FileNotFound"));
- }
- });
- webServer.on(F("/edit"), HTTP_PUT, handleFileCreate);
- webServer.on(F("/edit"), HTTP_DELETE, handleFileDelete);
- // first callback is called after the request has ended with all parsed arguments
- // second callback handles file uploads at that location
- webServer.on(
- F("/edit"), HTTP_POST,
- []() {
- webServer.send(200, "text/plain", "");
- Log.verbose(TAG_HTTP, F("Headers: %d"), webServer.headers());
- },
- handleFileUpload);
- #endif
-
- // get heap status, analog input value and all GPIO statuses in one json call
- /*webServer.on(F("/all"), HTTP_GET, []() {
- String json;
- json.reserve(128);
- json += F("{\"heap\":");
- json += String(ESP.getFreeHeap());
- json += F(", \"analog\":");
- json += String(analogRead(A0));
- json += F("}");
-
- char mimetype[128];
- sprintf(mimetype, PSTR("text/json"));
- webServer.send(200, mimetype, json);
- json.clear();
- });*/
-
- webServer.on(F("/"), webHandleRoot);
- webServer.on(F("/info"), webHandleInfo);
-
- webServer.on(F("/config/hasp"), webHandleHaspConfig);
- webServer.on(F("/config/http"), webHandleHttpConfig);
- webServer.on(F("/config/gui"), webHandleGuiConfig);
- webServer.on(F("/config/debug"), webHandleDebugConfig);
- #if HASP_USE_MQTT > 0
- webServer.on(F("/config/mqtt"), webHandleMqttConfig);
- #endif
- #if HASP_USE_WIFI > 0
- webServer.on(F("/config/wifi"), webHandleWifiConfig);
- #endif
- #if HASP_USE_GPIO > 0
- webServer.on(F("/config/gpio"), webHandleGpioConfig);
- webServer.on(F("/config/gpio/options"), webHandleGpioOptions);
- #endif
- webServer.on(F("/screenshot"), webHandleScreenshot);
- webServer.on(F("/saveConfig"), webHandleSaveConfig);
- webServer.on(F("/resetConfig"), httpHandleResetConfig);
- webServer.on(F("/firmware"), webHandleFirmware);
- #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
- webServer.on(
- F("/update"), HTTP_POST,
- []() {
- webServer.send(200, "text/plain", "");
- Log.verbose(TAG_HTTP, F("Total size: %s"), webServer.hostHeader().c_str());
- },
- webHandleFirmwareUpdate);
- webServer.on(F("/espfirmware"), httpHandleEspFirmware);
- #endif
- webServer.on(F("/reboot"), httpHandleReboot);
- webServer.onNotFound(httpHandleNotFound);
- #if HASP_USE_WIFI > 0
- #if !defined(STM32F4xx)
- }
- #endif
- #endif
-
- // Shared pages
- webServer.on(F("/about"), webHandleAbout);
- webServer.on(F("/config"), webHandleConfig);
- webServer.onNotFound(httpHandleNotFound);
-
// ask server to track these headers
const char * headerkeys[] = {"Content-Length"}; // "Authentication"
size_t headerkeyssize = sizeof(headerkeys) / sizeof(char *);
webServer.collectHeaders(headerkeys, headerkeyssize);
+ // Shared pages
+ webServer.on(F("/about"), webHandleAbout);
+ webServer.onNotFound(httpHandleNotFound);
+
+ #if HASP_USE_WIFI > 0
+ #if !defined(STM32F4xx)
+
+ #if HASP_USE_CONFIG > 0
+ if(WiFi.getMode() != WIFI_STA) {
+ Log.notice(TAG_HTTP, F("Wifi access point"));
+ webServer.on(F("/"), webHandleWifiConfig);
+ return;
+ }
+
+ #endif
+ #endif
+ #endif
+
+ webServer.on(F("/page/"), []() {
+ String pageid = webServer.arg(F("page"));
+ webServer.send(200, PSTR("text/plain"), "Page: '" + pageid + "'");
+ haspSetPage(pageid.toInt());
+ });
+
+ #if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
+ webServer.on(F("/list"), HTTP_GET, handleFileList);
+ // load editor
+ webServer.on(F("/edit"), HTTP_GET, []() {
+ if(!handleFileRead("/edit.htm")) {
+ char mimetype[16];
+ snprintf(mimetype, sizeof(mimetype), PSTR("text/plain"));
+ webServer.send_P(404, mimetype, PSTR("FileNotFound"));
+ }
+ });
+ webServer.on(F("/edit"), HTTP_PUT, handleFileCreate);
+ webServer.on(F("/edit"), HTTP_DELETE, handleFileDelete);
+ // first callback is called after the request has ended with all parsed arguments
+ // second callback handles file uploads at that location
+ webServer.on(
+ F("/edit"), HTTP_POST,
+ []() {
+ webServer.send(200, "text/plain", "");
+ Log.verbose(TAG_HTTP, F("Headers: %d"), webServer.headers());
+ },
+ handleFileUpload);
+ #endif
+
+ webServer.on(F("/"), webHandleRoot);
+ webServer.on(F("/info"), webHandleInfo);
+ webServer.on(F("/screenshot"), webHandleScreenshot);
+ webServer.on(F("/firmware"), webHandleFirmware);
+ webServer.on(F("/reboot"), httpHandleReboot);
+ webServer.onNotFound(httpHandleNotFound);
+
+ #if HASP_USE_CONFIG > 0
+ webServer.on(F("/config/hasp"), webHandleHaspConfig);
+ webServer.on(F("/config/http"), webHandleHttpConfig);
+ webServer.on(F("/config/gui"), webHandleGuiConfig);
+ webServer.on(F("/config/debug"), webHandleDebugConfig);
+ #if HASP_USE_MQTT > 0
+ webServer.on(F("/config/mqtt"), webHandleMqttConfig);
+ #endif
+ #if HASP_USE_WIFI > 0
+ webServer.on(F("/config/wifi"), webHandleWifiConfig);
+ #endif
+ #if HASP_USE_GPIO > 0
+ webServer.on(F("/config/gpio"), webHandleGpioConfig);
+ webServer.on(F("/config/gpio/options"), webHandleGpioOptions);
+ #endif
+ webServer.on(F("/saveConfig"), webHandleSaveConfig);
+ webServer.on(F("/resetConfig"), httpHandleResetConfig);
+ webServer.on(F("/config"), webHandleConfig);
+ #endif // HASP_USE_CONFIG
+
+ #if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
+ webServer.on(
+ F("/update"), HTTP_POST,
+ []() {
+ webServer.send(200, "text/plain", "");
+ Log.verbose(TAG_HTTP, F("Total size: %s"), webServer.hostHeader().c_str());
+ },
+ webHandleFirmwareUpdate);
+ webServer.on(F("/espfirmware"), httpHandleEspFirmware);
+ #endif
+
Log.trace(TAG_HTTP, F("Setup Complete"));
// webStart(); Wait for network connection
}
@@ -1886,6 +1877,7 @@ void httpEvery5Seconds()
}
////////////////////////////////////////////////////////////////////////////////////////////////////
+ #if HASP_USE_CONFIG > 0
bool httpGetConfig(const JsonObject & settings)
{
bool changed = false;
@@ -1932,6 +1924,7 @@ bool httpSetConfig(const JsonObject & settings)
return changed;
}
+ #endif // HASP_USE_CONFIG
size_t httpClientWrite(const uint8_t * buf, size_t size)
{
diff --git a/src/hasp_http.h b/src/hasp_http.h
index 1bf1dd66..8ef7213a 100644
--- a/src/hasp_http.h
+++ b/src/hasp_http.h
@@ -15,7 +15,9 @@ void httpStop(void);
size_t httpClientWrite(const uint8_t * buf, size_t size); // Screenshot Write Data
+#if HASP_USE_CONFIG > 0
bool httpGetConfig(const JsonObject & settings);
bool httpSetConfig(const JsonObject & settings);
+#endif // HASP_USE_CONFIG
#endif
\ No newline at end of file
diff --git a/src/hasp_mdns.cpp b/src/hasp_mdns.cpp
index 7a427f81..ebced002 100644
--- a/src/hasp_mdns.cpp
+++ b/src/hasp_mdns.cpp
@@ -83,6 +83,7 @@ void mdnsStop()
#endif
}
+ #if HASP_USE_CONFIG > 0
bool mdnsGetConfig(const JsonObject & settings)
{
bool changed = false;
@@ -108,5 +109,6 @@ bool mdnsSetConfig(const JsonObject & settings)
return changed;
}
+ #endif // HASP_USE_CONFIG
#endif // HASP_USE_MDNS
diff --git a/src/hasp_mdns.h b/src/hasp_mdns.h
index e8bde2f3..296d8cd6 100644
--- a/src/hasp_mdns.h
+++ b/src/hasp_mdns.h
@@ -13,7 +13,9 @@ void mdnsStart(void);
void mdnsStop(void);
/* ===== Read/Write Configuration ===== */
+#if HASP_USE_CONFIG > 0
bool mdnsGetConfig(const JsonObject & settings);
bool mdnsSetConfig(const JsonObject & settings);
+#endif
#endif
\ No newline at end of file
diff --git a/src/hasp_mqtt.cpp b/src/hasp_mqtt.cpp
index 3f047a2e..e6c93ed4 100644
--- a/src/hasp_mqtt.cpp
+++ b/src/hasp_mqtt.cpp
@@ -409,6 +409,7 @@ void mqttStop()
}
}
+#if HASP_USE_CONFIG > 0
bool mqttGetConfig(const JsonObject & settings)
{
bool changed = false;
@@ -493,5 +494,6 @@ bool mqttSetConfig(const JsonObject & settings)
return changed;
}
+#endif // HASP_USE_CONFIG
#endif // HASP_USE_MQTT
diff --git a/src/hasp_mqtt.h b/src/hasp_mqtt.h
index 9b8abb14..e63f0bba 100644
--- a/src/hasp_mqtt.h
+++ b/src/hasp_mqtt.h
@@ -17,8 +17,10 @@ void IRAM_ATTR mqtt_send_obj_attribute_str(uint8_t pageid, uint8_t btnid, const
bool IRAM_ATTR mqttIsConnected();
+#if HASP_USE_CONFIG > 0
bool mqttGetConfig(const JsonObject & settings);
bool mqttSetConfig(const JsonObject & settings);
+#endif
String mqttGetNodename(void);
diff --git a/src/hasp_oobe.cpp b/src/hasp_oobe.cpp
index a95f229b..6c70e349 100644
--- a/src/hasp_oobe.cpp
+++ b/src/hasp_oobe.cpp
@@ -1,6 +1,8 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
For full license information read the LICENSE file in the project folder */
+#if HASP_USE_CONFIG > 0
+
#include "hasp_conf.h"
#include "lvgl.h"
@@ -362,4 +364,5 @@ void oobeFakeSetup(const char *, const char *)
Log.trace(TAG_OOBE, F("Already calibrated"));
}
#endif
-}
\ No newline at end of file
+}
+#endif // HASP_USE_CONFIG
\ No newline at end of file
diff --git a/src/hasp_oobe.h b/src/hasp_oobe.h
index f4b0630e..8e3e7f4b 100644
--- a/src/hasp_oobe.h
+++ b/src/hasp_oobe.h
@@ -1,6 +1,10 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
For full license information read the LICENSE file in the project folder */
+#if HASP_USE_CONFIG > 0
+
void oobeSetAutoCalibrate(bool cal);
bool oobeSetup();
-void oobeFakeSetup(const char *, const char *); // for testing purposes only
\ No newline at end of file
+void oobeFakeSetup(const char *, const char *); // for testing purposes only
+
+#endif // HASP_USE_CONFIG
diff --git a/src/hasp_telnet.cpp b/src/hasp_telnet.cpp
index 564a51ca..462a78a0 100644
--- a/src/hasp_telnet.cpp
+++ b/src/hasp_telnet.cpp
@@ -313,6 +313,7 @@ void IRAM_ATTR telnetLoop()
#endif
}
+#if HASP_USE_CONFIG > 0
bool telnetGetConfig(const JsonObject & settings)
{
bool changed = false;
@@ -345,5 +346,6 @@ bool telnetSetConfig(const JsonObject & settings)
return changed;
}
+#endif // HASP_USE_CONFIG
#endif
\ No newline at end of file
diff --git a/src/hasp_telnet.h b/src/hasp_telnet.h
index a06b5f13..143e5059 100644
--- a/src/hasp_telnet.h
+++ b/src/hasp_telnet.h
@@ -22,9 +22,10 @@ void telnetStop(void);
/* ===== Getter and Setter Functions ===== */
/* ===== Read/Write Configuration ===== */
-
+#if HASP_USE_CONFIG > 0
bool telnetSetConfig(const JsonObject & settings);
bool telnetGetConfig(const JsonObject & settings);
+#endif
#define TELNET_UNAUTHENTICATED 0
#define TELNET_USERNAME_OK 10
diff --git a/src/hasp_wifi.cpp b/src/hasp_wifi.cpp
index d6f5b1aa..e0f2d2d7 100644
--- a/src/hasp_wifi.cpp
+++ b/src/hasp_wifi.cpp
@@ -508,7 +508,7 @@ void wifi_get_statusupdate(char * buffer, size_t len)
}
/* ============ Confiuration =============================================================== */
-
+#if HASP_USE_CONFIG > 0
bool wifiGetConfig(const JsonObject & settings)
{
bool changed = false;
@@ -549,5 +549,6 @@ bool wifiSetConfig(const JsonObject & settings)
return changed;
}
+#endif // HASP_USE_CONFIG
#endif
\ No newline at end of file
diff --git a/src/hasp_wifi.h b/src/hasp_wifi.h
index 91c8e70a..5364150f 100644
--- a/src/hasp_wifi.h
+++ b/src/hasp_wifi.h
@@ -15,7 +15,9 @@ void wifiStop(void);
bool wifiValidateSsid(const char * ssid, const char * pass);
void wifi_get_statusupdate(char * buffer, size_t len);
+#if HASP_USE_CONFIG > 0
bool wifiGetConfig(const JsonObject & settings);
bool wifiSetConfig(const JsonObject & settings);
+#endif
#endif
\ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index bf451f99..6cf9ff5d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -36,7 +36,9 @@ void setup()
/****************************
* Read & Apply User Configuration
***************************/
+#if HASP_USE_CONFIG > 0
configSetup(); // also runs debugPreSetup(), debugSetup() and debugStart()
+#endif
dispatchSetup();
guiSetup();
@@ -57,7 +59,10 @@ void setup()
networkSetup();
#endif
- if(!oobeSetup()) {
+#if HASP_USE_CONFIG > 0
+ if(!oobeSetup())
+#endif
+ {
haspSetup();
}
From c633978183323c51dadd03d9926047113feb954d Mon Sep 17 00:00:00 2001
From: fvanroie