diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 4a6418b9e..e14e4078e 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -841,6 +841,9 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 // Jm void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { + const char *wifiName = radioConfig.preferences.wifi_ssid; + const char *wifiPsw = radioConfig.preferences.wifi_password; + displayedNodeNum = 0; // Not currently showing a node pane display->setFont(ArialMT_Plain_10); @@ -856,6 +859,9 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i display->drawString(x, y + FONT_HEIGHT * 1, WiFi.localIP().toString().c_str()); + display->drawString(x, y + FONT_HEIGHT * 2, wifiName); + display->drawString(x, y + FONT_HEIGHT * 3, wifiPsw); + /* Display a heartbeat pixel that blinks every time the frame is redrawn */ #ifdef SHOW_REDRAWS if (heartbeat) diff --git a/src/main.cpp b/src/main.cpp index 13b28debf..5c5a3a0e1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,6 +42,7 @@ #include #include #include "meshwifi/meshwifi.h" +#include "meshwifi/meshhttp.h" // #include #ifndef NO_ESP32 @@ -426,6 +427,15 @@ void loop() // TODO: This should go into a thread handled by FreeRTOS. handleWebResponse(); #endif - +/* + const char *wifiName = radioConfig.preferences.wifi_ssid; + const char *wifiPsw = radioConfig.preferences.wifi_password; + Serial.print("-------------------"); + Serial.print(wifiName); + Serial.print(" "); + Serial.println(wifiPsw); + Serial.println("+++++++++++++++++++"); + Serial.println(""); +*/ delay(msecstosleep); } diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 22d4675a3..07a97acfb 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -401,10 +401,11 @@ void NodeDB::updateFrom(const MeshPacket &mp) powerFSM.trigger(EVENT_RECEIVED_TEXT_MSG); notifyObservers(true); // Force an update whether or not our node counts have changed +// This is going into the wifidev feature branch // Only update the WebUI if WiFi is enabled -#if WiFi_MODE != 0 - notifyWebUI(); -#endif +//#if WiFi_MODE != 0 +// notifyWebUI(); +//#endif } } break; diff --git a/src/meshwifi/meshhttp.cpp b/src/meshwifi/meshhttp.cpp new file mode 100644 index 000000000..b70b8fc29 --- /dev/null +++ b/src/meshwifi/meshhttp.cpp @@ -0,0 +1,89 @@ +#include +#include +#include "configuration.h" +#include "main.h" +#include "NodeDB.h" +#include "meshwifi.h" +#include "meshhttp.h" + + +WebServer webserver(80); + +String something = ""; +String sender = ""; + + +void handleWebResponse() { + webserver.handleClient(); +} + +void initWebServer() { + webserver.onNotFound(handleNotFound); + //webserver.on("/", handleJSONChatHistory); + //webserver.on("/json/chat/history", handleJSONChatHistory); + webserver.on("/", []() { + webserver.send(200, "text/plain", "Everything is awesome!"); + }); + webserver.begin(); + +} + + +void handleJSONChatHistory() { + + String out = ""; + out += "{\n"; + out += " \"data\" : {\n"; + out += " \"chat\" : "; + out += "["; + out += "\"" + sender + "\""; + out += ","; + out += "\"" + something + "\""; + out += "]\n"; + + + + out += "\n"; + out += " }\n"; + out += "}\n"; + + webserver.send ( 200, "application/json", out ); + return; + +} + +void handleNotFound() { + String message = "File Not Found\n\n"; + message += "URI: "; + message += webserver.uri(); + message += "\nMethod: "; + message += (webserver.method() == HTTP_GET) ? "GET" : "POST"; + message += "\nArguments: "; + message += webserver.args(); + message += "\n"; + + for (uint8_t i = 0; i < webserver.args(); i++) { + message += " " + webserver.argName(i) + ": " + webserver.arg(i) + "\n"; + } + + webserver.send(404, "text/plain", message); + /* + */ +} + + + +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 diff --git a/src/meshwifi/meshhttp.h b/src/meshwifi/meshhttp.h new file mode 100644 index 000000000..cbff51db7 --- /dev/null +++ b/src/meshwifi/meshhttp.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include +#include + +void initWebServer(); + +void handleNotFound(); + +void handleWebResponse(); + +void handleJSONChatHistory(); + +void notifyWebUI(); + diff --git a/src/meshwifi/meshwifi.cpp b/src/meshwifi/meshwifi.cpp index 254c852d9..ea7df5c73 100644 --- a/src/meshwifi/meshwifi.cpp +++ b/src/meshwifi/meshwifi.cpp @@ -3,23 +3,7 @@ #include "configuration.h" #include "main.h" #include "NodeDB.h" -#include - -WebServer webserver(80); - -String something = ""; -String sender = ""; - -void initWebServer() { - webserver.onNotFound(handleNotFound); - webserver.on("/", handleJSONChatHistory); - webserver.on("/json/chat/history", handleJSONChatHistory); - //webserver.on("/", []() { - //webserver.send(200, "text/plain", "everything is awesome!"); - //}); - webserver.begin(); - -} +#include "meshwifi/meshhttp.h" void initWifi() { @@ -139,54 +123,6 @@ void WiFiEvent(WiFiEvent_t event) } } -void handleJSONChatHistory() { - - String out = ""; - out += "{\n"; - out += " \"data\" : {\n"; - out += " \"chat\" : "; - out += "["; - out += "\"" + sender + "\""; - out += ","; - out += "\"" + something + "\""; - out += "]\n"; - - - - out += "\n"; - out += " }\n"; - out += "}\n"; - - webserver.send ( 200, "application/json", out ); - return; - - -} - -void handleWebResponse() { - webserver.handleClient(); -} - - -void handleNotFound() { - String message = "File Not Found\n\n"; - message += "URI: "; - message += webserver.uri(); - message += "\nMethod: "; - message += (webserver.method() == HTTP_GET) ? "GET" : "POST"; - message += "\nArguments: "; - message += webserver.args(); - message += "\n"; - - for (uint8_t i = 0; i < webserver.args(); i++) { - message += " " + webserver.argName(i) + ": " + webserver.arg(i) + "\n"; - } - - webserver.send(404, "text/plain", message); - /* - */ -} - void reconnectWiFi() { if ( WiFi.status() != WL_CONNECTED ) { DEBUG_MSG("... Reconnecting to WiFi access point"); @@ -194,19 +130,3 @@ void reconnectWiFi() { } } - - -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 diff --git a/src/meshwifi/meshwifi.h b/src/meshwifi/meshwifi.h index e6b456e22..97903397f 100644 --- a/src/meshwifi/meshwifi.h +++ b/src/meshwifi/meshwifi.h @@ -4,19 +4,9 @@ #include #include -void handleNotFound(); - void reconnectWiFi(); void initWifi(); -void initWebServer(); - -void handleWebResponse(); - -void notifyWebUI(); - -void handleJSONChatHistory(); - void WiFiEvent(WiFiEvent_t event);