Merge pull request #411 from mc-hamster/master

Moved handleDNSResponse from main into handleWebResponse and used the auto format
This commit is contained in:
Jm Casler 2020-09-18 18:36:40 -07:00 committed by GitHub
commit 0929b86d62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 30 deletions

View File

@ -423,7 +423,6 @@ void loop()
// TODO: This should go into a thread handled by FreeRTOS. // TODO: This should go into a thread handled by FreeRTOS.
handleWebResponse(); handleWebResponse();
handleDNSResponse();
delay(msecstosleep); delay(msecstosleep);
} }

View File

@ -1,40 +1,41 @@
#include <WebServer.h> #include "meshwifi/meshhttp.h"
#include <WiFi.h> #include "NodeDB.h"
#include "configuration.h" #include "configuration.h"
#include "main.h" #include "main.h"
#include "NodeDB.h"
#include "meshwifi/meshwifi.h" #include "meshwifi/meshwifi.h"
#include "meshwifi/meshhttp.h" #include <WebServer.h>
#include <WiFi.h>
WebServer webserver(80); WebServer webserver(80);
String something = ""; String something = "";
String sender = ""; String sender = "";
void handleWebResponse()
void handleWebResponse() { {
if (isWifiAvailable() == 0) { if (isWifiAvailable() == 0) {
return; return;
} }
// We're going to handle the DNS responder here so it
// will be ignored by the NRF boards.
handleDNSResponse();
webserver.handleClient(); webserver.handleClient();
} }
void initWebServer() { void initWebServer()
{
webserver.onNotFound(handleNotFound); webserver.onNotFound(handleNotFound);
// webserver.on("/", handleJSONChatHistory); // webserver.on("/", handleJSONChatHistory);
// webserver.on("/json/chat/history", handleJSONChatHistory); // webserver.on("/json/chat/history", handleJSONChatHistory);
webserver.on("/hotspot-detect.html", handleHotspot); webserver.on("/hotspot-detect.html", handleHotspot);
webserver.on("/", []() { webserver.on("/", []() { webserver.send(200, "text/plain", "Everything is awesome!"); });
webserver.send(200, "text/plain", "Everything is awesome!");
});
webserver.begin(); webserver.begin();
} }
void handleJSONChatHistory()
void handleJSONChatHistory() { {
String out = ""; String out = "";
out += "{\n"; out += "{\n";
@ -46,18 +47,16 @@ void handleJSONChatHistory() {
out += "\"" + something + "\""; out += "\"" + something + "\"";
out += "]\n"; out += "]\n";
out += "\n"; out += "\n";
out += " }\n"; out += " }\n";
out += "}\n"; out += "}\n";
webserver.send(200, "application/json", out); webserver.send(200, "application/json", out);
return; return;
} }
void handleNotFound() { void handleNotFound()
{
String message = "File Not Found\n\n"; String message = "File Not Found\n\n";
message += "URI: "; message += "URI: ";
message += webserver.uri(); message += webserver.uri();
@ -79,7 +78,8 @@ void handleNotFound() {
/* /*
This supports the Apple Captive Network Assistant (CNA) Portal This supports the Apple Captive Network Assistant (CNA) Portal
*/ */
void handleHotspot() { void handleHotspot()
{
DEBUG_MSG("Hotspot Request\n"); DEBUG_MSG("Hotspot Request\n");
String out = ""; String out = "";
@ -89,7 +89,8 @@ void handleHotspot() {
return; return;
} }
void notifyWebUI() { void notifyWebUI()
{
DEBUG_MSG("************ Got a message! ************\n"); DEBUG_MSG("************ Got a message! ************\n");
MeshPacket &mp = devicestate.rx_text_message; MeshPacket &mp = devicestate.rx_text_message;
NodeInfo *node = nodeDB.getNode(mp.from); NodeInfo *node = nodeDB.getNode(mp.from);
@ -99,7 +100,5 @@ void notifyWebUI() {
assert(mp.decoded.which_payload == SubPacket_data_tag); assert(mp.decoded.which_payload == SubPacket_data_tag);
snprintf(tempBuf, sizeof(tempBuf), "%s", mp.decoded.data.payload.bytes); snprintf(tempBuf, sizeof(tempBuf), "%s", mp.decoded.data.payload.bytes);
something = tempBuf; something = tempBuf;
} }