From 65fc1cf4a6419ee6a28a2161f8dee47256f651d8 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Fri, 18 Sep 2020 18:29:16 -0700 Subject: [PATCH] Moved handleDNSResponse into handleWebResponse and used the autoformatter --- src/main.cpp | 1 - src/meshwifi/meshhttp.cpp | 57 +++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 65881b9e1..b0d133f22 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -423,7 +423,6 @@ void loop() // TODO: This should go into a thread handled by FreeRTOS. handleWebResponse(); - handleDNSResponse(); delay(msecstosleep); } diff --git a/src/meshwifi/meshhttp.cpp b/src/meshwifi/meshhttp.cpp index 09219602e..c2f6ed342 100644 --- a/src/meshwifi/meshhttp.cpp +++ b/src/meshwifi/meshhttp.cpp @@ -1,40 +1,41 @@ -#include -#include +#include "meshwifi/meshhttp.h" +#include "NodeDB.h" #include "configuration.h" #include "main.h" -#include "NodeDB.h" #include "meshwifi/meshwifi.h" -#include "meshwifi/meshhttp.h" - +#include +#include WebServer webserver(80); String something = ""; String sender = ""; - -void handleWebResponse() { +void handleWebResponse() +{ if (isWifiAvailable() == 0) { return; } + // We're going to handle the DNS responder here so it + // will be ignored by the NRF boards. + handleDNSResponse(); + webserver.handleClient(); } -void initWebServer() { +void initWebServer() +{ webserver.onNotFound(handleNotFound); - //webserver.on("/", handleJSONChatHistory); - //webserver.on("/json/chat/history", handleJSONChatHistory); + // webserver.on("/", handleJSONChatHistory); + // webserver.on("/json/chat/history", handleJSONChatHistory); webserver.on("/hotspot-detect.html", handleHotspot); - webserver.on("/", []() { - webserver.send(200, "text/plain", "Everything is awesome!"); - }); + webserver.on("/", []() { webserver.send(200, "text/plain", "Everything is awesome!"); }); webserver.begin(); - } - -void handleJSONChatHistory() { +void handleJSONChatHistory() +{ String out = ""; out += "{\n"; @@ -46,18 +47,16 @@ void handleJSONChatHistory() { out += "\"" + something + "\""; out += "]\n"; - - out += "\n"; out += " }\n"; out += "}\n"; - webserver.send ( 200, "application/json", out ); + webserver.send(200, "application/json", out); return; - } -void handleNotFound() { +void handleNotFound() +{ String message = "File Not Found\n\n"; message += "URI: "; message += webserver.uri(); @@ -73,33 +72,33 @@ void handleNotFound() { Serial.println(message); webserver.send(404, "text/plain", message); /* - */ + */ } /* This supports the Apple Captive Network Assistant (CNA) Portal */ -void handleHotspot() { +void handleHotspot() +{ DEBUG_MSG("Hotspot Request\n"); String out = ""; - //out += "Success\n"; + // out += "Success\n"; out += "\n"; - webserver.send ( 200, "text/html", out ); + webserver.send(200, "text/html", out); return; } -void notifyWebUI() { +void notifyWebUI() +{ DEBUG_MSG("************ Got a message! ************\n"); MeshPacket &mp = devicestate.rx_text_message; NodeInfo *node = nodeDB.getNode(mp.from); sender = (node && node->has_user) ? node->user.long_name : "???"; - + static char tempBuf[256]; // mesh.options says this is MeshPacket.encrypted max_size assert(mp.decoded.which_payload == SubPacket_data_tag); snprintf(tempBuf, sizeof(tempBuf), "%s", mp.decoded.data.payload.bytes); - something = tempBuf; - } \ No newline at end of file