From ee70b5996f5268f25b971942486b635c71ba3d6a Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Tue, 14 Dec 2021 22:38:54 -0500 Subject: [PATCH 1/9] Updated formula for position plugin --- src/plugins/PositionPlugin.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/plugins/PositionPlugin.cpp b/src/plugins/PositionPlugin.cpp index e0503930c..e10f05d1e 100644 --- a/src/plugins/PositionPlugin.cpp +++ b/src/plugins/PositionPlugin.cpp @@ -148,14 +148,22 @@ int32_t PositionPlugin::runOnce() NodeInfo *node = service.refreshMyNodeInfo(); // should guarantee there is now a position if (node->has_position && (node->position.latitude_i != 0 || node->position.longitude_i != 0)) { + // The minimum distance to travel before we are able to send a new position packet. + const uint32_t distanceTravelMinimum = 30; + + // The minimum time that would pass before we are able to send a new position packet. + const uint32_t timeTravelMinimum = 30; + + // Determine the distance in meters between two points on the globe float distance = GeoCoord::latLongToMeter(lastGpsLatitude * 1e-7, lastGpsLongitude * 1e-7, node->position.latitude_i * 1e-7, node->position.longitude_i * 1e-7); - // 2500 is a magic number. 50 is the minumum distance we want to travel before sending another position packet. - uint32_t distanceTravel = ((2500 / myNodeInfo.bitrate) >= 50) ? (2500 / myNodeInfo.bitrate) : 50; + // Yes, this has a bunch of magic numbers. Sorry. This is to make the scale non-linear. + const float distanceTravelMath = 1203 / (sqrt( pow(myNodeInfo.bitrate, 1.5) / 1.1 ) ) ; + uint32_t distanceTravel = (distanceTravelMath >= distanceTravelMinimum) ? distanceTravelMath : distanceTravelMinimum; - // 1500 is a magic number. 30 is the minumum interval between position packets - uint32_t timeTravel = ((1500 / myNodeInfo.bitrate) >= 30) ? (1500 / myNodeInfo.bitrate) : 30; + // Yes, this has a bunch of magic numbers. Sorry. + uint32_t timeTravel = ((1500 / myNodeInfo.bitrate) >= timeTravelMinimum) ? (1500 / myNodeInfo.bitrate) : timeTravelMinimum; // If the distance traveled since the last update is greater than 100 meters // and it's been at least 60 seconds since the last update From 62602b54f4bd55fc58d5c345f3536c5d7fb100bf Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Tue, 14 Dec 2021 23:50:49 -0500 Subject: [PATCH 2/9] Improve time to generate the SSL certificate --- src/graphics/Screen.cpp | 12 ++++++++++-- src/mesh/http/WebServer.cpp | 22 ++++++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 2b028a842..71cdad008 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -156,7 +156,11 @@ static void drawSSLScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16 display->drawString(64 + x, y, "Creating SSL certificate"); display->setFont(FONT_SMALL); - display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Please wait..."); + if ((millis() / 1000) % 2) { + display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Please wait . . ."); + } else { + display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Please wait . . "); + } } #ifdef HAS_EINK @@ -216,7 +220,11 @@ static void drawFrameFirmware(OLEDDisplay *display, OLEDDisplayUiState *state, i display->drawString(64 + x, y, "Updating"); display->setFont(FONT_SMALL); - display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Please wait..."); + if ((millis() / 1000) % 2) { + display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Please wait . . ."); + } else { + display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Please wait . . "); + } // display->setFont(FONT_LARGE); // display->drawString(64 + x, 26 + y, btPIN); diff --git a/src/mesh/http/WebServer.cpp b/src/mesh/http/WebServer.cpp index f9e2e99dc..9d370846b 100644 --- a/src/mesh/http/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include "sleep.h" #include #include @@ -79,12 +80,14 @@ static void taskCreateCert(void *parameter) prefs.begin("MeshtasticHTTPS", false); // Delete the saved certs (used in debugging) - if (0) { + +#if 0 DEBUG_MSG("Deleting any saved SSL keys ...\n"); // prefs.clear(); prefs.remove("PK"); prefs.remove("cert"); - } +#endif + DEBUG_MSG("Checking if we have a previously saved SSL Certificate.\n"); @@ -103,16 +106,12 @@ static void taskCreateCert(void *parameter) cert = new SSLCert(certBuffer, certLen, pkBuffer, pkLen); DEBUG_MSG("Retrieved Private Key: %d Bytes\n", cert->getPKLength()); - // DEBUG_MSG("Retrieved Private Key: " + String(cert->getPKLength()) + " Bytes"); - // for (int i = 0; i < cert->getPKLength(); i++) - // Serial.print(cert->getPKData()[i], HEX); - // Serial.println(); - DEBUG_MSG("Retrieved Certificate: %d Bytes\n", cert->getCertLength()); - // for (int i = 0; i < cert->getCertLength(); i++) - // Serial.print(cert->getCertData()[i], HEX); - // Serial.println(); + } else { + + setCPUFast(true); + DEBUG_MSG("Creating the certificate. This may take a while. Please wait...\n"); yield(); cert = new SSLCert(); @@ -144,6 +143,9 @@ static void taskCreateCert(void *parameter) prefs.putBytes("PK", (uint8_t *)cert->getPKData(), cert->getPKLength()); prefs.putBytes("cert", (uint8_t *)cert->getCertData(), cert->getCertLength()); } + + setCPUFast(false); + } isCertReady = true; From 5ff6b919c6bfc00a95e337a9da0f71a67a4db483 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 15 Dec 2021 07:50:36 -0600 Subject: [PATCH 3/9] Remove BATTERY_PIN from tlora v1 target (#996) --- src/configuration.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index 0d32e36fd..2bddcbb65 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -330,8 +330,6 @@ along with this program. If not, see . #define GPS_RX_PIN 36 #define GPS_TX_PIN 37 -#define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage - #define I2C_SDA 4 // I2C pins for this board #define I2C_SCL 15 From 5354c49c50fcf8b87a34bbfd307ab23fb2cc41fe Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Thu, 16 Dec 2021 13:53:59 -0500 Subject: [PATCH 4/9] Bump version to 1.2.49 --- version.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.properties b/version.properties index 5eae0b8b4..13eff275e 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ [VERSION] major = 1 minor = 2 -build = 48 +build = 49 From a27260a605e324d05d0ebe24beca6229f3549536 Mon Sep 17 00:00:00 2001 From: Vladislav Osmanov <7123463+osmanovv@users.noreply.github.com> Date: Fri, 17 Dec 2021 12:13:27 +0300 Subject: [PATCH 5/9] Overridden default pin to use for Ext Notify Plugin (#975) In Meshtastic DIY `GPIO13` is used for `SX126X_TXEN`, so we choose `GPIO12` as default for Ext Notification Plugin. --- src/configuration.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/configuration.h b/src/configuration.h index 2bddcbb65..597f60094 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -243,6 +243,7 @@ along with this program. If not, see . //#define GPS_TX_PIN 12 // not connected #define BUTTON_PIN 39 // The middle button GPIO on the T-Beam +#define EXT_NOTIFY_OUT 12 // Overridden default pin to use for Ext Notify Plugin (#975). #define LORA_DIO0 26 // a No connect on the SX1262/SX1268 module #define LORA_RESET 23 // RST for SX1276, and for SX1262/SX1268 From b71051a227ff35dac62c53b7cfd4bcf45d186ac2 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Fri, 17 Dec 2021 14:02:29 -0500 Subject: [PATCH 6/9] Attempt to address the ssl screen crashing on AndreK's device. --- src/graphics/Screen.cpp | 8 ++++- src/mesh/http/WebServer.cpp | 70 ++++++++++++------------------------- 2 files changed, 29 insertions(+), 49 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 71cdad008..ecf9953be 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -40,6 +40,7 @@ along with this program. If not, see . #ifndef NO_ESP32 #include "mesh/http/WiFiAPClient.h" +#include "esp_task_wdt.h" #endif using namespace meshtastic; /** @todo remove */ @@ -155,6 +156,11 @@ static void drawSSLScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16 display->setFont(FONT_SMALL); display->drawString(64 + x, y, "Creating SSL certificate"); +#ifndef NO_ESP32 + yield(); + esp_task_wdt_reset(); +#endif + display->setFont(FONT_SMALL); if ((millis() / 1000) % 2) { display->drawString(64 + x, FONT_HEIGHT_SMALL + y + 2, "Please wait . . ."); @@ -934,7 +940,7 @@ void Screen::drawDebugInfoWiFiTrampoline(OLEDDisplay *display, OLEDDisplayUiStat * it is expected that this will be used during the boot phase */ void Screen::setSSLFrames() { - DEBUG_MSG("showing SSL frames\n"); + // DEBUG_MSG("showing SSL frames\n"); static FrameCallback sslFrames[] = {drawSSLScreen}; ui.setFrames(sslFrames, 1); ui.update(); diff --git a/src/mesh/http/WebServer.cpp b/src/mesh/http/WebServer.cpp index 9d370846b..dea62765c 100644 --- a/src/mesh/http/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -79,13 +79,13 @@ static void taskCreateCert(void *parameter) { prefs.begin("MeshtasticHTTPS", false); - // Delete the saved certs (used in debugging) #if 0 - DEBUG_MSG("Deleting any saved SSL keys ...\n"); - // prefs.clear(); - prefs.remove("PK"); - prefs.remove("cert"); + // Delete the saved certs (used in debugging) + DEBUG_MSG("Deleting any saved SSL keys ...\n"); + // prefs.clear(); + prefs.remove("PK"); + prefs.remove("cert"); #endif @@ -156,6 +156,7 @@ static void taskCreateCert(void *parameter) void createSSLCert() { + bool runLoop = false; if (isWifiAvailable() && !isCertReady) { // Create a new process just to handle creating the cert. @@ -163,21 +164,28 @@ void createSSLCert() // jm@casler.org (Oct 2020) xTaskCreate(taskCreateCert, /* Task function. */ "createCert", /* String with name of task. */ - 16384, /* Stack size in bytes. */ + //16384, /* Stack size in bytes. */ + 8192, /* Stack size in bytes. */ NULL, /* Parameter passed as input of the task */ 16, /* Priority of the task. */ NULL); /* Task handle. */ DEBUG_MSG("Waiting for SSL Cert to be generated.\n"); - int seconds = 0; while (!isCertReady) { - DEBUG_MSG("."); - delay(1000); - yield(); - esp_task_wdt_reset(); - seconds++; - if ((seconds == 3) && screen) { - screen->setSSLFrames(); + if ((millis() / 500) % 2) { + if (runLoop) { + DEBUG_MSG("."); + + yield(); + esp_task_wdt_reset(); + + if ((millis() / 1000 >= 3) && screen) { + screen->setSSLFrames(); + } + } + runLoop = false; + } else { + runLoop = true; } } DEBUG_MSG("SSL Cert Ready!\n"); @@ -201,40 +209,6 @@ void initWebServer() { DEBUG_MSG("Initializing Web Server ...\n"); -#if 0 -// this seems to be a copypaste dup of taskCreateCert - prefs.begin("MeshtasticHTTPS", false); - - size_t pkLen = prefs.getBytesLength("PK"); - size_t certLen = prefs.getBytesLength("cert"); - - DEBUG_MSG("Checking if we have a previously saved SSL Certificate.\n"); - - if (pkLen && certLen) { - - uint8_t *pkBuffer = new uint8_t[pkLen]; - prefs.getBytes("PK", pkBuffer, pkLen); - - uint8_t *certBuffer = new uint8_t[certLen]; - prefs.getBytes("cert", certBuffer, certLen); - - cert = new SSLCert(certBuffer, certLen, pkBuffer, pkLen); - - DEBUG_MSG("Retrieved Private Key: %d Bytes\n", cert->getPKLength()); - // DEBUG_MSG("Retrieved Private Key: " + String(cert->getPKLength()) + " Bytes"); - // for (int i = 0; i < cert->getPKLength(); i++) - // Serial.print(cert->getPKData()[i], HEX); - // Serial.println(); - - DEBUG_MSG("Retrieved Certificate: %d Bytes\n", cert->getCertLength()); - // for (int i = 0; i < cert->getCertLength(); i++) - // Serial.print(cert->getCertData()[i], HEX); - // Serial.println(); - } else { - DEBUG_MSG("Web Server started without SSL keys! How did this happen?\n"); - } -#endif - // We can now use the new certificate to setup our server as usual. secureServer = new HTTPSServer(cert); insecureServer = new HTTPServer(); From d1370071da5d6b449caa22f4aa7c5a30f6a53e96 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Fri, 17 Dec 2021 15:53:23 -0500 Subject: [PATCH 7/9] Test that the screen object has been created --- src/mesh/http/WebServer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mesh/http/WebServer.cpp b/src/mesh/http/WebServer.cpp index dea62765c..301b18ccb 100644 --- a/src/mesh/http/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -179,8 +179,9 @@ void createSSLCert() yield(); esp_task_wdt_reset(); - if ((millis() / 1000 >= 3) && screen) { - screen->setSSLFrames(); + if ((millis() / 1000 >= 3) && screen) { + if (screen) + screen->setSSLFrames(); } } runLoop = false; From f3fc88ac5d49976af4ace8d4a3d7d0471429903d Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sat, 18 Dec 2021 11:02:54 -0500 Subject: [PATCH 8/9] Test if screen address was found --- src/graphics/Screen.cpp | 11 +++++++---- src/graphics/Screen.h | 2 ++ src/mesh/http/WebServer.cpp | 7 ++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index ecf9953be..dc3f73d39 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -703,6 +703,7 @@ void _screen_header() Screen::Screen(uint8_t address, int sda, int scl) : OSThread("Screen"), cmdQueue(32), dispdev(address, sda, scl), ui(&dispdev) { + address_found = address; cmdQueue.setReader(this); } @@ -940,10 +941,12 @@ void Screen::drawDebugInfoWiFiTrampoline(OLEDDisplay *display, OLEDDisplayUiStat * it is expected that this will be used during the boot phase */ void Screen::setSSLFrames() { - // DEBUG_MSG("showing SSL frames\n"); - static FrameCallback sslFrames[] = {drawSSLScreen}; - ui.setFrames(sslFrames, 1); - ui.update(); + if (address_found) { + // DEBUG_MSG("showing SSL frames\n"); + static FrameCallback sslFrames[] = {drawSSLScreen}; + ui.setFrames(sslFrames, 1); + ui.update(); + } } // restore our regular frame list diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index e4b9044c7..9334fe43c 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -97,6 +97,8 @@ class Screen : public concurrency::OSThread Screen(const Screen &) = delete; Screen &operator=(const Screen &) = delete; + uint8_t address_found; + /// Initializes the UI, turns on the display, starts showing boot screen. // // Not thread safe - must be called before any other methods are called. diff --git a/src/mesh/http/WebServer.cpp b/src/mesh/http/WebServer.cpp index 301b18ccb..d073c16a0 100644 --- a/src/mesh/http/WebServer.cpp +++ b/src/mesh/http/WebServer.cpp @@ -6,6 +6,8 @@ #include #include #include "sleep.h" +#include "graphics/Screen.h" + #include #include @@ -179,9 +181,8 @@ void createSSLCert() yield(); esp_task_wdt_reset(); - if ((millis() / 1000 >= 3) && screen) { - if (screen) - screen->setSSLFrames(); + if (millis() / 1000 >= 3) { + screen->setSSLFrames(); } } runLoop = false; From 4fcd82d6f575f9108d963573296318e3e9b85071 Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Sat, 18 Dec 2021 15:51:44 -0500 Subject: [PATCH 9/9] updating proto submodule to latest --- proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto b/proto index 10e6857b1..26389cfa0 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 10e6857b1bd4a03ec16ec5cbaadf4f28293ab9a5 +Subproject commit 26389cfa05f4980f318cc5c4ddbe3770a7865251