From 925829dc58565c340e5a1c5e3701c8351167af5e Mon Sep 17 00:00:00 2001 From: Jm Date: Fri, 1 Jan 2021 12:31:46 -0800 Subject: [PATCH 01/32] Partial work to migrate to OSThread model --- src/airtime.cpp | 49 +++++++++++++++++++++++----------- src/airtime.h | 22 ++++++++++++--- src/main.cpp | 2 -- src/mesh/RadioLibInterface.cpp | 6 ++--- src/meshwifi/meshhttp.cpp | 21 +++++++++++---- src/meshwifi/meshhttp.h | 21 +++++++++++++-- 6 files changed, 91 insertions(+), 30 deletions(-) diff --git a/src/airtime.cpp b/src/airtime.cpp index ec0bf8c8..9632181b 100644 --- a/src/airtime.cpp +++ b/src/airtime.cpp @@ -3,6 +3,8 @@ #define periodsToLog 48 +AirTime airTime; + // A reminder that there are 3600 seconds in an hour so I don't have // to keep googling it. // This can be changed to a smaller number to speed up testing. @@ -11,6 +13,8 @@ uint32_t secondsPerPeriod = 3600; uint32_t lastMillis = 0; uint32_t secSinceBoot = 0; +// AirTime at; + // Don't read out of this directly. Use the helper functions. struct airtimeStruct { uint16_t periodTX[periodsToLog]; @@ -19,14 +23,18 @@ struct airtimeStruct { uint8_t lastPeriodIndex; } airtimes; -void logAirtime(reportTypes reportType, uint32_t airtime_ms) +void AirTime::logAirtime(reportTypes reportType, uint32_t airtime_ms) { + DEBUG_MSG("Packet - logAirtime()\n"); if (reportType == TX_LOG) { + DEBUG_MSG("Packet transmitted = %u\n", (uint32_t)round(airtime_ms / 1000)); airtimes.periodTX[0] = airtimes.periodTX[0] + round(airtime_ms / 1000); } else if (reportType == RX_LOG) { + DEBUG_MSG("Packet received = %u\n", (uint32_t)round(airtime_ms / 1000)); airtimes.periodRX[0] = airtimes.periodRX[0] + round(airtime_ms / 1000); } else if (reportType == RX_ALL_LOG) { + DEBUG_MSG("Packet received (noise?) = %u\n", (uint32_t)round(airtime_ms / 1000)); airtimes.periodRX_ALL[0] = airtimes.periodRX_ALL[0] + round(airtime_ms / 1000); } else { // Unknown report type @@ -38,23 +46,22 @@ uint8_t currentPeriodIndex() return ((getSecondsSinceBoot() / secondsPerPeriod) % periodsToLog); } -void airtimeCalculator() +void airtimeRotatePeriod() { - if (millis() - lastMillis > 1000) { - lastMillis = millis(); - secSinceBoot++; - if (airtimes.lastPeriodIndex != currentPeriodIndex()) { - for (int i = periodsToLog - 2; i >= 0; --i) { - airtimes.periodTX[i + 1] = airtimes.periodTX[i]; - airtimes.periodRX[i + 1] = airtimes.periodRX[i]; - airtimes.periodRX_ALL[i + 1] = airtimes.periodRX_ALL[i]; - } - airtimes.periodTX[0] = 0; - airtimes.periodRX[0] = 0; - airtimes.periodRX_ALL[0] = 0; - airtimes.lastPeriodIndex = currentPeriodIndex(); + if (airtimes.lastPeriodIndex != currentPeriodIndex()) { + DEBUG_MSG("Rotating airtimes to a new period = %u\n", currentPeriodIndex()); + + for (int i = periodsToLog - 2; i >= 0; --i) { + airtimes.periodTX[i + 1] = airtimes.periodTX[i]; + airtimes.periodRX[i + 1] = airtimes.periodRX[i]; + airtimes.periodRX_ALL[i + 1] = airtimes.periodRX_ALL[i]; } + airtimes.periodTX[0] = 0; + airtimes.periodRX[0] = 0; + airtimes.periodRX_ALL[0] = 0; + + airtimes.lastPeriodIndex = currentPeriodIndex(); } } @@ -86,3 +93,15 @@ uint32_t getSecondsSinceBoot() { return secSinceBoot; } + +AirTime::AirTime() : concurrency::OSThread("AirTime") {} + +int32_t AirTime::runOnce() +{ + DEBUG_MSG("AirTime::runOnce()\n"); + + airtimeRotatePeriod(); + secSinceBoot++; + + return 1000; +} \ No newline at end of file diff --git a/src/airtime.h b/src/airtime.h index 4cfbb82c..d79e8829 100644 --- a/src/airtime.h +++ b/src/airtime.h @@ -1,5 +1,6 @@ #pragma once +#include "concurrency/OSThread.h" #include "configuration.h" #include #include @@ -18,7 +19,7 @@ TX_LOG + RX_LOG = Total air time for a perticular meshtastic channel. TX_LOG + RX_LOG = Total air time for a perticular meshtastic channel, including - other lora radios. + other lora radios. RX_ALL_LOG - RX_LOG = Other lora radios on our frequency channel. */ @@ -26,7 +27,7 @@ enum reportTypes { TX_LOG, RX_LOG, RX_ALL_LOG }; void logAirtime(reportTypes reportType, uint32_t airtime_ms); -void airtimeCalculator(); +void airtimeRotatePeriod(); uint8_t currentPeriodIndex(); uint8_t getPeriodsToLog(); @@ -35,4 +36,19 @@ uint32_t getSecondsSinceBoot(); uint16_t *airtimeReport(reportTypes reportType); -uint32_t getSecondsPerPeriod(); \ No newline at end of file +uint32_t getSecondsPerPeriod(); + +class AirTime : private concurrency::OSThread +{ + + public: + AirTime(); + + void logAirtime(reportTypes reportType, uint32_t airtime_ms); + + protected: + + virtual int32_t runOnce(); +}; + +extern AirTime airTime; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 029f753e..bf62e585 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -584,6 +584,4 @@ void loop() mainDelay.delay(delayMsec); // if (didWake) DEBUG_MSG("wake!\n"); - // Handles cleanup for the airtime calculator. - airtimeCalculator(); } diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index f4ceeded..b4c93ac9 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -97,7 +97,7 @@ ErrorCode RadioLibInterface::send(MeshPacket *p) // Count the packet toward our TX airtime utilization. // We only count it if it can be added to the TX queue. - logAirtime(TX_LOG, xmitMsec); + airTime.logAirtime(TX_LOG, xmitMsec); // We want all sending/receiving to be done by our daemon thread, We use a delay here because this packet might have been sent // in response to a packet we just received. So we want to make sure the other side has had a chance to reconfigure its radio @@ -216,7 +216,7 @@ void RadioLibInterface::handleReceiveInterrupt() size_t length = iface->getPacketLength(); xmitMsec = getPacketTime(length); - logAirtime(RX_ALL_LOG, xmitMsec); + airTime.logAirtime(RX_ALL_LOG, xmitMsec); int state = iface->readData(radiobuf, length); if (state != ERR_NONE) { @@ -258,7 +258,7 @@ void RadioLibInterface::handleReceiveInterrupt() printPacket("Lora RX", mp); xmitMsec = getPacketTime(mp); - logAirtime(RX_LOG, xmitMsec); + airTime.logAirtime(RX_LOG, xmitMsec); deliverToReceiver(mp); } diff --git a/src/meshwifi/meshhttp.cpp b/src/meshwifi/meshhttp.cpp index 319a70d7..46fb1809 100644 --- a/src/meshwifi/meshhttp.cpp +++ b/src/meshwifi/meshhttp.cpp @@ -808,10 +808,10 @@ void handleFormUpload(HTTPRequest *req, HTTPResponse *res) return; } - //if (readLength) { - file.write(buf, readLength); - fileLength += readLength; - DEBUG_MSG("File Length %i\n", fileLength); + // if (readLength) { + file.write(buf, readLength); + fileLength += readLength; + DEBUG_MSG("File Length %i\n", fileLength); //} } // enableLoopWDT(); @@ -988,7 +988,8 @@ void handleRoot(HTTPRequest *req, HTTPResponse *res) res->printf("

\n"); res->printf("

You have gotten this error because the filesystem for the web server has not been loaded.

\n"); res->printf("

Please review the 'Common Problems' section of the web interface documentation.

\n"); + "href=https://github.com/meshtastic/Meshtastic-device/wiki/" + "How-to-use-the-Meshtastic-Web-Interface-over-WiFi>web interface documentation.

