From 84f5685ca73b7ad2371abb99c86a49453e5615a9 Mon Sep 17 00:00:00 2001
From: fvanroie <15969459+fvanroie@users.noreply.github.com>
Date: Fri, 2 Jul 2021 16:00:51 +0200
Subject: [PATCH] Add HASP_USE_HTTP_ASYNC
---
include/hasp_conf.h | 8 +
src/main_arduino.cpp | 6 +-
src/sys/net/hasp_network.cpp | 4 +-
src/sys/svc/hasp_http_async.cpp | 2419 +++++++++++++++++++++++++++++++
src/sys/svc/hasp_telnet.cpp | 26 +-
5 files changed, 2448 insertions(+), 15 deletions(-)
create mode 100644 src/sys/svc/hasp_http_async.cpp
diff --git a/include/hasp_conf.h b/include/hasp_conf.h
index 76a30be1..eb609306 100644
--- a/include/hasp_conf.h
+++ b/include/hasp_conf.h
@@ -58,6 +58,10 @@
#define HASP_USE_HTTP (HASP_HAS_NETWORK)
#endif
+#ifndef HASP_USE_HTTP_ASYNC
+#define HASP_USE_HTTP_ASYNC 0 //(HASP_HAS_NETWORK)
+#endif
+
#ifndef HASP_USE_MDNS
#define HASP_USE_MDNS (HASP_HAS_NETWORK)
#endif
@@ -224,6 +228,10 @@ static WiFiSpiClass WiFi;
#include "sys/svc/hasp_http.h"
#endif
+#if HASP_USE_HTTP_ASYNC > 0
+#include "sys/svc/hasp_http.h"
+#endif
+
#if HASP_USE_CONSOLE > 0
#include "sys/svc/hasp_console.h"
#endif
diff --git a/src/main_arduino.cpp b/src/main_arduino.cpp
index 0047a7f2..567bf9c0 100644
--- a/src/main_arduino.cpp
+++ b/src/main_arduino.cpp
@@ -90,7 +90,7 @@ void setup()
otaSetup();
#endif
-#if HASP_USE_HTTP > 0
+#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
httpSetup();
#endif
@@ -160,8 +160,8 @@ IRAM_ATTR void loop()
break;
case 2:
-#if HASP_USE_HTTP > 0
- // httpEvery5Seconds();
+#if HASP_USE_HTTP_ASYNC > 0
+ httpEvery5Seconds();
#endif
break;
diff --git a/src/sys/net/hasp_network.cpp b/src/sys/net/hasp_network.cpp
index be0915db..3ee09239 100644
--- a/src/sys/net/hasp_network.cpp
+++ b/src/sys/net/hasp_network.cpp
@@ -31,7 +31,7 @@ void networkStart(void)
haspReconnect();
debugStartSyslog();
// mqttStart();
-#if HASP_USE_HTTP > 0
+#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
httpStart();
#endif
#if HASP_USE_MDNS > 0
@@ -45,7 +45,7 @@ void networkStop(void)
debugStopSyslog();
// mqttStop();
-#if HASP_USE_HTTP > 0
+#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
httpStop();
#endif
mdnsStop();
diff --git a/src/sys/svc/hasp_http_async.cpp b/src/sys/svc/hasp_http_async.cpp
new file mode 100644
index 00000000..a3385d0e
--- /dev/null
+++ b/src/sys/svc/hasp_http_async.cpp
@@ -0,0 +1,2419 @@
+/* MIT License - Copyright (c) 2019-2021 Francis Van Roie
+ For full license information read the LICENSE file in the project folder */
+
+//#include "webServer.h"
+#include "hasplib.h"
+#include "ArduinoLog.h"
+
+#if defined(ARDUINO_ARCH_ESP32)
+#include "Update.h"
+#endif
+
+#include "hasp_conf.h"
+#include "dev/device.h"
+#include "hal/hasp_hal.h"
+
+#include "hasp_gui.h"
+#include "hasp_debug.h"
+#include "hasp_config.h"
+
+#if HASP_USE_HTTP_ASYNC > 0
+#include "sys/net/hasp_network.h"
+
+/* clang-format off */
+//default theme
+#ifndef D_HTTP_COLOR_TEXT
+#define D_HTTP_COLOR_TEXT "#000" // Global text color - Black
+#endif
+#ifndef D_HTTP_COLOR_BACKGROUND
+#define D_HTTP_COLOR_BACKGROUND "#fff" // Global background color - White
+#endif
+#ifndef D_HTTP_COLOR_INPUT_TEXT
+#define D_HTTP_COLOR_INPUT_TEXT "#000" // Input text color - Black
+#endif
+#ifndef D_HTTP_COLOR_INPUT
+#define D_HTTP_COLOR_INPUT "#fff" // Input background color - White
+#endif
+#ifndef D_HTTP_COLOR_INPUT_WARNING
+#define D_HTTP_COLOR_INPUT_WARNING "#f00" // Input warning border color - Red
+#endif
+#ifndef D_HTTP_COLOR_BUTTON_TEXT
+#define D_HTTP_COLOR_BUTTON_TEXT "#fff" // Button text color - White
+#endif
+#ifndef D_HTTP_COLOR_BUTTON
+#define D_HTTP_COLOR_BUTTON "#1fa3ec" // Button color - Vivid blue
+#endif
+#ifndef D_HTTP_COLOR_BUTTON_RESET
+#define D_HTTP_COLOR_BUTTON_RESET "#f00" // Restart/Reset button color - red
+#endif
+/* clang-format on */
+
+#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
+File fsUploadFile;
+#endif
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+bool webServerStarted = false;
+
+// bool httpEnable = true;
+// uint16_t httpPort = 80;
+// char httpUser[32] = "";
+// char httpPassword[32] = "";
+hasp_http_config_t http_config;
+
+#define HTTP_PAGE_SIZE (6 * 256)
+
+#if defined(STM32F4xx) && HASP_USE_ETHERNET > 0
+#include
+EthernetWebServer webServer(80);
+#endif
+
+#if defined(STM32F4xx) && HASP_USE_WIFI > 0
+#include
+// #include
+EthernetWebServer webServer(80);
+#endif
+
+#if defined(ARDUINO_ARCH_ESP8266)
+#include "StringStream.h"
+#include
+#include
+#include
+#include
+AsyncWebServer webServer(80);
+#endif
+
+#if defined(ARDUINO_ARCH_ESP32)
+#include "AsyncTCP.h"
+#include "ESPAsyncWebServer.h"
+#include
+AsyncWebServer webServer(80);
+extern const uint8_t EDIT_HTM_GZ_START[] asm("_binary_data_edit_htm_gz_start");
+extern const uint8_t EDIT_HTM_GZ_END[] asm("_binary_data_edit_htm_gz_end");
+#endif // ESP32
+
+AsyncWebSocket ws("/ws"); // access at ws://[esp ip]/ws
+
+// HTTPUpload* upload;
+
+static const char HTTP_MENU_BUTTON[] PROGMEM =
+ "
";
+
+const char MAIN_MENU_BUTTON[] PROGMEM =
+ "";
+const char HTTP_END[] PROGMEM = "
";
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+// URL for auto-update "version.json"
+// const char UPDATE_URL[] PROGMEM = "http://haswitchplate.com/update/version.json";
+// // Default link to compiled Arduino firmware image
+// String espFirmwareUrl = "http://haswitchplate.com/update/HASwitchPlate.ino.d1_mini.bin";
+// // Default link to compiled Nextion firmware images
+// String lcdFirmwareUrl = "http://haswitchplate.com/update/HASwitchPlate.tft";
+
+// #if HASP_USE_MQTT > 0
+// extern char mqttNodeName[16];
+// #else
+// char mqttNodeName[3] = "na";
+// #endif
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+String getOption(int value, String label, bool selected)
+{
+ char buffer[128];
+ snprintf_P(buffer, sizeof(buffer), PSTR("
%s "), value,
+ (selected ? PSTR(" selected") : ""), label.c_str());
+ return buffer;
+}
+
+String getOption(String value, String label, bool selected)
+{
+ char buffer[128];
+ snprintf_P(buffer, sizeof(buffer), PSTR("
%s "), value.c_str(),
+ (selected ? PSTR(" selected") : ""), label.c_str());
+ return buffer;
+}
+
+static void add_gpio_select_option(String& str, uint8_t gpio, uint8_t bcklpin)
+{
+ char buffer[10];
+ snprintf_P(buffer, sizeof(buffer), PSTR("GPIO %d"), gpio);
+ str += getOption(gpio, buffer, bcklpin == gpio);
+}
+
+static void add_button(String& str, const __FlashStringHelper* label, const __FlashStringHelper* extra)
+{
+ str += F("
");
+ str += label;
+ str += F(" ");
+}
+
+static void close_form(String& str)
+{
+ str += F("");
+}
+
+static void add_form_button(String& str, const __FlashStringHelper* label, const __FlashStringHelper* action,
+ const __FlashStringHelper* extra)
+{
+ str += F("
");
+
+ // httpMessage += F("
");
+ // httpMessage += F("Replace Filesystem Image ");
+
+ httpMessage += F("
");
+ httpMessage += F("Update ESP from URL ");
+ httpMessage += F("Update ESP from URL ");
+
+ httpMessage += FPSTR(MAIN_MENU_BUTTON);
+
+ webSendPage(request, haspDevice.get_hostname(), httpMessage.c_str(), false);
+ // //webSendFooter(reponse);(httpMessage);
+ }
+ // httpMessage.clear();
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+void httpHandleEspFirmware(AsyncWebServerRequest* request)
+{ // http://plate01/espfirmware
+ char url[4];
+ memcpy_P(url, PSTR("url"), 4);
+
+ if(!httpIsAuthenticated(request, F("espfirmware"))) return;
+
+ {
+ String httpMessage((char*)0);
+ httpMessage.reserve(HTTP_PAGE_SIZE);
+ httpMessage += F("
");
+ httpMessage += haspDevice.get_hostname();
+ httpMessage += F(" ");
+
+ httpMessage += F("
ESP update
Updating ESP firmware from: ");
+ httpMessage += request->arg(url);
+
+ webSendPage(request, haspDevice.get_hostname(), httpMessage.c_str(), true);
+ // //webSendFooter(reponse);(httpMessage);
+ // httpMessage.clear();
+ }
+
+ LOG_TRACE(TAG_HTTP, F("Updating ESP firmware from: %s"), request->arg(url).c_str());
+ dispatch_web_update(NULL, request->arg(url).c_str());
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+#if HASP_USE_CONFIG > 0
+void webHandleSaveConfig(AsyncWebServerRequest* request)
+{
+ if(!httpIsAuthenticated(request, F("saveConfig"))) return;
+ configWrite();
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+void httpHandleResetConfig(AsyncWebServerRequest* request)
+{ // http://plate01/resetConfig
+ if(!httpIsAuthenticated(request, F("resetConfig"))) return;
+
+ bool resetConfirmed = request->arg(F("confirm")) == F("yes");
+
+ {
+ String httpMessage((char*)0);
+ httpMessage.reserve(HTTP_PAGE_SIZE);
+ httpMessage += F("
");
+ httpMessage += haspDevice.get_hostname();
+ httpMessage += F(" ");
+
+ if(resetConfirmed) { // User has confirmed, so reset everything
+ bool formatted = configClearEeprom();
+ if(formatted) {
+ httpMessage += F("
Resetting all saved settings and restarting device ");
+ } else {
+ httpMessage += F("
Failed to format the internal flash partition ");
+ resetConfirmed = false;
+ }
+ } else {
+ httpMessage +=
+ F("
Warning This process will reset all settings to the default values. The internal flash "
+ "will be erased and the device is restarted. You may need to connect to the WiFi AP displayed on "
+ "the "
+ "panel to re-configure the device before accessing it again. ALL FILES WILL BE LOST! "
+ "
");
+
+ add_button(httpMessage, F(D_HTTP_ERASE_DEVICE), F("name='confirm' value='yes'"));
+ close_form(httpMessage);
+
+ add_form_button(httpMessage, F(D_BACK_ICON D_HTTP_CONFIGURATION), F("/config"), F(""));
+ }
+
+ webSendPage(request, haspDevice.get_hostname(), httpMessage.c_str(), resetConfirmed);
+ // //webSendFooter(reponse);(httpMessage);
+ }
+ // httpMessage.clear();
+
+ if(resetConfirmed) {
+ delay(250);
+ // configClearSaved();
+ dispatch_reboot(false); // Do not save the current config
+ }
+}
+#endif // HASP_USE_CONFIG
+
+void httpStart()
+{
+ webServer.begin();
+ webServerStarted = true;
+#if HASP_USE_WIFI > 0
+#if defined(STM32F4xx)
+ IPAddress ip;
+ ip = WiFi.localIP();
+ LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
+#else
+ LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%s"),
+ (WiFi.getMode() != WIFI_STA ? WiFi.softAPIP().toString().c_str() : WiFi.localIP().toString().c_str()));
+#endif
+#else
+ IPAddress ip;
+#if defined(ARDUINO_ARCH_ESP32)
+ ip = ETH.localIP();
+#else
+ ip = Ethernet.localIP();
+#endif
+ LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED " @ http://%d.%d.%d.%d"), ip[0], ip[1], ip[2], ip[3]);
+#endif
+}
+
+void httpStop()
+{
+ webServer.end();
+ webServerStarted = false;
+ LOG_WARNING(TAG_HTTP, F(D_SERVICE_STOPPED));
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+void httpSetup()
+{
+ // httpSetConfig(settings);
+
+ // 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(("/about"), webHandleAbout);
+ webServer.on(("/css"), [](AsyncWebServerRequest* request) { request->send_P(200, PSTR("text/css"), HTTP_CSS); });
+ webServer.onNotFound(httpHandleNotFound);
+
+#if HASP_USE_WIFI > 0
+
+
+#if !defined(STM32F4xx)
+
+#if HASP_USE_CONFIG > 0
+ if(WiFi.getMode() != WIFI_STA) {
+ webServer.on(("/"), webHandleWifiConfig);
+ LOG_TRACE(TAG_HTTP, F("Wifi access point"));
+ return;
+ }
+
+#endif // HASP_USE_CONFIG
+#endif // !STM32F4xx
+#endif // HASP_USE_WIFI
+
+ // The following endpoints are only needed in STA mode
+ webServer.on(("/page/"), [](AsyncWebServerRequest* request) {
+ String pageid = request->arg(F("page"));
+ request->send(200, PSTR("text/plain"), "Page: '" + pageid + "'");
+ dispatch_set_page(pageid.toInt(), LV_SCR_LOAD_ANIM_NONE);
+ });
+
+#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
+ webServer.on(("/list"), HTTP_GET, handleFileList);
+ // load editor
+ webServer.on(("/edit"), HTTP_GET, [](AsyncWebServerRequest* request) {
+ if(handleFileRead(request, "/edit.htm") != 200) {
+ char mimetype[16];
+ snprintf_P(mimetype, sizeof(mimetype), PSTR("text/plain"));
+ request->send_P(404, mimetype, PSTR("FileNotFound"));
+ }
+ });
+ webServer.on(("/edit"), HTTP_PUT, handleFileCreate);
+ webServer.on(("/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(("/edit"), HTTP_POST,
+ [](AsyncWebServerRequest* request) {
+ request->send(200);
+ LOG_VERBOSE(TAG_HTTP, F("Headers: %d"), request->headers());
+ },
+ handleFileUpload);
+#endif
+
+ webServer.on(("/"), webHandleRoot);
+ webServer.on(("/info"), webHandleInfoJson);
+ // webServer.on(F("/info"), webHandleInfo);
+ webServer.on(("/screenshot"), webHandleScreenshot);
+ webServer.on(("/firmware"), webHandleFirmware);
+ webServer.on(("/reboot"), httpHandleReboot);
+
+#if HASP_USE_CONFIG > 0
+ webServer.on(("/config/hasp"), webHandleHaspConfig);
+ webServer.on(("/config/http"), webHandleHttpConfig);
+ webServer.on(("/config/gui"), webHandleGuiConfig);
+ webServer.on(("/config/debug"), webHandleDebugConfig);
+#if HASP_USE_MQTT > 0
+ webServer.on(("/config/mqtt"), webHandleMqttConfig);
+#endif
+#if HASP_USE_WIFI > 0
+ webServer.on(("/config/wifi"), webHandleWifiConfig);
+#endif
+#if HASP_USE_GPIO > 0
+ webServer.on(("/config/gpio/options"), webHandleGpioOutput);
+ webServer.on(("/config/gpio/input"), webHandleGpioInput);
+ webServer.on(("/config/gpio"), webHandleGpioConfig);
+#endif
+ webServer.on(("/saveConfig"), webHandleSaveConfig);
+ webServer.on(("/resetConfig"), httpHandleResetConfig);
+#endif // HASP_USE_CONFIG
+
+#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
+ webServer.on(("/update"), HTTP_POST, [](AsyncWebServerRequest* request) { request->send(200); },
+ webHandleFirmwareUpload);
+ webServer.on(("/espfirmware"), httpHandleEspFirmware);
+#endif
+
+ // These two endpoints are needed in STA and AP mode
+ webServer.on(("/config"), webHandleConfig);
+
+ LOG_INFO(TAG_HTTP, F(D_SERVICE_STARTED));
+ // webStart(); Wait for network connection
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+void httpReconnect()
+{
+ if(!http_config.enable) return;
+
+ if(webServerStarted) {
+ httpStop();
+ } else
+#if HASP_USE_WIFI > 0 && !defined(STM32F4xx)
+ if(WiFi.status() == WL_CONNECTED || WiFi.getMode() != WIFI_STA)
+#endif
+ {
+ httpStart();
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+IRAM_ATTR void httpLoop(void)
+{}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+void httpEvery5Seconds()
+{}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+void httpEverySecond()
+{
+ ws.cleanupClients();
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+#if HASP_USE_CONFIG > 0
+bool httpGetConfig(const JsonObject& settings)
+{
+ bool changed = false;
+
+ settings[FPSTR(FP_CONFIG_ENABLE)] = http_config.enable;
+
+ if(http_config.port != settings[FPSTR(FP_CONFIG_PORT)].as()) changed = true;
+ settings[FPSTR(FP_CONFIG_PORT)] = http_config.port;
+
+ if(strcmp(http_config.user, settings[FPSTR(FP_CONFIG_USER)].as().c_str()) != 0) changed = true;
+ settings[FPSTR(FP_CONFIG_USER)] = http_config.user;
+
+ if(strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)].as().c_str()) != 0) changed = true;
+ settings[FPSTR(FP_CONFIG_PASS)] = http_config.password;
+
+ if(changed) configOutput(settings, TAG_HTTP);
+ return changed;
+}
+
+/** Set HTTP Configuration.
+ *
+ * Read the settings from json and sets the application variables.
+ *
+ * @note: data pixel should be formated to uint32_t RGBA. Imagemagick requirements.
+ *
+ * @param[in] settings JsonObject with the config settings.
+ **/
+bool httpSetConfig(const JsonObject& settings)
+{
+ configOutput(settings, TAG_HTTP);
+ bool changed = false;
+
+ changed |= configSet(http_config.port, settings[FPSTR(FP_CONFIG_PORT)], F("httpPort"));
+
+ if(!settings[FPSTR(FP_CONFIG_USER)].isNull()) {
+ changed |= strcmp(http_config.user, settings[FPSTR(FP_CONFIG_USER)]) != 0;
+ strncpy(http_config.user, settings[FPSTR(FP_CONFIG_USER)], sizeof(http_config.user));
+ }
+
+ if(!settings[FPSTR(FP_CONFIG_PASS)].isNull()) {
+ changed |= strcmp(http_config.password, settings[FPSTR(FP_CONFIG_PASS)]) != 0;
+ strncpy(http_config.password, settings[FPSTR(FP_CONFIG_PASS)], sizeof(http_config.password));
+ }
+
+ return changed;
+}
+#endif // HASP_USE_CONFIG
+
+size_t httpClientWrite(const uint8_t* buf, size_t size)
+{
+ /***** Sending 16Kb at once freezes on STM32 EthernetClient *****/
+ size_t bytes_sent = 0;
+ while(bytes_sent < size) {
+ // if(!webServer.client()) return bytes_sent;
+ // if(size - bytes_sent >= 2048) {
+ // bytes_sent += webServer.client().write(buf + bytes_sent, 2048);
+ // } else {
+ // bytes_sent += webServer.client().write(buf + bytes_sent, size - bytes_sent);
+ // }
+ // // Serial.println(bytes_sent);
+
+ // // stm32_eth_scheduler(); // already in write
+ // // webServer.client().flush();
+ delay(1); // Fixes the freeze
+ }
+ return bytes_sent;
+}
+
+#endif
diff --git a/src/sys/svc/hasp_telnet.cpp b/src/sys/svc/hasp_telnet.cpp
index 424ac4d2..0eb58d34 100644
--- a/src/sys/svc/hasp_telnet.cpp
+++ b/src/sys/svc/hasp_telnet.cpp
@@ -29,7 +29,7 @@ EthernetClient telnetClient;
static EthernetServer telnetServer(23);
#endif
-#if HASP_USE_HTTP > 0
+#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
extern hasp_http_config_t http_config;
#endif
@@ -48,9 +48,10 @@ void telnet_update_prompt()
bufferedTelnetClient.flush();
}
-void telnetStop(void)
+static void telnetClientDisconnect()
{
- LOG_TRACE(TAG_TELN, F(D_TELNET_CLOSING_CONNECTION), telnetClient.remoteIP().toString().c_str());
+ if(telnetClient.connected())
+ LOG_TRACE(TAG_TELN, F(D_TELNET_CLOSING_CONNECTION), telnetClient.remoteIP().toString().c_str());
Log.unregisterOutput(1); // telnetClient
telnetClient.stop();
@@ -60,9 +61,11 @@ void telnetStop(void)
telnetConsole = NULL;
}
-static inline void telnetClientDisconnect()
+void telnetStop(void)
{
- telnetStop();
+ telnetClientDisconnect();
+ delete telnetServer;
+ telnetServer = NULL;
}
void telnetClientLogon()
@@ -99,7 +102,7 @@ void telnetAcceptClient()
// telnetClient.print((char)0xFD);
// telnetClient.print((char)0x1B);
-#if HASP_USE_HTTP > 0
+#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
if(strlen(http_config.user) != 0 || strlen(http_config.password) != 0) {
telnetClient.println(F("\r\n" D_USERNAME " "));
telnetLoginState = TELNET_UNAUTHENTICATED;
@@ -119,7 +122,7 @@ static inline void telnetProcessLine()
switch(telnetLoginState) {
case TELNET_UNAUTHENTICATED: {
telnetClient.printf(PSTR(D_PASSWORD" %c%c%c"), 0xFF, 0xFB, 0x01); // Hide characters
-#if HASP_USE_HTTP > 0
+#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
telnetLoginState = strcmp(telnetInputBuffer, http_config.user) == 0 ? TELNET_USERNAME_OK : TELNET_USERNAME_NOK;
break;
}
@@ -205,7 +208,7 @@ static void telnetProcessLine(const char* input)
snprintf_P(buffer, sizeof(buffer), PSTR(D_PASSWORD " %c%c%c\n"), 0xFF, 0xFB,
0x01); // Hide characters
telnetClient.print(buffer);
-#if HASP_USE_HTTP > 0
+#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
telnetLoginState = strcmp(input, http_config.user) == 0 ? TELNET_USERNAME_OK : TELNET_USERNAME_NOK;
break;
}
@@ -235,7 +238,7 @@ static void telnetProcessLine(const char* input)
strcasecmp_P(input, PSTR("bye")) == 0) {
telnetClientDisconnect();
} else if(strcasecmp_P(input, PSTR("logoff")) == 0) {
-#if HASP_USE_HTTP > 0
+#if HASP_USE_HTTP > 0 || HASP_USE_HTTP_ASYNC > 0
if(strcmp(input, http_config.password) == 0) {
telnetClient.println(F("\r\n" D_USERNAME " "));
telnetLoginState = TELNET_UNAUTHENTICATED;
@@ -250,7 +253,7 @@ static void telnetProcessLine(const char* input)
}
}
-void telnetSetup()
+void telnetStart()
{
// telnetSetConfig(settings);
@@ -283,6 +286,9 @@ void telnetSetup()
}
}
+void telnetSetup()
+{telnetStart();}
+
IRAM_ATTR void telnetLoop()
{
// Basic telnet client handling code from: https://gist.github.com/tablatronix/4793677ca748f5f584c95ec4a2b10303