From ee70b5996f5268f25b971942486b635c71ba3d6a Mon Sep 17 00:00:00 2001 From: Jm Casler Date: Tue, 14 Dec 2021 22:38:54 -0500 Subject: [PATCH 1/2] 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/2] 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;