Skip to content

Commit

Permalink
Merge pull request #411 from mc-hamster/master
Browse files Browse the repository at this point in the history
Moved handleDNSResponse from main into handleWebResponse and used the auto format
  • Loading branch information
mc-hamster authored Sep 19, 2020
2 parents 6f75379 + 65fc1cf commit 0929b86
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ void loop()

// TODO: This should go into a thread handled by FreeRTOS.
handleWebResponse();
handleDNSResponse();

delay(msecstosleep);
}
57 changes: 28 additions & 29 deletions src/meshwifi/meshhttp.cpp
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
#include <WebServer.h>
#include <WiFi.h>
#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 <WebServer.h>
#include <WiFi.h>

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";
Expand All @@ -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();
Expand All @@ -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 += "<meta http-equiv=\"refresh\" content=\"0;url=http://meshtastic.org/\" />\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;

}

0 comments on commit 0929b86

Please sign in to comment.