From 642440414c52e44f25126dbc14ef1ed86b8de5af Mon Sep 17 00:00:00 2001
From: fvanroie
Date: Sat, 1 Feb 2020 20:05:44 +0100
Subject: [PATCH] Added GUI calibrate to config
---
src/hasp_http.cpp | 84 ++++++++++++++++++++++++++++++++---------------
1 file changed, 57 insertions(+), 27 deletions(-)
diff --git a/src/hasp_http.cpp b/src/hasp_http.cpp
index bfd23808..fc77fb3e 100644
--- a/src/hasp_http.cpp
+++ b/src/hasp_http.cpp
@@ -3,11 +3,13 @@
#include "ArduinoJson.h"
#include "hasp_log.h"
+#include "hasp_gui.h"
#include "hasp_debug.h"
#include "hasp_http.h"
#include "hasp_mqtt.h"
#include "hasp_wifi.h"
#include "hasp_config.h"
+#include "hasp_dispatch.h"
#include "hasp.h"
#if defined(ARDUINO_ARCH_ESP32)
@@ -248,13 +250,9 @@ void httpHandleReboot()
webSendPage(nodename, httpMessage.length(), true);
webServer.sendContent(httpMessage); // len
webServer.sendContent_P(HTTP_END); // 20
- delay(500);
- debugPrintln(PSTR("HTTP: Reboot device"));
- // haspProcessAttribute(F("p[0].b[1].txt"), F("\"Rebooting...\""));
-
- delay(500);
- haspReset(true);
+ delay(200);
+ dispatchCommand(F("reboot"));
}
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -677,7 +675,7 @@ void webHandleConfig()
F("
");
httpMessage +=
- F("");
+ F("");
httpMessage +=
F("");
@@ -741,6 +739,35 @@ void webHandleMqttConfig()
}
#endif
+////////////////////////////////////////////////////////////////////////////////////////////////////
+void webHandleGuiConfig()
+{ // http://plate01/config/wifi
+ if(!httpIsAuthenticated(F("/config/gui"))) return;
+
+ DynamicJsonDocument settings(256);
+ // guiGetConfig(settings.to());
+
+ char buffer[64];
+ String nodename = haspGetNodename();
+ String httpMessage((char *)0);
+ httpMessage.reserve(1024);
+
+ httpMessage += String(F("");
+
+ httpMessage += PSTR("");
+
+ httpMessage +=
+ PSTR("");
+
+ webSendPage(nodename, httpMessage.length(), false);
+ webServer.sendContent(httpMessage); // len
+ webServer.sendContent_P(HTTP_END); // 20
+
+ if(webServer.hasArg(F("action"))) dispatchCommand(webServer.arg(F("action")));
+}
+
////////////////////////////////////////////////////////////////////////////////////////////////////
#if LV_USE_HASP_WIFI > 0
void webHandleWifiConfig()
@@ -826,12 +853,12 @@ void webHandleHaspConfig()
String httpMessage((char *)0);
httpMessage.reserve(1024);
- httpMessage += String(F("");
- httpMessage += String(F("");
@@ -916,7 +945,7 @@ void httpHandleNotFound()
debugPrintln(String(F("HTTP: Sending 404 to client connected from: ")) + webServer.client().remoteIP().toString());
String httpMessage((char *)0);
- httpMessage.reserve(128);
+ httpMessage.reserve(512);
httpMessage += F("File Not Found\n\nURI: ");
httpMessage += webServer.uri();
httpMessage += F("\nMethod: ");
@@ -1007,7 +1036,7 @@ void httpHandleResetConfig()
if(resetConfirmed) {
delay(250);
// configClearSaved();
- haspReset(false); // Do not save the current config
+ haspReboot(false); // Do not save the current config
}
}
@@ -1048,6 +1077,7 @@ void httpSetup(const JsonObject & settings)
webServer.on(F("/config"), webHandleConfig);
webServer.on(F("/config/hasp"), webHandleHaspConfig);
webServer.on(F("/config/http"), webHandleHttpConfig);
+ webServer.on(F("/config/gui"), webHandleGuiConfig);
#if LV_USE_HASP_MQTT > 0
webServer.on(F("/config/mqtt"), webHandleMqttConfig);
#endif