\n"); return; } @@ -1212,3 +1213,13 @@ void replaceAll(std::string &str, const std::string &from, const std::string &to start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx' } } + +HttpServer::HttpServer() : concurrency::OSThread("HttpServer") { + DEBUG_MSG("22**********************************\n"); +} + +int32_t HttpServer::runOnce() +{ + DEBUG_MSG("11**********************************\n"); + return 200; // Poll our GPIOs every 200ms (FIXME, make adjustable via protobuf arg) +} diff --git a/src/meshwifi/meshhttp.h b/src/meshwifi/meshhttp.h index b7a84475..3bcf2511 100644 --- a/src/meshwifi/meshhttp.h +++ b/src/meshwifi/meshhttp.h @@ -1,6 +1,7 @@ #pragma once #include "PhoneAPI.h" +#include "concurrency/OSThread.h" #include #include @@ -22,7 +23,7 @@ void handleRoot(); void handleScriptsScriptJS(); void handleJSONChatHistoryDummy(); -void replaceAll(std::string& str, const std::string& from, const std::string& to); +void replaceAll(std::string &str, const std::string &from, const std::string &to); class HttpAPI : public PhoneAPI { @@ -35,4 +36,20 @@ class HttpAPI : public PhoneAPI protected: // Nothing here yet -}; \ No newline at end of file +}; + +/** + * A plugin that provides easy low-level remote access to device hardware. + */ +class HttpServer : public concurrency::OSThread +{ + public: + // Nothing here + // RemoteHardwarePlugin(); + HttpServer(); + + protected: + virtual int32_t runOnce(); +}; + +// extern HttpServer httpServer; From 8295b88d96cfaa0fa913a20e08c66914ae39cec3 Mon Sep 17 00:00:00 2001 From: Jm Date: Fri, 1 Jan 2021 21:20:34 -0800 Subject: [PATCH 02/32] Checking in work so I don't lose it. Nothing's broke with the build. --- src/airtime.cpp | 28 +++++++++++++++++----------- src/main.cpp | 1 + src/meshwifi/WebServerThread.cpp | 14 ++++++++++++++ src/meshwifi/WebServerThread.h | 22 ++++++++++++++++++++++ src/meshwifi/meshhttp.cpp | 11 +---------- src/meshwifi/meshhttp.h | 18 ++---------------- 6 files changed, 57 insertions(+), 37 deletions(-) create mode 100644 src/meshwifi/WebServerThread.cpp create mode 100644 src/meshwifi/WebServerThread.h diff --git a/src/airtime.cpp b/src/airtime.cpp index 9632181b..a8399fbc 100644 --- a/src/airtime.cpp +++ b/src/airtime.cpp @@ -17,27 +17,27 @@ uint32_t secSinceBoot = 0; // Don't read out of this directly. Use the helper functions. struct airtimeStruct { - uint16_t periodTX[periodsToLog]; - uint16_t periodRX[periodsToLog]; - uint16_t periodRX_ALL[periodsToLog]; + uint16_t periodTX[periodsToLog]; // AirTime transmitted + uint16_t periodRX[periodsToLog]; // AirTime received and repeated (Only valid mesh packets) + uint16_t periodRX_ALL[periodsToLog]; // AirTime received regardless of valid mesh packet. Could include noise. uint8_t lastPeriodIndex; } airtimes; void AirTime::logAirtime(reportTypes reportType, uint32_t airtime_ms) { - DEBUG_MSG("Packet - logAirtime()\n"); + // DEBUG_MSG("Packet - logAirtime()\n"); if (reportType == TX_LOG) { - DEBUG_MSG("Packet transmitted = %u\n", (uint32_t)round(airtime_ms / 1000)); + DEBUG_MSG("AirTime - Packet transmitted : %us %ums\n", (uint32_t)round((float)airtime_ms / (float)1000), airtime_ms); airtimes.periodTX[0] = airtimes.periodTX[0] + round(airtime_ms / 1000); } else if (reportType == RX_LOG) { - DEBUG_MSG("Packet received = %u\n", (uint32_t)round(airtime_ms / 1000)); + DEBUG_MSG("AirTime - Packet received : %us %ums\n", (uint32_t)round((float)airtime_ms / (float)1000), airtime_ms); airtimes.periodRX[0] = airtimes.periodRX[0] + round(airtime_ms / 1000); } else if (reportType == RX_ALL_LOG) { - DEBUG_MSG("Packet received (noise?) = %u\n", (uint32_t)round(airtime_ms / 1000)); + DEBUG_MSG("AirTime - Packet received (noise?) : %us %ums\n", (uint32_t)round((float)airtime_ms / (float)1000), airtime_ms); airtimes.periodRX_ALL[0] = airtimes.periodRX_ALL[0] + round(airtime_ms / 1000); } else { - // Unknown report type + DEBUG_MSG("AirTime - Unknown report time. This should never happen!!\n"); } } @@ -67,7 +67,6 @@ void airtimeRotatePeriod() uint16_t *airtimeReport(reportTypes reportType) { - // currentHourIndexReset(); if (reportType == TX_LOG) { return airtimes.periodTX; @@ -98,10 +97,17 @@ AirTime::AirTime() : concurrency::OSThread("AirTime") {} int32_t AirTime::runOnce() { - DEBUG_MSG("AirTime::runOnce()\n"); + // DEBUG_MSG("AirTime::runOnce()\n"); airtimeRotatePeriod(); secSinceBoot++; - return 1000; + /* + This actually doesn't need to be run once per second but we currently use it for the + secSinceBoot counter. + + If we have a better counter of how long the device has been online (and not millis()) + then we can change this to something less frequent. Maybe once ever 5 seconds? + */ + return (1000 * 1); } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index bf62e585..32704093 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,7 @@ #include "main.h" #include "meshwifi/meshhttp.h" #include "meshwifi/meshwifi.h" +#include "meshwifi/WebServerThread.h" #include "sleep.h" #include "target_specific.h" #include diff --git a/src/meshwifi/WebServerThread.cpp b/src/meshwifi/WebServerThread.cpp new file mode 100644 index 00000000..dbb4a82f --- /dev/null +++ b/src/meshwifi/WebServerThread.cpp @@ -0,0 +1,14 @@ +#include "meshwifi/WebServerThread.h" +#include + +// Thread for the HTTP Server +WebServerThread webServerThread; + +WebServerThread::WebServerThread() : concurrency::OSThread("WebServerThread") {} + +int32_t WebServerThread::runOnce() +{ + DEBUG_MSG("WebServerThread::runOnce()\n"); + + return (1000 * 1); +} diff --git a/src/meshwifi/WebServerThread.h b/src/meshwifi/WebServerThread.h new file mode 100644 index 00000000..2f3b5510 --- /dev/null +++ b/src/meshwifi/WebServerThread.h @@ -0,0 +1,22 @@ +#pragma once + +#include "concurrency/OSThread.h" +#include "concurrency/Periodic.h" +#include +#include +#include "configuration.h" + + +class WebServerThread : private concurrency::OSThread +{ + + public: + WebServerThread(); + + + protected: + + virtual int32_t runOnce(); +}; + +extern WebServerThread webServerThread; \ No newline at end of file diff --git a/src/meshwifi/meshhttp.cpp b/src/meshwifi/meshhttp.cpp index 46fb1809..8814dc9d 100644 --- a/src/meshwifi/meshhttp.cpp +++ b/src/meshwifi/meshhttp.cpp @@ -49,6 +49,7 @@ HTTPServer *insecureServer; // Our API to handle messages to and from the radio. HttpAPI webAPI; + // Declare some handler functions for the various URLs on the server void handleAPIv1FromRadio(HTTPRequest *req, HTTPResponse *res); void handleAPIv1ToRadio(HTTPRequest *req, HTTPResponse *res); @@ -1213,13 +1214,3 @@ void replaceAll(std::string &str, const std::string &from, const std::string &to start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx' } } - -HttpServer::HttpServer() : concurrency::OSThread("HttpServer") { - DEBUG_MSG("22**********************************\n"); -} - -int32_t HttpServer::runOnce() -{ - DEBUG_MSG("11**********************************\n"); - return 200; // Poll our GPIOs every 200ms (FIXME, make adjustable via protobuf arg) -} diff --git a/src/meshwifi/meshhttp.h b/src/meshwifi/meshhttp.h index 3bcf2511..fc3e89f0 100644 --- a/src/meshwifi/meshhttp.h +++ b/src/meshwifi/meshhttp.h @@ -25,6 +25,8 @@ void handleJSONChatHistoryDummy(); void replaceAll(std::string &str, const std::string &from, const std::string &to); + +// Interface to the PhoneAPI to access the protobufs with messages class HttpAPI : public PhoneAPI { @@ -37,19 +39,3 @@ class HttpAPI : public PhoneAPI protected: // Nothing here yet }; - -/** - * A plugin that provides easy low-level remote access to device hardware. - */ -class HttpServer : public concurrency::OSThread -{ - public: - // Nothing here - // RemoteHardwarePlugin(); - HttpServer(); - - protected: - virtual int32_t runOnce(); -}; - -// extern HttpServer httpServer; From f7dcef39ced03ce2a993f657172a6068a4133092 Mon Sep 17 00:00:00 2001 From: Jm Date: Tue, 5 Jan 2021 23:21:14 -0800 Subject: [PATCH 03/32] intermediate work --- src/airtime.cpp | 2 +- src/main.cpp | 2 +- src/{meshwifi => mesh/wifi}/WebServerThread.cpp | 4 ++-- src/{meshwifi => mesh/wifi}/WebServerThread.h | 6 ++---- 4 files changed, 6 insertions(+), 8 deletions(-) rename src/{meshwifi => mesh/wifi}/WebServerThread.cpp (78%) rename src/{meshwifi => mesh/wifi}/WebServerThread.h (77%) diff --git a/src/airtime.cpp b/src/airtime.cpp index a8399fbc..5c8eb67f 100644 --- a/src/airtime.cpp +++ b/src/airtime.cpp @@ -97,7 +97,7 @@ AirTime::AirTime() : concurrency::OSThread("AirTime") {} int32_t AirTime::runOnce() { - // DEBUG_MSG("AirTime::runOnce()\n"); + //DEBUG_MSG("AirTime::runOnce()\n"); airtimeRotatePeriod(); secSinceBoot++; diff --git a/src/main.cpp b/src/main.cpp index 32704093..2c9485e2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,7 +21,7 @@ #include "main.h" #include "meshwifi/meshhttp.h" #include "meshwifi/meshwifi.h" -#include "meshwifi/WebServerThread.h" +#include "mesh/wifi/WebServerThread.h" #include "sleep.h" #include "target_specific.h" #include diff --git a/src/meshwifi/WebServerThread.cpp b/src/mesh/wifi/WebServerThread.cpp similarity index 78% rename from src/meshwifi/WebServerThread.cpp rename to src/mesh/wifi/WebServerThread.cpp index dbb4a82f..2bf0f79c 100644 --- a/src/meshwifi/WebServerThread.cpp +++ b/src/mesh/wifi/WebServerThread.cpp @@ -1,7 +1,6 @@ -#include "meshwifi/WebServerThread.h" +#include "mesh/wifi/WebServerThread.h" #include -// Thread for the HTTP Server WebServerThread webServerThread; WebServerThread::WebServerThread() : concurrency::OSThread("WebServerThread") {} @@ -12,3 +11,4 @@ int32_t WebServerThread::runOnce() return (1000 * 1); } + diff --git a/src/meshwifi/WebServerThread.h b/src/mesh/wifi/WebServerThread.h similarity index 77% rename from src/meshwifi/WebServerThread.h rename to src/mesh/wifi/WebServerThread.h index 2f3b5510..43e357f1 100644 --- a/src/meshwifi/WebServerThread.h +++ b/src/mesh/wifi/WebServerThread.h @@ -1,10 +1,9 @@ #pragma once #include "concurrency/OSThread.h" -#include "concurrency/Periodic.h" +#include "configuration.h" #include #include -#include "configuration.h" class WebServerThread : private concurrency::OSThread @@ -13,10 +12,9 @@ class WebServerThread : private concurrency::OSThread public: WebServerThread(); - protected: virtual int32_t runOnce(); }; -extern WebServerThread webServerThread; \ No newline at end of file +extern WebServerThread webServerThread; From 0af5b225c4eb2d23420d3a4dcb8dc03d60adbdf1 Mon Sep 17 00:00:00 2001 From: Jm Date: Tue, 5 Jan 2021 23:32:33 -0800 Subject: [PATCH 04/32] intermediate --- src/JMTest.cpp | 14 ++++++++++++++ src/JMTest.h | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 src/JMTest.cpp create mode 100644 src/JMTest.h diff --git a/src/JMTest.cpp b/src/JMTest.cpp new file mode 100644 index 00000000..1f2877af --- /dev/null +++ b/src/JMTest.cpp @@ -0,0 +1,14 @@ +#include "JMTest.h" +#include + +JMTest jMTest; + +JMTest::JMTest() : concurrency::OSThread("JMTest") {} + +int32_t JMTest::runOnce() +{ + DEBUG_MSG("JMTest::runOnce()\n"); + + return (1000); +} + diff --git a/src/JMTest.h b/src/JMTest.h new file mode 100644 index 00000000..dfb87345 --- /dev/null +++ b/src/JMTest.h @@ -0,0 +1,20 @@ +#pragma once + +#include "concurrency/OSThread.h" +#include "configuration.h" +#include +#include + + +class JMTest : private concurrency::OSThread +{ + + public: + JMTest(); + + protected: + + virtual int32_t runOnce(); +}; + +extern JMTest jMTest; From 977e47d109ccf46675b33a661de031e88e94c420 Mon Sep 17 00:00:00 2001 From: Jm Date: Fri, 8 Jan 2021 20:06:11 -0800 Subject: [PATCH 05/32] partial work --- proto | 2 +- src/JMTest.cpp | 14 -------------- src/JMTest.h | 20 -------------------- src/main.cpp | 6 +++++- src/mesh/wifi/WebServerThread.cpp | 2 +- src/mesh/wifi/WebServerThread.h | 2 +- 6 files changed, 8 insertions(+), 38 deletions(-) delete mode 100644 src/JMTest.cpp delete mode 100644 src/JMTest.h diff --git a/proto b/proto index dfe7bc12..75078afe 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit dfe7bc1217a00c23eecb9dfcf1d56fe95ebddc3b +Subproject commit 75078afe43934f4ce15ef86ebc6950658a170145 diff --git a/src/JMTest.cpp b/src/JMTest.cpp deleted file mode 100644 index 1f2877af..00000000 --- a/src/JMTest.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "JMTest.h" -#include - -JMTest jMTest; - -JMTest::JMTest() : concurrency::OSThread("JMTest") {} - -int32_t JMTest::runOnce() -{ - DEBUG_MSG("JMTest::runOnce()\n"); - - return (1000); -} - diff --git a/src/JMTest.h b/src/JMTest.h deleted file mode 100644 index dfb87345..00000000 --- a/src/JMTest.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "concurrency/OSThread.h" -#include "configuration.h" -#include -#include - - -class JMTest : private concurrency::OSThread -{ - - public: - JMTest(); - - protected: - - virtual int32_t runOnce(); -}; - -extern JMTest jMTest; diff --git a/src/main.cpp b/src/main.cpp index 077a9e2d..5808e3fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -517,6 +517,10 @@ void setup() // Initialize Wifi initWifi(forceSoftAP); + // Start web server thread. + //webServerThread = new WebServerThread(); + + if (!rIf) recordCriticalError(CriticalErrorCode_NoRadio); else @@ -577,7 +581,7 @@ void loop() #endif // TODO: This should go into a thread handled by FreeRTOS. - handleWebResponse(); + //handleWebResponse(); service.loop(); diff --git a/src/mesh/wifi/WebServerThread.cpp b/src/mesh/wifi/WebServerThread.cpp index 2bf0f79c..32fb5a38 100644 --- a/src/mesh/wifi/WebServerThread.cpp +++ b/src/mesh/wifi/WebServerThread.cpp @@ -1,7 +1,7 @@ #include "mesh/wifi/WebServerThread.h" #include -WebServerThread webServerThread; +WebServerThread *webServerThread; WebServerThread::WebServerThread() : concurrency::OSThread("WebServerThread") {} diff --git a/src/mesh/wifi/WebServerThread.h b/src/mesh/wifi/WebServerThread.h index 43e357f1..f57afb75 100644 --- a/src/mesh/wifi/WebServerThread.h +++ b/src/mesh/wifi/WebServerThread.h @@ -17,4 +17,4 @@ class WebServerThread : private concurrency::OSThread virtual int32_t runOnce(); }; -extern WebServerThread webServerThread; +extern WebServerThread *webServerThread; From cfcb00b9437da8182aefe892fb7fbfb5e06e2655 Mon Sep 17 00:00:00 2001 From: Jm Date: Fri, 8 Jan 2021 20:43:51 -0800 Subject: [PATCH 06/32] that's enough for tonight. web server is in its own thread, needs to be further optimized but it works enough. next is to refactor. --- src/airtime.cpp | 2 +- src/airtime.h | 2 +- src/main.cpp | 4 +++- src/mesh/RadioLibInterface.cpp | 9 ++++++--- src/mesh/wifi/WebServerThread.cpp | 7 +++++-- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/airtime.cpp b/src/airtime.cpp index 5c8eb67f..66f4a0a5 100644 --- a/src/airtime.cpp +++ b/src/airtime.cpp @@ -3,7 +3,7 @@ #define periodsToLog 48 -AirTime airTime; +AirTime *airTime; // A reminder that there are 3600 seconds in an hour so I don't have // to keep googling it. diff --git a/src/airtime.h b/src/airtime.h index d79e8829..43967001 100644 --- a/src/airtime.h +++ b/src/airtime.h @@ -51,4 +51,4 @@ class AirTime : private concurrency::OSThread virtual int32_t runOnce(); }; -extern AirTime airTime; \ No newline at end of file +extern AirTime *airTime; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 5808e3fa..4bf110ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -518,8 +518,10 @@ void setup() initWifi(forceSoftAP); // Start web server thread. - //webServerThread = new WebServerThread(); + webServerThread = new WebServerThread(); + // Start airtime logger thread. + airTime = new AirTime(); if (!rIf) recordCriticalError(CriticalErrorCode_NoRadio); diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index b4c93ac9..0266614a 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -97,7 +97,8 @@ ErrorCode RadioLibInterface::send(MeshPacket *p) // Count the packet toward our TX airtime utilization. // We only count it if it can be added to the TX queue. - airTime.logAirtime(TX_LOG, xmitMsec); + airTime->logAirtime(TX_LOG, xmitMsec); + //airTime.logAirtime(TX_LOG, xmitMsec); // We want all sending/receiving to be done by our daemon thread, We use a delay here because this packet might have been sent // in response to a packet we just received. So we want to make sure the other side has had a chance to reconfigure its radio @@ -216,7 +217,8 @@ void RadioLibInterface::handleReceiveInterrupt() size_t length = iface->getPacketLength(); xmitMsec = getPacketTime(length); - airTime.logAirtime(RX_ALL_LOG, xmitMsec); + airTime->logAirtime(RX_ALL_LOG, xmitMsec); + //airTime.logAirtime(RX_ALL_LOG, xmitMsec); int state = iface->readData(radiobuf, length); if (state != ERR_NONE) { @@ -258,7 +260,8 @@ void RadioLibInterface::handleReceiveInterrupt() printPacket("Lora RX", mp); xmitMsec = getPacketTime(mp); - airTime.logAirtime(RX_LOG, xmitMsec); + airTime->logAirtime(RX_LOG, xmitMsec); + //airTime.logAirtime(RX_LOG, xmitMsec); deliverToReceiver(mp); } diff --git a/src/mesh/wifi/WebServerThread.cpp b/src/mesh/wifi/WebServerThread.cpp index 32fb5a38..991fd6d9 100644 --- a/src/mesh/wifi/WebServerThread.cpp +++ b/src/mesh/wifi/WebServerThread.cpp @@ -1,4 +1,5 @@ #include "mesh/wifi/WebServerThread.h" +#include "meshwifi/meshhttp.h" #include WebServerThread *webServerThread; @@ -7,8 +8,10 @@ WebServerThread::WebServerThread() : concurrency::OSThread("WebServerThread") {} int32_t WebServerThread::runOnce() { - DEBUG_MSG("WebServerThread::runOnce()\n"); + //DEBUG_MSG("WebServerThread::runOnce()\n"); + handleWebResponse(); - return (1000 * 1); + // Loop every 5ms. + return (5); } From d458f673be870976263896c4ca9105e2bb13b406 Mon Sep 17 00:00:00 2001 From: Jm Date: Fri, 8 Jan 2021 22:25:44 -0800 Subject: [PATCH 07/32] Web server is now treaded and moved to mesh/wifi/* --- src/graphics/Screen.cpp | 2 +- src/main.cpp | 10 +- src/mesh/NodeDB.cpp | 2 +- src/mesh/wifi/ContentHelper.cpp | 14 ++ src/mesh/wifi/ContentHelper.h | 8 + .../wifi/ContentStatic.h} | 9 +- .../meshhttp.cpp => mesh/wifi/WebServer.cpp} | 216 +++++++++--------- .../meshhttp.h => mesh/wifi/WebServer.h} | 26 ++- src/mesh/wifi/WebServerThread.cpp | 17 -- src/mesh/wifi/WebServerThread.h | 20 -- .../wifi/WiFiAPClient.cpp} | 4 +- .../meshwifi.h => mesh/wifi/WiFiAPClient.h} | 0 src/nimble/BluetoothUtil.cpp | 2 +- src/nrf52/wifi-stubs.cpp | 4 +- 14 files changed, 160 insertions(+), 174 deletions(-) create mode 100644 src/mesh/wifi/ContentHelper.cpp create mode 100644 src/mesh/wifi/ContentHelper.h rename src/{meshwifi/meshhttpStatic.h => mesh/wifi/ContentStatic.h} (98%) rename src/{meshwifi/meshhttp.cpp => mesh/wifi/WebServer.cpp} (98%) rename src/{meshwifi/meshhttp.h => mesh/wifi/WebServer.h} (62%) delete mode 100644 src/mesh/wifi/WebServerThread.cpp delete mode 100644 src/mesh/wifi/WebServerThread.h rename src/{meshwifi/meshwifi.cpp => mesh/wifi/WiFiAPClient.cpp} (99%) rename src/{meshwifi/meshwifi.h => mesh/wifi/WiFiAPClient.h} (100%) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 34ab53ac..d4a1f5e7 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -31,7 +31,7 @@ along with this program. If not, see . #include "graphics/images.h" #include "main.h" #include "mesh-pb-constants.h" -#include "meshwifi/meshwifi.h" +#include "mesh/wifi/WiFiAPClient.h" #include "plugins/TextMessagePlugin.h" #include "target_specific.h" #include "utils.h" diff --git a/src/main.cpp b/src/main.cpp index 4bf110ad..441d16fd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,11 +19,10 @@ #include "concurrency/Periodic.h" #include "graphics/Screen.h" #include "main.h" -#include "meshwifi/meshhttp.h" -#include "meshwifi/meshwifi.h" -#include "mesh/wifi/WebServerThread.h" -#include "sleep.h" +#include "mesh/wifi/WebServer.h" +#include "mesh/wifi/WiFiAPClient.h" #include "plugins/Plugins.h" +#include "sleep.h" #include "target_specific.h" #include #include @@ -583,7 +582,7 @@ void loop() #endif // TODO: This should go into a thread handled by FreeRTOS. - //handleWebResponse(); + // handleWebResponse(); service.loop(); @@ -596,5 +595,4 @@ void loop() // We want to sleep as long as possible here - because it saves power mainDelay.delay(delayMsec); // if (didWake) DEBUG_MSG("wake!\n"); - } diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index a87a5e49..d674301d 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -16,7 +16,7 @@ #include "configuration.h" #include "error.h" #include "mesh-pb-constants.h" -#include "meshwifi/meshwifi.h" +#include "mesh/wifi/WiFiAPClient.h" #include #include diff --git a/src/mesh/wifi/ContentHelper.cpp b/src/mesh/wifi/ContentHelper.cpp new file mode 100644 index 00000000..96dec5d9 --- /dev/null +++ b/src/mesh/wifi/ContentHelper.cpp @@ -0,0 +1,14 @@ +#include "mesh/wifi/ContentHelper.h" +//#include +//#include "main.h" + +void replaceAll(std::string &str, const std::string &from, const std::string &to) +{ + if (from.empty()) + return; + size_t start_pos = 0; + while ((start_pos = str.find(from, start_pos)) != std::string::npos) { + str.replace(start_pos, from.length(), to); + start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx' + } +} diff --git a/src/mesh/wifi/ContentHelper.h b/src/mesh/wifi/ContentHelper.h new file mode 100644 index 00000000..f94b9816 --- /dev/null +++ b/src/mesh/wifi/ContentHelper.h @@ -0,0 +1,8 @@ +#include +#include + + + + +void replaceAll(std::string &str, const std::string &from, const std::string &to); + diff --git a/src/meshwifi/meshhttpStatic.h b/src/mesh/wifi/ContentStatic.h similarity index 98% rename from src/meshwifi/meshhttpStatic.h rename to src/mesh/wifi/ContentStatic.h index e48aeb41..32427647 100644 --- a/src/meshwifi/meshhttpStatic.h +++ b/src/mesh/wifi/ContentStatic.h @@ -2,14 +2,7 @@ #include /* - Steps: - - Compress the .js file to .js.gz - - Convert to hex: - http://tomeko.net/online_tools/file_to_hex.php?lang=en - - Paste into the array - - Note the filesize of your .gz file and write the file - size into the length int. - + This file contains static content. */ // Length of the binary data diff --git a/src/meshwifi/meshhttp.cpp b/src/mesh/wifi/WebServer.cpp similarity index 98% rename from src/meshwifi/meshhttp.cpp rename to src/mesh/wifi/WebServer.cpp index 76e9616f..ef11e5d3 100644 --- a/src/meshwifi/meshhttp.cpp +++ b/src/mesh/wifi/WebServer.cpp @@ -1,12 +1,12 @@ -#include "meshwifi/meshhttp.h" +#include "mesh/wifi/WebServer.h" #include "NodeDB.h" #include "PowerFSM.h" #include "airtime.h" -#include "configuration.h" #include "esp_task_wdt.h" #include "main.h" -#include "meshhttpStatic.h" -#include "meshwifi/meshwifi.h" +#include "mesh/wifi/ContentHelper.h" +#include "mesh/wifi/ContentStatic.h" +#include "mesh/wifi/WiFiAPClient.h" #include "sleep.h" #include #include @@ -15,6 +15,7 @@ #include #include + // Persistant Data Storage #include Preferences prefs; @@ -49,7 +50,6 @@ HTTPServer *insecureServer; // Our API to handle messages to and from the radio. HttpAPI webAPI; - // Declare some handler functions for the various URLs on the server void handleAPIv1FromRadio(HTTPRequest *req, HTTPResponse *res); void handleAPIv1ToRadio(HTTPRequest *req, HTTPResponse *res); @@ -197,6 +197,19 @@ void createSSLCert() DEBUG_MSG("SSL Cert Ready!\n"); } +WebServerThread *webServerThread; + +WebServerThread::WebServerThread() : concurrency::OSThread("WebServerThread") {} + +int32_t WebServerThread::runOnce() +{ + // DEBUG_MSG("WebServerThread::runOnce()\n"); + handleWebResponse(); + + // Loop every 5ms. + return (5); +} + void initWebServer() { DEBUG_MSG("Initializing Web Server ...\n"); @@ -242,6 +255,7 @@ void initWebServer() ResourceNode *nodeAPIv1ToRadioOptions = new ResourceNode("/api/v1/toradio", "OPTIONS", &handleAPIv1ToRadio); ResourceNode *nodeAPIv1ToRadio = new ResourceNode("/api/v1/toradio", "PUT", &handleAPIv1ToRadio); ResourceNode *nodeAPIv1FromRadio = new ResourceNode("/api/v1/fromradio", "GET", &handleAPIv1FromRadio); + ResourceNode *nodeHotspot = new ResourceNode("/hotspot-detect.html", "GET", &handleHotspot); ResourceNode *nodeFavicon = new ResourceNode("/favicon.ico", "GET", &handleFavicon); ResourceNode *nodeRoot = new ResourceNode("/", "GET", &handleRoot); @@ -341,6 +355,97 @@ void middlewareSpeedUp160(HTTPRequest *req, HTTPResponse *res, std::functiongetParams(); + + // std::string paramAll = "all"; + std::string valueAll; + + // Status code is 200 OK by default. + res->setHeader("Content-Type", "application/x-protobuf"); + res->setHeader("Access-Control-Allow-Origin", "*"); + res->setHeader("Access-Control-Allow-Methods", "PUT, GET"); + res->setHeader("X-Protobuf-Schema", "https://raw.githubusercontent.com/meshtastic/Meshtastic-protobufs/master/mesh.proto"); + + uint8_t txBuf[MAX_STREAM_BUF_SIZE]; + uint32_t len = 1; + + if (params->getQueryParameter("all", valueAll)) { + + // If all is ture, return all the buffers we have available + // to us at this point in time. + if (valueAll == "true") { + while (len) { + len = webAPI.getFromRadio(txBuf); + res->write(txBuf, len); + } + + // Otherwise, just return one protobuf + } else { + len = webAPI.getFromRadio(txBuf); + res->write(txBuf, len); + } + + // the param "all" was not spcified. Return just one protobuf + } else { + len = webAPI.getFromRadio(txBuf); + res->write(txBuf, len); + } + + DEBUG_MSG("--------------- webAPI handleAPIv1FromRadio, len %d\n", len); +} + +void handleAPIv1ToRadio(HTTPRequest *req, HTTPResponse *res) +{ + DEBUG_MSG("+++++++++++++++ webAPI handleAPIv1ToRadio\n"); + + /* + For documentation, see: + https://github.com/meshtastic/Meshtastic-device/wiki/HTTP-REST-API-discussion + https://github.com/meshtastic/Meshtastic-device/blob/master/docs/software/device-api.md + + Example: + http://10.10.30.198/api/v1/toradio + */ + + // Status code is 200 OK by default. + + res->setHeader("Content-Type", "application/x-protobuf"); + res->setHeader("Access-Control-Allow-Headers", "Content-Type"); + res->setHeader("Access-Control-Allow-Origin", "*"); + res->setHeader("Access-Control-Allow-Methods", "PUT, OPTIONS"); + res->setHeader("X-Protobuf-Schema", "https://raw.githubusercontent.com/meshtastic/Meshtastic-protobufs/master/mesh.proto"); + + if (req->getMethod() == "OPTIONS") { + res->setStatusCode(204); // Success with no content + res->print(""); + return; + } + + byte buffer[MAX_TO_FROM_RADIO_SIZE]; + size_t s = req->readBytes(buffer, MAX_TO_FROM_RADIO_SIZE); + + DEBUG_MSG("Received %d bytes from PUT request\n", s); + webAPI.handleToRadio(buffer, s); + + res->write(buffer, s); + DEBUG_MSG("--------------- webAPI handleAPIv1ToRadio\n"); +} + void handleStaticPost(HTTPRequest *req, HTTPResponse *res) { // Assume POST request. Contains submitted data. @@ -877,97 +982,6 @@ void handleHotspot(HTTPRequest *req, HTTPResponse *res) res->println("\n"); } -void handleAPIv1FromRadio(HTTPRequest *req, HTTPResponse *res) -{ - - DEBUG_MSG("+++++++++++++++ webAPI handleAPIv1FromRadio\n"); - - /* - For documentation, see: - https://github.com/meshtastic/Meshtastic-device/wiki/HTTP-REST-API-discussion - https://github.com/meshtastic/Meshtastic-device/blob/master/docs/software/device-api.md - - Example: - http://10.10.30.198/api/v1/fromradio - */ - - // Get access to the parameters - ResourceParameters *params = req->getParams(); - - // std::string paramAll = "all"; - std::string valueAll; - - // Status code is 200 OK by default. - res->setHeader("Content-Type", "application/x-protobuf"); - res->setHeader("Access-Control-Allow-Origin", "*"); - res->setHeader("Access-Control-Allow-Methods", "PUT, GET"); - res->setHeader("X-Protobuf-Schema", "https://raw.githubusercontent.com/meshtastic/Meshtastic-protobufs/master/mesh.proto"); - - uint8_t txBuf[MAX_STREAM_BUF_SIZE]; - uint32_t len = 1; - - if (params->getQueryParameter("all", valueAll)) { - - // If all is ture, return all the buffers we have available - // to us at this point in time. - if (valueAll == "true") { - while (len) { - len = webAPI.getFromRadio(txBuf); - res->write(txBuf, len); - } - - // Otherwise, just return one protobuf - } else { - len = webAPI.getFromRadio(txBuf); - res->write(txBuf, len); - } - - // the param "all" was not spcified. Return just one protobuf - } else { - len = webAPI.getFromRadio(txBuf); - res->write(txBuf, len); - } - - DEBUG_MSG("--------------- webAPI handleAPIv1FromRadio, len %d\n", len); -} - -void handleAPIv1ToRadio(HTTPRequest *req, HTTPResponse *res) -{ - DEBUG_MSG("+++++++++++++++ webAPI handleAPIv1ToRadio\n"); - - /* - For documentation, see: - https://github.com/meshtastic/Meshtastic-device/wiki/HTTP-REST-API-discussion - https://github.com/meshtastic/Meshtastic-device/blob/master/docs/software/device-api.md - - Example: - http://10.10.30.198/api/v1/toradio - */ - - // Status code is 200 OK by default. - - res->setHeader("Content-Type", "application/x-protobuf"); - res->setHeader("Access-Control-Allow-Headers", "Content-Type"); - res->setHeader("Access-Control-Allow-Origin", "*"); - res->setHeader("Access-Control-Allow-Methods", "PUT, OPTIONS"); - res->setHeader("X-Protobuf-Schema", "https://raw.githubusercontent.com/meshtastic/Meshtastic-protobufs/master/mesh.proto"); - - if (req->getMethod() == "OPTIONS") { - res->setStatusCode(204); // Success with no content - res->print(""); - return; - } - - byte buffer[MAX_TO_FROM_RADIO_SIZE]; - size_t s = req->readBytes(buffer, MAX_TO_FROM_RADIO_SIZE); - - DEBUG_MSG("Received %d bytes from PUT request\n", s); - webAPI.handleToRadio(buffer, s); - - res->write(buffer, s); - DEBUG_MSG("--------------- webAPI handleAPIv1ToRadio\n"); -} - /* To convert text to c strings: @@ -1212,13 +1226,3 @@ void handleFavicon(HTTPRequest *req, HTTPResponse *res) res->write(FAVICON_DATA, FAVICON_LENGTH); } -void replaceAll(std::string &str, const std::string &from, const std::string &to) -{ - if (from.empty()) - return; - size_t start_pos = 0; - while ((start_pos = str.find(from, start_pos)) != std::string::npos) { - str.replace(start_pos, from.length(), to); - start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx' - } -} diff --git a/src/meshwifi/meshhttp.h b/src/mesh/wifi/WebServer.h similarity index 62% rename from src/meshwifi/meshhttp.h rename to src/mesh/wifi/WebServer.h index fc3e89f0..b01d5960 100644 --- a/src/meshwifi/meshhttp.h +++ b/src/mesh/wifi/WebServer.h @@ -12,18 +12,11 @@ void handleNotFound(); void handleWebResponse(); -void handleJSONChatHistory(); -void notifyWebUI(); +//void handleHotspot(); -void handleHotspot(); - -void handleStyleCSS(); -void handleRoot(); -void handleScriptsScriptJS(); -void handleJSONChatHistoryDummy(); - -void replaceAll(std::string &str, const std::string &from, const std::string &to); +//void handleStyleCSS(); +//void handleRoot(); // Interface to the PhoneAPI to access the protobufs with messages @@ -39,3 +32,16 @@ class HttpAPI : public PhoneAPI protected: // Nothing here yet }; + +class WebServerThread : private concurrency::OSThread +{ + + public: + WebServerThread(); + + protected: + + virtual int32_t runOnce(); +}; + +extern WebServerThread *webServerThread; diff --git a/src/mesh/wifi/WebServerThread.cpp b/src/mesh/wifi/WebServerThread.cpp deleted file mode 100644 index 991fd6d9..00000000 --- a/src/mesh/wifi/WebServerThread.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "mesh/wifi/WebServerThread.h" -#include "meshwifi/meshhttp.h" -#include - -WebServerThread *webServerThread; - -WebServerThread::WebServerThread() : concurrency::OSThread("WebServerThread") {} - -int32_t WebServerThread::runOnce() -{ - //DEBUG_MSG("WebServerThread::runOnce()\n"); - handleWebResponse(); - - // Loop every 5ms. - return (5); -} - diff --git a/src/mesh/wifi/WebServerThread.h b/src/mesh/wifi/WebServerThread.h deleted file mode 100644 index f57afb75..00000000 --- a/src/mesh/wifi/WebServerThread.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "concurrency/OSThread.h" -#include "configuration.h" -#include -#include - - -class WebServerThread : private concurrency::OSThread -{ - - public: - WebServerThread(); - - protected: - - virtual int32_t runOnce(); -}; - -extern WebServerThread *webServerThread; diff --git a/src/meshwifi/meshwifi.cpp b/src/mesh/wifi/WiFiAPClient.cpp similarity index 99% rename from src/meshwifi/meshwifi.cpp rename to src/mesh/wifi/WiFiAPClient.cpp index 5ae83f87..32989b2b 100644 --- a/src/meshwifi/meshwifi.cpp +++ b/src/mesh/wifi/WiFiAPClient.cpp @@ -1,9 +1,9 @@ -#include "meshwifi.h" +#include "mesh/wifi/WiFiAPClient.h" #include "NodeDB.h" #include "mesh/wifi/WiFiServerAPI.h" #include "configuration.h" #include "main.h" -#include "meshwifi/meshhttp.h" +#include "mesh/wifi/WebServer.h" #include "target_specific.h" #include #include diff --git a/src/meshwifi/meshwifi.h b/src/mesh/wifi/WiFiAPClient.h similarity index 100% rename from src/meshwifi/meshwifi.h rename to src/mesh/wifi/WiFiAPClient.h diff --git a/src/nimble/BluetoothUtil.cpp b/src/nimble/BluetoothUtil.cpp index daba6937..37fb54d5 100644 --- a/src/nimble/BluetoothUtil.cpp +++ b/src/nimble/BluetoothUtil.cpp @@ -7,7 +7,7 @@ #include "esp_bt.h" #include "host/util/util.h" #include "main.h" -#include "meshwifi/meshwifi.h" +#include "mesh/wifi/WiFiAPClient.h" #include "nimble/NimbleDefs.h" #include "services/gap/ble_svc_gap.h" #include "services/gatt/ble_svc_gatt.h" diff --git a/src/nrf52/wifi-stubs.cpp b/src/nrf52/wifi-stubs.cpp index 1c100986..e12e295a 100644 --- a/src/nrf52/wifi-stubs.cpp +++ b/src/nrf52/wifi-stubs.cpp @@ -1,5 +1,5 @@ -#include "meshwifi/meshhttp.h" -#include "meshwifi/meshwifi.h" +#include "mesh/wifi/WebServer.h" +#include "mesh/wifi/WiFiAPClient.h" void initWifi(bool forceSoftAP) {} From 3798f4ca5be01c07a07424e9190878b48cb53f07 Mon Sep 17 00:00:00 2001 From: Jm Date: Fri, 8 Jan 2021 22:59:37 -0800 Subject: [PATCH 08/32] fix for building on NRF platform. --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 441d16fd..3e462d7a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -516,8 +516,10 @@ void setup() // Initialize Wifi initWifi(forceSoftAP); +#ifndef NO_ESP32 // Start web server thread. webServerThread = new WebServerThread(); +#endif // Start airtime logger thread. airTime = new AirTime(); From 69391e186b16a69b4e74716b3178cc4d9b012b07 Mon Sep 17 00:00:00 2001 From: Jm Date: Sat, 9 Jan 2021 13:47:10 -0800 Subject: [PATCH 09/32] Fix for breaking the linux build --- src/mesh/wifi/WebServer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mesh/wifi/WebServer.cpp b/src/mesh/wifi/WebServer.cpp index ef11e5d3..8eb88808 100644 --- a/src/mesh/wifi/WebServer.cpp +++ b/src/mesh/wifi/WebServer.cpp @@ -2,7 +2,6 @@ #include "NodeDB.h" #include "PowerFSM.h" #include "airtime.h" -#include "esp_task_wdt.h" #include "main.h" #include "mesh/wifi/ContentHelper.h" #include "mesh/wifi/ContentStatic.h" @@ -15,6 +14,9 @@ #include #include +#ifndef NO_ESP32 +#include "esp_task_wdt.h" +#endif // Persistant Data Storage #include @@ -1225,4 +1227,3 @@ void handleFavicon(HTTPRequest *req, HTTPResponse *res) // Write data from header file res->write(FAVICON_DATA, FAVICON_LENGTH); } - From 52dacaed37bdb17667a6968545d06ac0a59a46e2 Mon Sep 17 00:00:00 2001 From: Jm Date: Sat, 9 Jan 2021 17:30:36 -0800 Subject: [PATCH 10/32] more fixes for linux build --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 3e462d7a..1b736578 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,6 @@ #include "concurrency/Periodic.h" #include "graphics/Screen.h" #include "main.h" -#include "mesh/wifi/WebServer.h" #include "mesh/wifi/WiFiAPClient.h" #include "plugins/Plugins.h" #include "sleep.h" @@ -29,6 +28,7 @@ // #include #ifndef NO_ESP32 +#include "mesh/wifi/WebServer.h" #include "nimble/BluetoothUtil.h" #endif From 8b2798abd58f3de05b4a87cb68e476a4e354fb95 Mon Sep 17 00:00:00 2001 From: Jm Date: Sat, 9 Jan 2021 17:44:20 -0800 Subject: [PATCH 11/32] Added a few commented out default_envs --- platformio.ini | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 34667d2c..67199199 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,8 +9,13 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] +;default_envs = tbeam +;default_envs = tbeam0.7 +;default_envs = heltec +;default_envs = tlora-v1 +;default_envs = tlora-v2 +;default_envs = lora-relay-v1 # nrf board default_envs = linux # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here -;default_envs = heltec # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here [common] ; common is not currently used From 5688c8b81e3a608e6fdd5dfc526440c3680ed744 Mon Sep 17 00:00:00 2001 From: Jm Date: Sat, 9 Jan 2021 17:50:58 -0800 Subject: [PATCH 12/32] more linux build fixes --- src/graphics/Screen.cpp | 7 ++++++- src/main.cpp | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index d4a1f5e7..97b24df3 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -31,11 +31,14 @@ along with this program. If not, see . #include "graphics/images.h" #include "main.h" #include "mesh-pb-constants.h" -#include "mesh/wifi/WiFiAPClient.h" #include "plugins/TextMessagePlugin.h" #include "target_specific.h" #include "utils.h" +#ifndef NO_ESP32 +#include "mesh/wifi/WiFiAPClient.h" +#endif + using namespace meshtastic; /** @todo remove */ namespace graphics @@ -895,10 +898,12 @@ void Screen::setFrames() // call a method on debugInfoScreen object (for more details) normalFrames[numframes++] = &Screen::drawDebugInfoSettingsTrampoline; +#ifndef NO_ESP32 if (isWifiAvailable()) { // call a method on debugInfoScreen object (for more details) normalFrames[numframes++] = &Screen::drawDebugInfoWiFiTrampoline; } +#endif ui.setFrames(normalFrames, numframes); ui.enableAllIndicators(); diff --git a/src/main.cpp b/src/main.cpp index 1b736578..605b9196 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,6 @@ #include "concurrency/Periodic.h" #include "graphics/Screen.h" #include "main.h" -#include "mesh/wifi/WiFiAPClient.h" #include "plugins/Plugins.h" #include "sleep.h" #include "target_specific.h" @@ -29,6 +28,7 @@ #ifndef NO_ESP32 #include "mesh/wifi/WebServer.h" +#include "mesh/wifi/WiFiAPClient.h" #include "nimble/BluetoothUtil.h" #endif @@ -513,10 +513,11 @@ void setup() } #endif + +#ifndef NO_ESP32 // Initialize Wifi initWifi(forceSoftAP); -#ifndef NO_ESP32 // Start web server thread. webServerThread = new WebServerThread(); #endif From c82905bbddd4708d7d90ec8fea6fb5e50957c6ab Mon Sep 17 00:00:00 2001 From: Jm Date: Sat, 9 Jan 2021 18:09:16 -0800 Subject: [PATCH 13/32] is linux fixed now? --- src/nrf52/wifi-stubs.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/nrf52/wifi-stubs.cpp b/src/nrf52/wifi-stubs.cpp index e12e295a..8be0b41f 100644 --- a/src/nrf52/wifi-stubs.cpp +++ b/src/nrf52/wifi-stubs.cpp @@ -1,4 +1,4 @@ -#include "mesh/wifi/WebServer.h" +//#include "mesh/wifi/WebServer.h" #include "mesh/wifi/WiFiAPClient.h" void initWifi(bool forceSoftAP) {} @@ -9,8 +9,3 @@ bool isWifiAvailable() { return false; } - -void handleWebResponse() {} - -/// Perform idle loop processing required by the wifi layer -void loopWifi() {} \ No newline at end of file From 9cd24a56468f3ccf876193d9cb3e225a5f866095 Mon Sep 17 00:00:00 2001 From: Jm Date: Sat, 9 Jan 2021 18:27:03 -0800 Subject: [PATCH 14/32] is linux fixed now? --- src/nimble/BluetoothUtil.cpp | 6 +++++- src/nrf52/wifi-stubs.cpp | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/nimble/BluetoothUtil.cpp b/src/nimble/BluetoothUtil.cpp index 37fb54d5..18ffb1ed 100644 --- a/src/nimble/BluetoothUtil.cpp +++ b/src/nimble/BluetoothUtil.cpp @@ -545,7 +545,9 @@ void setBluetoothEnable(bool on) if (firstTime) { firstTime = 0; } else { - initWifi(0); +#ifndef NO_ESP32 + initWifi(); +#endif } } else { @@ -557,7 +559,9 @@ void setBluetoothEnable(bool on) */ // shutdown wifi +#ifndef NO_ESP32 deinitWifi(); +#endif // We have to totally teardown our bluetooth objects to prevent leaks deinitBLE(); diff --git a/src/nrf52/wifi-stubs.cpp b/src/nrf52/wifi-stubs.cpp index 8be0b41f..3de751ef 100644 --- a/src/nrf52/wifi-stubs.cpp +++ b/src/nrf52/wifi-stubs.cpp @@ -1,4 +1,7 @@ //#include "mesh/wifi/WebServer.h" + +#ifndef NO_ESP32 + #include "mesh/wifi/WiFiAPClient.h" void initWifi(bool forceSoftAP) {} @@ -9,3 +12,5 @@ bool isWifiAvailable() { return false; } + +#endif From 0a40d920e3e4c3d3725f0c023d26bfd91e3c1e05 Mon Sep 17 00:00:00 2001 From: Jm Date: Sat, 9 Jan 2021 18:36:23 -0800 Subject: [PATCH 15/32] Update BluetoothUtil.cpp yet another linux fix? --- src/nimble/BluetoothUtil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nimble/BluetoothUtil.cpp b/src/nimble/BluetoothUtil.cpp index 18ffb1ed..b6786e39 100644 --- a/src/nimble/BluetoothUtil.cpp +++ b/src/nimble/BluetoothUtil.cpp @@ -546,7 +546,7 @@ void setBluetoothEnable(bool on) firstTime = 0; } else { #ifndef NO_ESP32 - initWifi(); + initWifi(0); #endif } } else { From adb912b665893ce9c37defcadc3f7e507bce277c Mon Sep 17 00:00:00 2001 From: Jm Date: Sat, 9 Jan 2021 19:06:34 -0800 Subject: [PATCH 16/32] fixed in linux now? --- src/nrf52/wifi-stubs.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nrf52/wifi-stubs.cpp b/src/nrf52/wifi-stubs.cpp index 3de751ef..74e352c1 100644 --- a/src/nrf52/wifi-stubs.cpp +++ b/src/nrf52/wifi-stubs.cpp @@ -1,4 +1,5 @@ //#include "mesh/wifi/WebServer.h" +#include "configuration.h" #ifndef NO_ESP32 From f02ab88393286251aeecb403b8e9f2c8fd0fcc60 Mon Sep 17 00:00:00 2001 From: Jm Date: Sat, 9 Jan 2021 19:15:10 -0800 Subject: [PATCH 17/32] Does this fix the linux build? --- src/nrf52/wifi-stubs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nrf52/wifi-stubs.cpp b/src/nrf52/wifi-stubs.cpp index 74e352c1..6051e195 100644 --- a/src/nrf52/wifi-stubs.cpp +++ b/src/nrf52/wifi-stubs.cpp @@ -3,7 +3,7 @@ #ifndef NO_ESP32 -#include "mesh/wifi/WiFiAPClient.h" +//#include "mesh/wifi/WiFiAPClient.h" void initWifi(bool forceSoftAP) {} From 0c06d8db3c7de71f44f64aa3463381d5cb9f7618 Mon Sep 17 00:00:00 2001 From: Jm Date: Sat, 9 Jan 2021 19:31:16 -0800 Subject: [PATCH 18/32] maybe this will fix the linux build? --- src/mesh/NodeDB.cpp | 5 ++++- src/nimble/BluetoothUtil.cpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index d674301d..a2a1e316 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -16,10 +16,13 @@ #include "configuration.h" #include "error.h" #include "mesh-pb-constants.h" -#include "mesh/wifi/WiFiAPClient.h" #include #include +#ifndef NO_ESP32 +#include "mesh/wifi/WiFiAPClient.h" +#endif + NodeDB nodeDB; // we have plenty of ram so statically alloc this tempbuf (for now) diff --git a/src/nimble/BluetoothUtil.cpp b/src/nimble/BluetoothUtil.cpp index b6786e39..86cd2074 100644 --- a/src/nimble/BluetoothUtil.cpp +++ b/src/nimble/BluetoothUtil.cpp @@ -7,13 +7,16 @@ #include "esp_bt.h" #include "host/util/util.h" #include "main.h" -#include "mesh/wifi/WiFiAPClient.h" #include "nimble/NimbleDefs.h" #include "services/gap/ble_svc_gap.h" #include "services/gatt/ble_svc_gatt.h" #include #include +#ifndef NO_ESP32 +#include "mesh/wifi/WiFiAPClient.h" +#endif + static bool pinShowing; static uint32_t doublepressed; From fdc9bf57839600e5b3aae296eeec42ac26025808 Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Mon, 11 Jan 2021 20:25:02 -0500 Subject: [PATCH 19/32] add power statistics for #635 --- src/mesh/wifi/WebServer.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/mesh/wifi/WebServer.cpp b/src/mesh/wifi/WebServer.cpp index 8eb88808..385d57e6 100644 --- a/src/mesh/wifi/WebServer.cpp +++ b/src/mesh/wifi/WebServer.cpp @@ -1,6 +1,7 @@ #include "mesh/wifi/WebServer.h" #include "NodeDB.h" #include "PowerFSM.h" +#include "power.h" #include "airtime.h" #include "main.h" #include "mesh/wifi/ContentHelper.h" @@ -1169,7 +1170,14 @@ void handleReport(HTTPRequest *req, HTTPResponse *res) res->println("},"); - res->println("\"test\": 123"); + res->println("\"power\": {"); +#define BoolToString(x) ((x)?"true":"false") + res->printf("\"battery_percent\": %u,\n", powerStatus->getBatteryChargePercent()); + res->printf("\"battery_voltage_mv\": %u,\n", powerStatus->getBatteryVoltageMv()); + res->printf("\"has_battery\": %s,\n", BoolToString(powerStatus->getHasBattery())); + res->printf("\"has_usb\": %s,\n", BoolToString(powerStatus->getHasUSB())); + res->printf("\"is_charging\": %s\n", BoolToString(powerStatus->getIsCharging())); + res->println("}"); res->println("},"); From 0f573901d520ad0e7b176fbaba272a41114d0fdb Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Mon, 11 Jan 2021 20:28:09 -0500 Subject: [PATCH 20/32] didn't need power.h --- src/mesh/wifi/WebServer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mesh/wifi/WebServer.cpp b/src/mesh/wifi/WebServer.cpp index 385d57e6..2f263e21 100644 --- a/src/mesh/wifi/WebServer.cpp +++ b/src/mesh/wifi/WebServer.cpp @@ -1,7 +1,6 @@ #include "mesh/wifi/WebServer.h" #include "NodeDB.h" #include "PowerFSM.h" -#include "power.h" #include "airtime.h" #include "main.h" #include "mesh/wifi/ContentHelper.h" From 95c502c658be2c425246d826aaec2af351ae0092 Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Mon, 11 Jan 2021 20:30:02 -0500 Subject: [PATCH 21/32] fix typo --- src/PowerStatus.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PowerStatus.h b/src/PowerStatus.h index e9c192fb..a276be59 100644 --- a/src/PowerStatus.h +++ b/src/PowerStatus.h @@ -11,7 +11,7 @@ namespace meshtastic */ enum OptionalBool { OptFalse = 0, OptTrue = 1, OptUnknown = 2 }; -/// Describes the state of the GPS system. +/// Describes the state of the Power system. class PowerStatus : public Status { From 3c60df15651698239a4e3426c62ba37be558d6ae Mon Sep 17 00:00:00 2001 From: Jm Date: Wed, 13 Jan 2021 20:22:59 -0800 Subject: [PATCH 22/32] Partial work on the SerialPlugin --- src/plugins/Plugins.cpp | 2 + src/plugins/SerialPlugin.cpp | 133 +++++++++++++++++++++++++++++++++++ src/plugins/SerialPlugin.h | 54 ++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 src/plugins/SerialPlugin.cpp create mode 100644 src/plugins/SerialPlugin.h diff --git a/src/plugins/Plugins.cpp b/src/plugins/Plugins.cpp index 7a43c45f..eee8280c 100644 --- a/src/plugins/Plugins.cpp +++ b/src/plugins/Plugins.cpp @@ -1,6 +1,7 @@ #include "plugins/NodeInfoPlugin.h" #include "plugins/PositionPlugin.h" #include "plugins/ReplyPlugin.h" +#include "plugins/SerialPlugin.h" #include "plugins/RemoteHardwarePlugin.h" #include "plugins/TextMessagePlugin.h" @@ -17,4 +18,5 @@ void setupPlugins() { new RemoteHardwarePlugin(); new ReplyPlugin(); + new SerialPlugin(); // Maintained by MC Hamster (Jm Casler) jm@casler.org } \ No newline at end of file diff --git a/src/plugins/SerialPlugin.cpp b/src/plugins/SerialPlugin.cpp new file mode 100644 index 00000000..f317e822 --- /dev/null +++ b/src/plugins/SerialPlugin.cpp @@ -0,0 +1,133 @@ +#include "SerialPlugin.h" +#include "MeshService.h" +#include "NodeDB.h" +#include "RTC.h" +#include "Router.h" +#include "configuration.h" +#include + +#include + +/* + Designed for lora32 v1.0 + Manufacture Info: http://www.lilygo.cn/prod_view.aspx?TypeId=50003&Id=1133&FId=t3:50003:3 + Pin Mapping: http://ae01.alicdn.com/kf/HTB1fLBcxkSWBuNjSszdq6zeSpXaJ.jpg +*/ + +#define RXD2 16 +#define TXD2 17 +#define SERIALPLUGIN_RX_BUFFER 128 +#define SERIALPLUGIN_STRING_MAX Constants_DATA_PAYLOAD_LEN +#define SERIALPLUGIN_TIMEOUT 250 +#define SERIALPLUGIN_BAUD 38400 +#define SERIALPLUGIN_ENABLED 0 +#define SERIALPLUGIN_ECHO 1 + +SerialPlugin *serialPlugin; +SerialPluginRadio *serialPluginRadio; + +SerialPlugin::SerialPlugin() : concurrency::OSThread("SerialPlugin") {} + +char serialStringChar[Constants_DATA_PAYLOAD_LEN]; + +int32_t SerialPlugin::runOnce() +{ + +#if SERIALPLUGIN_ENABLED == 0 + + if (firstTime) { + + // Interface with the serial peripheral from in here. + DEBUG_MSG("Initilizing serial peripheral interface\n"); + + Serial2.begin(SERIALPLUGIN_BAUD, SERIAL_8N1, RXD2, TXD2); + Serial2.setTimeout(SERIALPLUGIN_TIMEOUT); // Number of MS to wait to set the timeout for the string. + Serial2.setRxBufferSize(SERIALPLUGIN_RX_BUFFER); + + serialPluginRadio = new SerialPluginRadio(); + + DEBUG_MSG("Initilizing serial peripheral interface - Done\n"); + + firstTime = 0; + + } else { + // Interface with the serial peripheral from in here. + String serialString; + + while (Serial2.available()) { + serialString = Serial2.readString(); + serialString.toCharArray(serialStringChar, Constants_DATA_PAYLOAD_LEN); + + serialPluginRadio->sendPayload(); + + DEBUG_MSG("Received: %s\n", serialStringChar); + } + } + + return (10); +#else + DEBUG_MSG("Serial Plugin Disabled\n"); + + return (INT32_MAX); +#endif +} + +MeshPacket *SerialPluginRadio::allocReply() +{ + + auto reply = allocDataPacket(); // Allocate a packet for sending + + return reply; +} + +void SerialPluginRadio::sendPayload(NodeNum dest, bool wantReplies) +{ + MeshPacket *p = allocReply(); + p->to = dest; + p->decoded.want_response = wantReplies; + + p->decoded.data.payload.size = strlen(serialStringChar); // You must specify how many bytes are in the reply + memcpy(p->decoded.data.payload.bytes, serialStringChar, p->decoded.data.payload.size); + + service.sendToMesh(p); +} + +bool SerialPluginRadio::handleReceived(const MeshPacket &mp) +{ + auto &p = mp.decoded.data; + DEBUG_MSG("* * * * * * * * * * Received text msg self=0x%0x, from=0x%0x, to=0x%0x, id=%d, msg=%.*s\n", nodeDB.getNodeNum(), + mp.from, mp.to, mp.id, p.payload.size, p.payload.bytes); + + /* + * If SERIALPLUGIN_ECHO is true, then echo the packets that are sent out back to the TX + * of the serial interface. + */ + if (mp.from == nodeDB.getNodeNum()) { + + if (SERIALPLUGIN_ECHO) { + + // For some reason, we get the packet back twice when we send out of the radio. + // TODO: need to find out why. + if (lastRxID != mp.id) { + lastRxID = mp.id; + DEBUG_MSG("* * Message came this device\n"); + Serial2.println("* * Message came this device"); + } + } + + } else { + DEBUG_MSG("* * Message came from the mesh\n"); + Serial2.println("* * Message came from the mesh"); + } + + // We only store/display messages destined for us. + // Keep a copy of the most recent text message. + // devicestate.rx_text_message = mp; + // devicestate.has_rx_text_message = true; + + // Serial2.print(p.payload.bytes); + + // TODO: If packet came from this device, don't echo locally. + + return true; // Let others look at this message also if they want +} diff --git a/src/plugins/SerialPlugin.h b/src/plugins/SerialPlugin.h new file mode 100644 index 00000000..814fbd15 --- /dev/null +++ b/src/plugins/SerialPlugin.h @@ -0,0 +1,54 @@ +#pragma once + +#include "SinglePortPlugin.h" +#include "concurrency/OSThread.h" +#include "configuration.h" +#include +#include + +class SerialPlugin : private concurrency::OSThread +{ + bool firstTime = 1; + + public: + SerialPlugin(); + + protected: + virtual int32_t runOnce(); +}; + +extern SerialPlugin *serialPlugin; + +/* + * Radio interface for SerialPlugin + * + */ +class SerialPluginRadio : public SinglePortPlugin +{ + uint32_t lastRxID; + + public: + /* + TODO: Switch this to PortNum_SERIAL_APP once the change is able to be merged back here + from the main code. + */ + + SerialPluginRadio() : SinglePortPlugin("SerialPluginRadio", PortNum_TEXT_MESSAGE_APP) {} + // SerialPluginRadio() : SinglePortPlugin("SerialPluginRadio", PortNum_PRIVATE_APP) {} + + /** + * Send our payload into the mesh + */ + void sendPayload(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false); + + protected: + virtual MeshPacket *allocReply(); + + /** Called to handle a particular incoming message + + @return true if you've guaranteed you've handled this message and no other handlers should be considered for it + */ + virtual bool handleReceived(const MeshPacket &mp); +}; + +extern SerialPluginRadio *serialPluginRadio; \ No newline at end of file From eee7e1de570c8239806941494e2bff0698e38d7e Mon Sep 17 00:00:00 2001 From: Jm Date: Wed, 13 Jan 2021 22:39:11 -0800 Subject: [PATCH 23/32] Update to serial plugin --- src/plugins/SerialPlugin.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/plugins/SerialPlugin.cpp b/src/plugins/SerialPlugin.cpp index f317e822..00d6070d 100644 --- a/src/plugins/SerialPlugin.cpp +++ b/src/plugins/SerialPlugin.cpp @@ -46,7 +46,7 @@ int32_t SerialPlugin::runOnce() serialPluginRadio = new SerialPluginRadio(); - DEBUG_MSG("Initilizing serial peripheral interface - Done\n"); + //DEBUG_MSG("Initilizing serial peripheral interface - Done\n"); firstTime = 0; @@ -95,8 +95,8 @@ void SerialPluginRadio::sendPayload(NodeNum dest, bool wantReplies) bool SerialPluginRadio::handleReceived(const MeshPacket &mp) { auto &p = mp.decoded.data; - DEBUG_MSG("* * * * * * * * * * Received text msg self=0x%0x, from=0x%0x, to=0x%0x, id=%d, msg=%.*s\n", nodeDB.getNodeNum(), - mp.from, mp.to, mp.id, p.payload.size, p.payload.bytes); + //DEBUG_MSG("Received text msg self=0x%0x, from=0x%0x, to=0x%0x, id=%d, msg=%.*s\n", nodeDB.getNodeNum(), + // mp.from, mp.to, mp.id, p.payload.size, p.payload.bytes); /* * If SERIALPLUGIN_ECHO is true, then echo the packets that are sent out back to the TX @@ -110,24 +110,17 @@ bool SerialPluginRadio::handleReceived(const MeshPacket &mp) // TODO: need to find out why. if (lastRxID != mp.id) { lastRxID = mp.id; - DEBUG_MSG("* * Message came this device\n"); - Serial2.println("* * Message came this device"); + //DEBUG_MSG("* * Message came this device\n"); + //Serial2.println("* * Message came this device"); + Serial2.printf("%s", p.payload.bytes); } } } else { - DEBUG_MSG("* * Message came from the mesh\n"); - Serial2.println("* * Message came from the mesh"); + //DEBUG_MSG("* * Message came from the mesh\n"); + //Serial2.println("* * Message came from the mesh"); + Serial2.printf("%s", p.payload.bytes); } - // We only store/display messages destined for us. - // Keep a copy of the most recent text message. - // devicestate.rx_text_message = mp; - // devicestate.has_rx_text_message = true; - - // Serial2.print(p.payload.bytes); - - // TODO: If packet came from this device, don't echo locally. - return true; // Let others look at this message also if they want } From c54e87f9a26ffa664387c0759e91e78d2b393f7e Mon Sep 17 00:00:00 2001 From: Jm Date: Wed, 13 Jan 2021 22:50:02 -0800 Subject: [PATCH 24/32] Update SerialPlugin.cpp Added documentation. --- src/plugins/SerialPlugin.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/plugins/SerialPlugin.cpp b/src/plugins/SerialPlugin.cpp index 00d6070d..710a9f20 100644 --- a/src/plugins/SerialPlugin.cpp +++ b/src/plugins/SerialPlugin.cpp @@ -12,16 +12,36 @@ Designed for lora32 v1.0 Manufacture Info: http://www.lilygo.cn/prod_view.aspx?TypeId=50003&Id=1133&FId=t3:50003:3 Pin Mapping: http://ae01.alicdn.com/kf/HTB1fLBcxkSWBuNjSszdq6zeSpXaJ.jpg + + + This will probably and most likely work on other boards too. + + Need help with this plugin? Post your question on the Meshtastic Discourse: + https://meshtastic.discourse.group + + Basic Usage: + + 1) Enable the plugin by setting SERIALPLUGIN_ENABLED to 1. + 2) Set the pins (RXD2 / TXD2) for your preferred RX and TX GPIO pins + 3) Set SERIALPLUGIN_TIMEOUT to the amount of time to wait before we consider + your packet as "done". + 4) (Optional) In SerialPlugin.h set the port to PortNum_TEXT_MESSAGE_APP if you want to + send messages to/from the general text message channel. + 5) Connect to your device over the serial interface at 38400 8N1. + 6) Send a packet up to 240 bytes in length. This will get relayed over the mesh network. + 7) (Optional) Set SERIALPLUGIN_ECHO to 1 and any message you send out will be echoed back + to your device. + */ #define RXD2 16 #define TXD2 17 #define SERIALPLUGIN_RX_BUFFER 128 #define SERIALPLUGIN_STRING_MAX Constants_DATA_PAYLOAD_LEN -#define SERIALPLUGIN_TIMEOUT 250 +#define SERIALPLUGIN_TIMEOUT 100 #define SERIALPLUGIN_BAUD 38400 #define SERIALPLUGIN_ENABLED 0 -#define SERIALPLUGIN_ECHO 1 +#define SERIALPLUGIN_ECHO 0 SerialPlugin *serialPlugin; SerialPluginRadio *serialPluginRadio; @@ -33,7 +53,7 @@ char serialStringChar[Constants_DATA_PAYLOAD_LEN]; int32_t SerialPlugin::runOnce() { -#if SERIALPLUGIN_ENABLED == 0 +#if SERIALPLUGIN_ENABLED == 1 if (firstTime) { @@ -46,12 +66,9 @@ int32_t SerialPlugin::runOnce() serialPluginRadio = new SerialPluginRadio(); - //DEBUG_MSG("Initilizing serial peripheral interface - Done\n"); - firstTime = 0; } else { - // Interface with the serial peripheral from in here. String serialString; while (Serial2.available()) { From 89b32dd7eeed252223d1dc15da5fedd948fae8c4 Mon Sep 17 00:00:00 2001 From: Jm Date: Wed, 13 Jan 2021 22:51:36 -0800 Subject: [PATCH 25/32] Fix comments in serial plugin --- src/plugins/SerialPlugin.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/plugins/SerialPlugin.cpp b/src/plugins/SerialPlugin.cpp index 710a9f20..43f40bbd 100644 --- a/src/plugins/SerialPlugin.cpp +++ b/src/plugins/SerialPlugin.cpp @@ -22,7 +22,7 @@ Basic Usage: 1) Enable the plugin by setting SERIALPLUGIN_ENABLED to 1. - 2) Set the pins (RXD2 / TXD2) for your preferred RX and TX GPIO pins + 2) Set the pins (RXD2 / TXD2) for your preferred RX and TX GPIO pins. 3) Set SERIALPLUGIN_TIMEOUT to the amount of time to wait before we consider your packet as "done". 4) (Optional) In SerialPlugin.h set the port to PortNum_TEXT_MESSAGE_APP if you want to @@ -112,30 +112,30 @@ void SerialPluginRadio::sendPayload(NodeNum dest, bool wantReplies) bool SerialPluginRadio::handleReceived(const MeshPacket &mp) { auto &p = mp.decoded.data; - //DEBUG_MSG("Received text msg self=0x%0x, from=0x%0x, to=0x%0x, id=%d, msg=%.*s\n", nodeDB.getNodeNum(), + // DEBUG_MSG("Received text msg self=0x%0x, from=0x%0x, to=0x%0x, id=%d, msg=%.*s\n", nodeDB.getNodeNum(), // mp.from, mp.to, mp.id, p.payload.size, p.payload.bytes); - /* - * If SERIALPLUGIN_ECHO is true, then echo the packets that are sent out back to the TX - * of the serial interface. - */ if (mp.from == nodeDB.getNodeNum()) { + /* + * If SERIALPLUGIN_ECHO is true, then echo the packets that are sent out back to the TX + * of the serial interface. + */ if (SERIALPLUGIN_ECHO) { // For some reason, we get the packet back twice when we send out of the radio. // TODO: need to find out why. if (lastRxID != mp.id) { lastRxID = mp.id; - //DEBUG_MSG("* * Message came this device\n"); - //Serial2.println("* * Message came this device"); + // DEBUG_MSG("* * Message came this device\n"); + // Serial2.println("* * Message came this device"); Serial2.printf("%s", p.payload.bytes); } } } else { - //DEBUG_MSG("* * Message came from the mesh\n"); - //Serial2.println("* * Message came from the mesh"); + // DEBUG_MSG("* * Message came from the mesh\n"); + // Serial2.println("* * Message came from the mesh"); Serial2.printf("%s", p.payload.bytes); } From b1181deb58f3168dbbf7f732dfba58ced24f09bd Mon Sep 17 00:00:00 2001 From: Jm Date: Wed, 13 Jan 2021 23:02:13 -0800 Subject: [PATCH 26/32] serialplugin - Added my todo list --- src/plugins/SerialPlugin.cpp | 9 +++++++-- src/plugins/SerialPlugin.h | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/plugins/SerialPlugin.cpp b/src/plugins/SerialPlugin.cpp index 43f40bbd..daf0c8c2 100644 --- a/src/plugins/SerialPlugin.cpp +++ b/src/plugins/SerialPlugin.cpp @@ -13,8 +13,8 @@ Manufacture Info: http://www.lilygo.cn/prod_view.aspx?TypeId=50003&Id=1133&FId=t3:50003:3 Pin Mapping: http://ae01.alicdn.com/kf/HTB1fLBcxkSWBuNjSszdq6zeSpXaJ.jpg - - This will probably and most likely work on other boards too. + This will probably and most likely work on other esp32 devices, given possible change the RX/TX + selection. Need help with this plugin? Post your question on the Meshtastic Discourse: https://meshtastic.discourse.group @@ -32,6 +32,11 @@ 7) (Optional) Set SERIALPLUGIN_ECHO to 1 and any message you send out will be echoed back to your device. + TODO: + * Once protobufs regenerated with the new port, update SerialPlugin.h + * Implement an interface to enable / disable ack + * Ensure this works on a tbeam + */ #define RXD2 16 diff --git a/src/plugins/SerialPlugin.h b/src/plugins/SerialPlugin.h index 814fbd15..c6d79f3e 100644 --- a/src/plugins/SerialPlugin.h +++ b/src/plugins/SerialPlugin.h @@ -34,7 +34,7 @@ class SerialPluginRadio : public SinglePortPlugin */ SerialPluginRadio() : SinglePortPlugin("SerialPluginRadio", PortNum_TEXT_MESSAGE_APP) {} - // SerialPluginRadio() : SinglePortPlugin("SerialPluginRadio", PortNum_PRIVATE_APP) {} + // SerialPluginRadio() : SinglePortPlugin("SerialPluginRadio", PortNum_SERIAL_APP) {} /** * Send our payload into the mesh From f68a31ab28f004d64340561d1fc204025c6ffe84 Mon Sep 17 00:00:00 2001 From: Jm Date: Wed, 13 Jan 2021 23:21:55 -0800 Subject: [PATCH 27/32] serialplugin - ability to configure ACK --- src/plugins/SerialPlugin.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/plugins/SerialPlugin.cpp b/src/plugins/SerialPlugin.cpp index daf0c8c2..a0f071ef 100644 --- a/src/plugins/SerialPlugin.cpp +++ b/src/plugins/SerialPlugin.cpp @@ -32,10 +32,16 @@ 7) (Optional) Set SERIALPLUGIN_ECHO to 1 and any message you send out will be echoed back to your device. - TODO: + TODO (in this order): * Once protobufs regenerated with the new port, update SerialPlugin.h - * Implement an interface to enable / disable ack * Ensure this works on a tbeam + * Define a verbose RX mode to report on mesh and packet infomration. + - This won't happen any time soon. + + KNOWN PROBLEMS + * Until the plugin is initilized by the startup sequence, the TX pin is in a floating + state. Device connected to that pin may see this as "noise". + */ @@ -43,10 +49,11 @@ #define TXD2 17 #define SERIALPLUGIN_RX_BUFFER 128 #define SERIALPLUGIN_STRING_MAX Constants_DATA_PAYLOAD_LEN -#define SERIALPLUGIN_TIMEOUT 100 +#define SERIALPLUGIN_TIMEOUT 250 #define SERIALPLUGIN_BAUD 38400 -#define SERIALPLUGIN_ENABLED 0 +#define SERIALPLUGIN_ENABLED 1 #define SERIALPLUGIN_ECHO 0 +#define SERIALPLUGIN_ACK 0 SerialPlugin *serialPlugin; SerialPluginRadio *serialPluginRadio; @@ -108,6 +115,8 @@ void SerialPluginRadio::sendPayload(NodeNum dest, bool wantReplies) p->to = dest; p->decoded.want_response = wantReplies; + p->want_ack = SERIALPLUGIN_ACK; + p->decoded.data.payload.size = strlen(serialStringChar); // You must specify how many bytes are in the reply memcpy(p->decoded.data.payload.bytes, serialStringChar, p->decoded.data.payload.size); From e39506824d547da2c6204473b517d316346faa9f Mon Sep 17 00:00:00 2001 From: Jm Date: Thu, 14 Jan 2021 18:08:23 -0800 Subject: [PATCH 28/32] Added more comments --- src/plugins/SerialPlugin.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/plugins/SerialPlugin.cpp b/src/plugins/SerialPlugin.cpp index a0f071ef..cc355c06 100644 --- a/src/plugins/SerialPlugin.cpp +++ b/src/plugins/SerialPlugin.cpp @@ -9,7 +9,11 @@ #include /* - Designed for lora32 v1.0 + SerialPlugin + An overly simplistic interface to send messages over the mesh network by sending strings + over a serial port. + + Originally designed for lora32 v1.0 Manufacture Info: http://www.lilygo.cn/prod_view.aspx?TypeId=50003&Id=1133&FId=t3:50003:3 Pin Mapping: http://ae01.alicdn.com/kf/HTB1fLBcxkSWBuNjSszdq6zeSpXaJ.jpg From 507cd1dd20e9b587ae3dd6e34a78f805344bdff0 Mon Sep 17 00:00:00 2001 From: Jm Date: Thu, 14 Jan 2021 18:40:18 -0800 Subject: [PATCH 29/32] #639 - Move from counting seconds to milliseconds --- src/airtime.cpp | 26 ++++++++++---------------- src/airtime.h | 2 +- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/airtime.cpp b/src/airtime.cpp index 66f4a0a5..8d1800d5 100644 --- a/src/airtime.cpp +++ b/src/airtime.cpp @@ -5,10 +5,6 @@ AirTime *airTime; -// A reminder that there are 3600 seconds in an hour so I don't have -// to keep googling it. -// This can be changed to a smaller number to speed up testing. -// uint32_t secondsPerPeriod = 3600; uint32_t lastMillis = 0; uint32_t secSinceBoot = 0; @@ -17,25 +13,23 @@ uint32_t secSinceBoot = 0; // Don't read out of this directly. Use the helper functions. struct airtimeStruct { - uint16_t periodTX[periodsToLog]; // AirTime transmitted - uint16_t periodRX[periodsToLog]; // AirTime received and repeated (Only valid mesh packets) - uint16_t periodRX_ALL[periodsToLog]; // AirTime received regardless of valid mesh packet. Could include noise. + uint32_t periodTX[periodsToLog]; // AirTime transmitted + uint32_t periodRX[periodsToLog]; // AirTime received and repeated (Only valid mesh packets) + uint32_t periodRX_ALL[periodsToLog]; // AirTime received regardless of valid mesh packet. Could include noise. uint8_t lastPeriodIndex; } airtimes; void AirTime::logAirtime(reportTypes reportType, uint32_t airtime_ms) { - // DEBUG_MSG("Packet - logAirtime()\n"); - if (reportType == TX_LOG) { - DEBUG_MSG("AirTime - Packet transmitted : %us %ums\n", (uint32_t)round((float)airtime_ms / (float)1000), airtime_ms); - airtimes.periodTX[0] = airtimes.periodTX[0] + round(airtime_ms / 1000); + DEBUG_MSG("AirTime - Packet transmitted : %ums\n", airtime_ms); + airtimes.periodTX[0] = airtimes.periodTX[0] + airtime_ms; } else if (reportType == RX_LOG) { - DEBUG_MSG("AirTime - Packet received : %us %ums\n", (uint32_t)round((float)airtime_ms / (float)1000), airtime_ms); - airtimes.periodRX[0] = airtimes.periodRX[0] + round(airtime_ms / 1000); + DEBUG_MSG("AirTime - Packet received : %ums\n", airtime_ms); + airtimes.periodRX[0] = airtimes.periodRX[0] + airtime_ms; } else if (reportType == RX_ALL_LOG) { - DEBUG_MSG("AirTime - Packet received (noise?) : %us %ums\n", (uint32_t)round((float)airtime_ms / (float)1000), airtime_ms); - airtimes.periodRX_ALL[0] = airtimes.periodRX_ALL[0] + round(airtime_ms / 1000); + DEBUG_MSG("AirTime - Packet received (noise?) : %ums\n", airtime_ms); + airtimes.periodRX_ALL[0] = airtimes.periodRX_ALL[0] + airtime_ms; } else { DEBUG_MSG("AirTime - Unknown report time. This should never happen!!\n"); } @@ -65,7 +59,7 @@ void airtimeRotatePeriod() } } -uint16_t *airtimeReport(reportTypes reportType) +uint32_t *airtimeReport(reportTypes reportType) { if (reportType == TX_LOG) { diff --git a/src/airtime.h b/src/airtime.h index 43967001..d78db86a 100644 --- a/src/airtime.h +++ b/src/airtime.h @@ -34,7 +34,7 @@ uint8_t getPeriodsToLog(); uint32_t getSecondsSinceBoot(); -uint16_t *airtimeReport(reportTypes reportType); +uint32_t *airtimeReport(reportTypes reportType); uint32_t getSecondsPerPeriod(); From 3598c91c296f535b324da956da9da4e8be42578f Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Fri, 15 Jan 2021 13:21:33 +0800 Subject: [PATCH 30/32] fix @mc-hamster build to work on linux/nrf52 --- platformio.ini | 4 ++-- src/graphics/EInkDisplay.cpp | 1 - src/graphics/Screen.cpp | 2 +- src/main.cpp | 4 ++-- src/mesh/NodeDB.cpp | 2 +- src/mesh/{wifi => http}/ContentHelper.cpp | 2 +- src/mesh/{wifi => http}/ContentHelper.h | 0 src/mesh/{wifi => http}/ContentStatic.h | 0 src/mesh/{wifi => http}/WebServer.cpp | 8 ++++---- src/mesh/{wifi => http}/WebServer.h | 0 src/mesh/{wifi => http}/WiFiAPClient.cpp | 6 +++--- src/mesh/{wifi => http}/WiFiAPClient.h | 0 src/nimble/BluetoothUtil.cpp | 2 +- 13 files changed, 15 insertions(+), 16 deletions(-) rename src/mesh/{wifi => http}/ContentHelper.cpp (91%) rename src/mesh/{wifi => http}/ContentHelper.h (100%) rename src/mesh/{wifi => http}/ContentStatic.h (100%) rename src/mesh/{wifi => http}/WebServer.cpp (99%) rename src/mesh/{wifi => http}/WebServer.h (100%) rename src/mesh/{wifi => http}/WiFiAPClient.cpp (99%) rename src/mesh/{wifi => http}/WiFiAPClient.h (100%) diff --git a/platformio.ini b/platformio.ini index 67199199..1f962a8d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -188,7 +188,7 @@ build_flags = -Isdk-nrfxlib/crypto/nrf_oberon/include -Lsdk-nrfxlib/crypto/nrf_oberon/lib/cortex-m4/hard-float/ -lliboberon_3.0.3 ;-DCFG_DEBUG=3 src_filter = - ${arduino_base.src_filter} - - - - + ${arduino_base.src_filter} - - - - lib_ignore = BluetoothOTA monitor_port = /dev/ttyACM1 @@ -315,7 +315,7 @@ lib_deps = ; The Portduino based sim environment on top of linux [env:linux] platform = https://github.com/geeksville/platform-portduino.git -src_filter = ${env.src_filter} - - - - +src_filter = ${env.src_filter} - - - - build_flags = ${arduino_base.build_flags} -O0 framework = arduino board = linux_x86_64 diff --git a/src/graphics/EInkDisplay.cpp b/src/graphics/EInkDisplay.cpp index 0d5e8307..2b530c0c 100644 --- a/src/graphics/EInkDisplay.cpp +++ b/src/graphics/EInkDisplay.cpp @@ -4,7 +4,6 @@ #include "EInkDisplay.h" #include "SPILock.h" #include "epd1in54.h" // Screen specific library -#include "graphics/configs.h" #include #include // Graphics library and Sprite class diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 97b24df3..6f022943 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -36,7 +36,7 @@ along with this program. If not, see . #include "utils.h" #ifndef NO_ESP32 -#include "mesh/wifi/WiFiAPClient.h" +#include "mesh/http/WiFiAPClient.h" #endif using namespace meshtastic; /** @todo remove */ diff --git a/src/main.cpp b/src/main.cpp index 605b9196..b63c193a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,8 +27,8 @@ // #include #ifndef NO_ESP32 -#include "mesh/wifi/WebServer.h" -#include "mesh/wifi/WiFiAPClient.h" +#include "mesh/http/WebServer.h" +#include "mesh/http/WiFiAPClient.h" #include "nimble/BluetoothUtil.h" #endif diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index a2a1e316..dc13bc42 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -20,7 +20,7 @@ #include #ifndef NO_ESP32 -#include "mesh/wifi/WiFiAPClient.h" +#include "mesh/http/WiFiAPClient.h" #endif NodeDB nodeDB; diff --git a/src/mesh/wifi/ContentHelper.cpp b/src/mesh/http/ContentHelper.cpp similarity index 91% rename from src/mesh/wifi/ContentHelper.cpp rename to src/mesh/http/ContentHelper.cpp index 96dec5d9..249dcbde 100644 --- a/src/mesh/wifi/ContentHelper.cpp +++ b/src/mesh/http/ContentHelper.cpp @@ -1,4 +1,4 @@ -#include "mesh/wifi/ContentHelper.h" +#include "mesh/http/ContentHelper.h" //#include //#include "main.h" diff --git a/src/mesh/wifi/ContentHelper.h b/src/mesh/http/ContentHelper.h similarity index 100% rename from src/mesh/wifi/ContentHelper.h rename to src/mesh/http/ContentHelper.h diff --git a/src/mesh/wifi/ContentStatic.h b/src/mesh/http/ContentStatic.h similarity index 100% rename from src/mesh/wifi/ContentStatic.h rename to src/mesh/http/ContentStatic.h diff --git a/src/mesh/wifi/WebServer.cpp b/src/mesh/http/WebServer.cpp similarity index 99% rename from src/mesh/wifi/WebServer.cpp rename to src/mesh/http/WebServer.cpp index 2f263e21..e22ebb27 100644 --- a/src/mesh/wifi/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -1,11 +1,11 @@ -#include "mesh/wifi/WebServer.h" +#include "mesh/http/WebServer.h" #include "NodeDB.h" #include "PowerFSM.h" #include "airtime.h" #include "main.h" -#include "mesh/wifi/ContentHelper.h" -#include "mesh/wifi/ContentStatic.h" -#include "mesh/wifi/WiFiAPClient.h" +#include "mesh/http/ContentHelper.h" +#include "mesh/http/ContentStatic.h" +#include "mesh/http/WiFiAPClient.h" #include "sleep.h" #include #include diff --git a/src/mesh/wifi/WebServer.h b/src/mesh/http/WebServer.h similarity index 100% rename from src/mesh/wifi/WebServer.h rename to src/mesh/http/WebServer.h diff --git a/src/mesh/wifi/WiFiAPClient.cpp b/src/mesh/http/WiFiAPClient.cpp similarity index 99% rename from src/mesh/wifi/WiFiAPClient.cpp rename to src/mesh/http/WiFiAPClient.cpp index 32989b2b..3ecd7235 100644 --- a/src/mesh/wifi/WiFiAPClient.cpp +++ b/src/mesh/http/WiFiAPClient.cpp @@ -1,9 +1,9 @@ -#include "mesh/wifi/WiFiAPClient.h" +#include "mesh/http/WiFiAPClient.h" #include "NodeDB.h" -#include "mesh/wifi/WiFiServerAPI.h" #include "configuration.h" #include "main.h" -#include "mesh/wifi/WebServer.h" +#include "mesh/http/WebServer.h" +#include "mesh/wifi/WiFiServerAPI.h" #include "target_specific.h" #include #include diff --git a/src/mesh/wifi/WiFiAPClient.h b/src/mesh/http/WiFiAPClient.h similarity index 100% rename from src/mesh/wifi/WiFiAPClient.h rename to src/mesh/http/WiFiAPClient.h diff --git a/src/nimble/BluetoothUtil.cpp b/src/nimble/BluetoothUtil.cpp index 86cd2074..f5f1f77e 100644 --- a/src/nimble/BluetoothUtil.cpp +++ b/src/nimble/BluetoothUtil.cpp @@ -14,7 +14,7 @@ #include #ifndef NO_ESP32 -#include "mesh/wifi/WiFiAPClient.h" +#include "mesh/http/WiFiAPClient.h" #endif static bool pinShowing; From 4ec8986934756e99afc16579af1a4dad8cf177db Mon Sep 17 00:00:00 2001 From: Jm Date: Thu, 14 Jan 2021 21:45:41 -0800 Subject: [PATCH 31/32] Fixed switching to uint32 from 16 for airtime in json report --- src/mesh/http/WebServer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mesh/http/WebServer.cpp b/src/mesh/http/WebServer.cpp index e22ebb27..1c1b5a82 100644 --- a/src/mesh/http/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -1110,13 +1110,13 @@ void handleReport(HTTPRequest *req, HTTPResponse *res) res->println("\"airtime\": {"); - uint16_t *logArray; + uint32_t *logArray; res->print("\"tx_log\": ["); logArray = airtimeReport(TX_LOG); for (int i = 0; i < getPeriodsToLog(); i++) { - uint16_t tmp; + uint32_t tmp; tmp = *(logArray + i); res->printf("%d", tmp); if (i != getPeriodsToLog() - 1) { @@ -1129,7 +1129,7 @@ void handleReport(HTTPRequest *req, HTTPResponse *res) logArray = airtimeReport(RX_LOG); for (int i = 0; i < getPeriodsToLog(); i++) { - uint16_t tmp; + uint32_t tmp; tmp = *(logArray + i); res->printf("%d", tmp); if (i != getPeriodsToLog() - 1) { @@ -1142,7 +1142,7 @@ void handleReport(HTTPRequest *req, HTTPResponse *res) logArray = airtimeReport(RX_ALL_LOG); for (int i = 0; i < getPeriodsToLog(); i++) { - uint16_t tmp; + uint32_t tmp; tmp = *(logArray + i); res->printf("%d", tmp); if (i != getPeriodsToLog() - 1) { From bd857362268ed217f370c69af34a2e7a9e7b30f9 Mon Sep 17 00:00:00 2001 From: Jm Date: Thu, 14 Jan 2021 21:59:26 -0800 Subject: [PATCH 32/32] SerialPlugin - Exclude working on non esp32 platforms. --- src/plugins/SerialPlugin.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/plugins/SerialPlugin.cpp b/src/plugins/SerialPlugin.cpp index cc355c06..82c8baf8 100644 --- a/src/plugins/SerialPlugin.cpp +++ b/src/plugins/SerialPlugin.cpp @@ -37,6 +37,7 @@ to your device. TODO (in this order): + * Add check for esp32 and only build code sections for esp32. * Once protobufs regenerated with the new port, update SerialPlugin.h * Ensure this works on a tbeam * Define a verbose RX mode to report on mesh and packet infomration. @@ -45,6 +46,7 @@ KNOWN PROBLEMS * Until the plugin is initilized by the startup sequence, the TX pin is in a floating state. Device connected to that pin may see this as "noise". + * This will not work on the NRF or Linux target. */ @@ -55,7 +57,7 @@ #define SERIALPLUGIN_STRING_MAX Constants_DATA_PAYLOAD_LEN #define SERIALPLUGIN_TIMEOUT 250 #define SERIALPLUGIN_BAUD 38400 -#define SERIALPLUGIN_ENABLED 1 +#define SERIALPLUGIN_ENABLED 0 #define SERIALPLUGIN_ECHO 0 #define SERIALPLUGIN_ACK 0 @@ -68,6 +70,7 @@ char serialStringChar[Constants_DATA_PAYLOAD_LEN]; int32_t SerialPlugin::runOnce() { +#ifdef NO_ESP32 #if SERIALPLUGIN_ENABLED == 1 @@ -103,6 +106,8 @@ int32_t SerialPlugin::runOnce() return (INT32_MAX); #endif + +#endif } MeshPacket *SerialPluginRadio::allocReply() @@ -129,6 +134,11 @@ void SerialPluginRadio::sendPayload(NodeNum dest, bool wantReplies) bool SerialPluginRadio::handleReceived(const MeshPacket &mp) { + +#ifdef NO_ESP32 + +#if SERIALPLUGIN_ENABLED == 1 + auto &p = mp.decoded.data; // DEBUG_MSG("Received text msg self=0x%0x, from=0x%0x, to=0x%0x, id=%d, msg=%.*s\n", nodeDB.getNodeNum(), // mp.from, mp.to, mp.id, p.payload.size, p.payload.bytes); @@ -157,5 +167,12 @@ bool SerialPluginRadio::handleReceived(const MeshPacket &mp) Serial2.printf("%s", p.payload.bytes); } +#else + DEBUG_MSG("Serial Plugin Disabled\n"); + +#endif + +#endif + return true; // Let others look at this message also if they want }