mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-03 03:09:59 +00:00
Merge pull request #411 from mc-hamster/master
Moved handleDNSResponse from main into handleWebResponse and used the auto format
This commit is contained in:
commit
0929b86d62
@ -423,7 +423,6 @@ void loop()
|
||||
|
||||
// TODO: This should go into a thread handled by FreeRTOS.
|
||||
handleWebResponse();
|
||||
handleDNSResponse();
|
||||
|
||||
delay(msecstosleep);
|
||||
}
|
||||
|
@ -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";
|
||||
@ -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 += "<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;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user