Merge pull request from mc-hamster/master

Updated formula for position plugin & Improve time to generate the SSL certificate
This commit is contained in:
Jm Casler 2021-12-15 07:22:20 -08:00 committed by GitHub
commit 3dbc31e8f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 16 deletions

View File

@ -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);

View File

@ -5,6 +5,7 @@
#include <HTTPBodyParser.hpp>
#include <HTTPMultipartBodyParser.hpp>
#include <HTTPURLEncodedBodyParser.hpp>
#include "sleep.h"
#include <WebServer.h>
#include <WiFi.h>
@ -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;

View File

@ -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