Merge upstream/dev (9 commits) [upstream-sync]
tth-docs / site (push) Successful in 20s
pub-release / release (push) Successful in 30m29s

This commit is contained in:
tth committed 2026-12-02 00:55:34 +01:00
commit c097b08b62
6 files changed
+143 -53

No files matched your search

+1
View File
@@ -22,6 +22,7 @@ Once you have a working app/project, you need to be able to demonstrate it exist
| 0140 | Nelos | support@nelos.app — https://nelos.app | | 0140 | Nelos | support@nelos.app — https://nelos.app |
| 0150 | Road Events | juraj@bednar.io — https://github.com/jooray/roadbeacon/blob/main/nips/road-events.md | | 0150 | Road Events | juraj@bednar.io — https://github.com/jooray/roadbeacon/blob/main/nips/road-events.md |
| 0160 | Knit | jeff@getknit.app — https://getknit.app | | 0160 | Knit | jeff@getknit.app — https://getknit.app |
| 0170 | MeshTrax | venahamtrack@gmail.com — https://github.com/venamartin/meshtrax |
| FF00 - FFFF | -reserved for testing/dev- | | | FF00 - FFFF | -reserved for testing/dev- | |
(add rows, inside the range 0100 - FEFF for custom apps) (add rows, inside the range 0100 - FEFF for custom apps)
+17
View File
@@ -11,6 +11,9 @@
// first accepted sync), so a spoofer cannot walk the clock away. // first accepted sync), so a spoofer cannot walk the clock away.
// A trusted fix that keeps disagreeing with the clock by the same offset raises an alert; // A trusted fix that keeps disagreeing with the clock by the same offset raises an alert;
// the operator can then accept that GPS time (acceptAlertedTime()). // the operator can then accept that GPS time (acceptAlertedTime()).
//
// epochFromFields() is always available, with or without GPS_GUARD: the location providers use it
// to turn the receiver's date and time into an epoch.
#include <Arduino.h> #include <Arduino.h>
#include <MeshCore.h> #include <MeshCore.h>
@@ -106,6 +109,20 @@ class GpsGuard {
} }
public: public:
// UTC date and time fields as reported by a receiver -> Unix epoch, or 0 if any field is out of
// range. Receivers (and their libraries) hand these over unchecked: MicroNMEA turns any two
// characters into a value 0..255, and both RTClib's DateTime and SparkFun's getUnixEpoch() index
// their days-per-month tables with the month without a range check.
static uint32_t epochFromFields(uint16_t year, uint8_t month, uint8_t day,
uint8_t hour, uint8_t minute, uint8_t second) {
static const uint8_t days_in_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (year < 2020 || year > 2099 || month < 1 || month > 12) return 0;
uint8_t mdays = days_in_month[month - 1];
if (month == 2 && year % 4 == 0) mdays = 29; // 2020..2099: every fourth year is a leap year
if (day < 1 || day > mdays || hour > 23 || minute > 59 || second > 60) return 0; // 60: leap second
return DateTime(year, month, day, hour, minute, second).unixtime();
}
// Plausible GPS time window: not before this firmware was built, at most 10 years after. // Plausible GPS time window: not before this firmware was built, at most 10 years after.
static uint32_t minEpoch() { static uint32_t minEpoch() {
static const uint32_t min_epoch = DateTime(__DATE__, __TIME__).unixtime() - 86400; static const uint32_t min_epoch = DateTime(__DATE__, __TIME__).unixtime() - 86400;
@@ -5,9 +5,7 @@
#include <MicroNMEA.h> #include <MicroNMEA.h>
#include <RTClib.h> #include <RTClib.h>
#include <string.h> #include <string.h>
#ifdef GPS_GUARD #include "GpsGuard.h" // epochFromFields(); the guard itself only with GPS_GUARD
#include "GpsGuard.h"
#endif
#ifndef GPS_PERIODIC_ACQUISITION_TIMEOUT_MS #ifndef GPS_PERIODIC_ACQUISITION_TIMEOUT_MS
#define GPS_PERIODIC_ACQUISITION_TIMEOUT_MS 300000UL #define GPS_PERIODIC_ACQUISITION_TIMEOUT_MS 300000UL
@@ -161,7 +159,7 @@ class MicroNMEALocationProvider : public LocationProvider {
(millis() - _last_time_sync) > TIME_SYNC_INTERVAL) { (millis() - _last_time_sync) > TIME_SYNC_INTERVAL) {
_time_sync_needed = true; _time_sync_needed = true;
} }
if (_time_sync_needed && time_valid > 2 && _clock != nullptr && timeSyncAllowed()) { if (_time_sync_needed && time_valid > 2 && _clock != nullptr && currentEpoch() != 0 && timeSyncAllowed()) {
_clock->setCurrentTime(getTimestamp()); _clock->setCurrentTime(getTimestamp());
_time_sync_needed = false; _time_sync_needed = false;
_last_time_sync = millis(); _last_time_sync = millis();
@@ -175,6 +173,12 @@ class MicroNMEALocationProvider : public LocationProvider {
return _clock == nullptr || !_time_sync_needed || time_valid > 3; return _clock == nullptr || !_time_sync_needed || time_valid > 3;
} }
// the receiver's current date and time, or 0 if a field is out of range
uint32_t currentEpoch() {
return GpsGuard::epochFromFields(nmea.getYear(), nmea.getMonth(), nmea.getDay(),
nmea.getHour(), nmea.getMinute(), nmea.getSecond());
}
bool timeSyncAllowed() { bool timeSyncAllowed() {
#ifdef GPS_GUARD #ifdef GPS_GUARD
return _guard.acceptTime(getTimestamp(), _clock->getCurrentTime()); return _guard.acceptTime(getTimestamp(), _clock->getCurrentTime());
@@ -299,14 +303,14 @@ public:
// GPS time minus clock time, from a current fix with a settled time // GPS time minus clock time, from a current fix with a settled time
bool getClockOffset(long& offset) override { bool getClockOffset(long& offset) override {
if (_clock == nullptr || !isValid() || time_valid < 3) return false; if (_clock == nullptr || !isValid() || time_valid < 3 || currentEpoch() == 0) return false;
offset = (long)getTimestamp() - (long)_clock->getCurrentTime(); offset = (long)getTimestamp() - (long)_clock->getCurrentTime();
return true; return true;
} }
// write the current GPS time to the clock now (caller has done its own checks) // write the current GPS time to the clock now (caller has done its own checks)
bool applyTimeNow() override { bool applyTimeNow() override {
if (_clock == nullptr || !isValid() || time_valid < 3) return false; if (_clock == nullptr || !isValid() || time_valid < 3 || currentEpoch() == 0) return false;
_clock->setCurrentTime(getTimestamp()); _clock->setCurrentTime(getTimestamp());
_time_sync_needed = false; _time_sync_needed = false;
_last_time_sync = millis(); _last_time_sync = millis();
@@ -319,9 +323,8 @@ public:
long getTimestamp() override { long getTimestamp() override {
if (!nmea.isValid()) return _lastFix.timestamp; if (!nmea.isValid()) return _lastFix.timestamp;
DateTime dt(nmea.getYear(), nmea.getMonth(), nmea.getDay(), uint32_t t = currentEpoch();
nmea.getHour(), nmea.getMinute(), nmea.getSecond()); return t != 0 ? t : _lastFix.timestamp;
return dt.unixtime();
} }
void drain() override { _driver->drain(); } void drain() override { _driver->drain(); }
+18 -2
View File
@@ -3,6 +3,7 @@
#include "GpsDriver.h" #include "GpsDriver.h"
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> #include <SparkFun_u-blox_GNSS_Arduino_Library.h>
#include "GpsGuard.h" // epochFromFields()
// Driver for the RAK12500 (u-blox, I2C). Serial NMEA modules are handled by NmeaGpsDriver. // Driver for the RAK12500 (u-blox, I2C). Serial NMEA modules are handled by NmeaGpsDriver.
class RakI2cGpsDriver : public GpsDriver { class RakI2cGpsDriver : public GpsDriver {
@@ -11,6 +12,7 @@ class RakI2cGpsDriver : public GpsDriver {
uint8_t _powerPin = 0; uint8_t _powerPin = 0;
bool _detected = false; bool _detected = false;
bool _started = false; bool _started = false;
bool _pvtSeen = false; // a NAV-PVT has been received since boot
bool probeRak12500(uint8_t powerPin) { bool probeRak12500(uint8_t powerPin) {
#if defined(ETHERNET_ENABLED) && defined(RAK_BOARD) #if defined(ETHERNET_ENABLED) && defined(RAK_BOARD)
@@ -95,10 +97,24 @@ public:
bool isDetected() const { return _detected; } bool isDetected() const { return _detected; }
bool hasFix() { return _started && _gnss.getGnssFixOk(8); } bool hasFix() {
if (!_started) return false;
// The library allocates its NAV-PVT record without clearing it: until the first reply has
// arrived, the fix flag and every other field are whatever was on the heap.
if (!_pvtSeen) {
if (!_gnss.getPVT(8)) return false;
_pvtSeen = true;
}
return _gnss.getGnssFixOk(8);
}
long getLatitude() { return _gnss.getLatitude(2) / 10; } long getLatitude() { return _gnss.getLatitude(2) / 10; }
long getLongitude() { return _gnss.getLongitude(2) / 10; } long getLongitude() { return _gnss.getLongitude(2) / 10; }
long getAltitude() { return _gnss.getAltitude(2); } long getAltitude() { return _gnss.getAltitude(2); }
long getSatellites() { return _gnss.getSIV(2); } long getSatellites() { return _gnss.getSIV(2); }
long getTimestamp() { return _gnss.getUnixEpoch(2); } // Not getUnixEpoch(): it indexes its day tables with the module's year and month unchecked.
// 0 (no time; RakLocationProvider then leaves the clock alone) for a date or time out of range.
long getTimestamp() {
return GpsGuard::epochFromFields(_gnss.getYear(2), _gnss.getMonth(2), _gnss.getDay(2),
_gnss.getHour(2), _gnss.getMinute(2), _gnss.getSecond(2));
}
}; };
+93 -42
View File
@@ -340,53 +340,104 @@ public:
} }
if (_page == HomePage::FIRST) { if (_page == HomePage::FIRST) {
display.setColor(UIColor::primary_txt); static constexpr uint32_t MIN_VALID_RTC_EPOCH = 1735689600UL; // 2025-01-01 00:00:00 UTC
#ifdef ENABLE_WIFI_INTERFACE uint32_t raw_now = _rtc->getCurrentTime();
// smaller unread message ui for wifi variants bool rtc_valid = (raw_now >= MIN_VALID_RTC_EPOCH);
display.setTextSize(1); const bool compact_screen = (display.height() < 120);
sprintf(tmp, "Unread Msg: %d", _task->getMsgCount());
display.drawTextCentered(display.width() / 2, 22, tmp); char time_str[8] = "--:--";
#else char date_str[12] = "";
// larger unread message ui for non wifi variants
display.setTextSize(2);
sprintf(tmp, "MSG: %d", _task->getMsgCount());
display.drawTextCentered(display.width() / 2, 22, tmp);
#endif
if (_node_prefs->ui_show_clock) { if (_node_prefs->ui_show_clock) {
display.setTextSize(3); if (rtc_valid) {
uint32_t now = _rtc->getCurrentTime(); uint32_t local_now = (uint32_t)((int64_t)raw_now + (int64_t)(_node_prefs->tz_offset * 3600.0f));
now += (int32_t)(_node_prefs->tz_offset * 3600); DateTime dt (local_now);
DateTime dt (now); snprintf(time_str, sizeof(time_str), "%02d:%02d", dt.hour(), dt.minute());
sprintf(tmp, "%02d:%02d", dt.hour(), dt.minute()); if (compact_screen) {
display.drawTextCentered(display.width() / 2, 60, tmp); snprintf(date_str, sizeof(date_str), "%02d/%02d/%02d", dt.day(), dt.month(), dt.year() % 100);
display.setTextSize(1); } else {
sprintf(tmp, "%02d/%02d/%d", dt.day(), dt.month(), dt.year()); snprintf(date_str, sizeof(date_str), "%02d/%02d/%d", dt.day(), dt.month(), dt.year());
display.drawTextCentered(display.width() / 2, 80, tmp); }
} else {
strcpy(date_str, compact_screen ? "--/--/--" : "--/--/----");
}
} }
#ifdef ENABLE_WIFI_INTERFACE
if (_node_prefs->ui_show_clock && compact_screen) {
display.setColor(UIColor::primary_txt);
display.setTextSize(1);
snprintf(tmp, sizeof(tmp), "MSG:%d", _task->getMsgCount());
display.drawTextLeftAlign(0, 19, tmp);
display.setColor(UIColor::secondary_txt);
display.drawTextRightAlign(display.width() - 1, 19, date_str);
display.setColor(UIColor::primary_txt);
#ifdef ENABLE_WIFI_INTERFACE
display.setTextSize(1);
display.drawTextCentered(display.width() / 2, 29, time_str);
IPAddress ip = WiFi.localIP(); IPAddress ip = WiFi.localIP();
snprintf(tmp, sizeof(tmp), "IP: %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); snprintf(tmp, sizeof(tmp), "IP: %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
display.setTextSize(1); display.drawTextCentered(display.width() / 2, 40, tmp);
display.drawTextCentered(display.width() / 2, 32, tmp); #else
#endif display.setTextSize(2);
if (_task->hasConnection()) { display.drawTextCentered(display.width() / 2, 30, time_str);
display.setColor(UIColor::warning_txt); #endif
display.setTextSize(1);
if (_node_prefs->ui_show_clock) if (_task->hasConnection()) {
display.drawTextCentered(display.width() / 2, 110, "< Connected >"); display.setColor(UIColor::warning_txt);
else
display.drawTextCentered(display.width() / 2, 43, "< Connected >");
// CUSTOM (TeTeHacko): jen kdyz BT opravdu bezi -- jinak displej nabizi PIN
// k parovani, ktere neni jak navazat.
} else if (_task->getBLEPin() != 0 && _task->isBluetoothEnabled()) { // BT pin
display.setColor(UIColor::warning_txt);
sprintf(tmp, "Pin:%d", _task->getBLEPin());
if (_node_prefs->ui_show_clock) {
display.setTextSize(1); display.setTextSize(1);
display.drawTextCentered(display.width() / 2, 110, tmp); display.drawTextCentered(display.width() / 2, 51, "< Connected >");
} else { // CUSTOM (TeTeHacko): jen kdyz BT opravdu bezi -- jinak displej nabizi PIN
display.setTextSize(2); // k parovani, ktere neni jak navazat.
display.drawTextCentered(display.width() / 2, 43, tmp); } else if (_task->getBLEPin() != 0 && _task->isBluetoothEnabled()) { // BT pin
display.setColor(UIColor::warning_txt);
display.setTextSize(1);
snprintf(tmp, sizeof(tmp), "Pin:%lu", (unsigned long)_task->getBLEPin());
display.drawTextCentered(display.width() / 2, 51, tmp);
}
} else {
display.setColor(UIColor::primary_txt);
#ifdef ENABLE_WIFI_INTERFACE
// smaller unread message ui for wifi variants
display.setTextSize(1);
sprintf(tmp, "Unread Msg: %d", _task->getMsgCount());
display.drawTextCentered(display.width() / 2, 22, tmp);
#else
// larger unread message ui for non wifi variants
display.setTextSize(2);
sprintf(tmp, "MSG: %d", _task->getMsgCount());
display.drawTextCentered(display.width() / 2, 22, tmp);
#endif
if (_node_prefs->ui_show_clock) {
display.setTextSize(3);
display.drawTextCentered(display.width() / 2, 60, time_str);
display.setTextSize(1);
display.drawTextCentered(display.width() / 2, 80, date_str);
}
#ifdef ENABLE_WIFI_INTERFACE
IPAddress ip = WiFi.localIP();
snprintf(tmp, sizeof(tmp), "IP: %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
display.setTextSize(1);
display.drawTextCentered(display.width() / 2, 32, tmp);
#endif
if (_task->hasConnection()) {
display.setColor(UIColor::warning_txt);
display.setTextSize(1);
if (_node_prefs->ui_show_clock)
display.drawTextCentered(display.width() / 2, 110, "< Connected >");
else
display.drawTextCentered(display.width() / 2, 43, "< Connected >");
// CUSTOM (TeTeHacko): jen kdyz BT opravdu bezi -- jinak displej nabizi PIN
// k parovani, ktere neni jak navazat.
} else if (_task->getBLEPin() != 0 && _task->isBluetoothEnabled()) { // BT pin
display.setColor(UIColor::warning_txt);
sprintf(tmp, "Pin:%lu", (unsigned long)_task->getBLEPin());
if (_node_prefs->ui_show_clock) {
display.setTextSize(1);
display.drawTextCentered(display.width() / 2, 110, tmp);
} else {
display.setTextSize(2);
display.drawTextCentered(display.width() / 2, 43, tmp);
}
} }
} }
} else if (_page == HomePage::RECENT) { } else if (_page == HomePage::RECENT) {
+2
View File
@@ -223,6 +223,7 @@ build_flags =
-D MAX_GROUP_CHANNELS=40 -D MAX_GROUP_CHANNELS=40
-D BLE_PIN_CODE=123456 -D BLE_PIN_CODE=123456
-D ENV_INCLUDE_GPS=1 ; enable the GPS page in UI -D ENV_INCLUDE_GPS=1 ; enable the GPS page in UI
-D UI_SHOW_CLOCK=1 ; show clock and date on home screen by default
; -D BLE_DEBUG_LOGGING=1 ; -D BLE_DEBUG_LOGGING=1
-D OFFLINE_QUEUE_SIZE=256 -D OFFLINE_QUEUE_SIZE=256
; -D MESH_PACKET_LOGGING=1 ; -D MESH_PACKET_LOGGING=1
@@ -245,6 +246,7 @@ build_flags =
-D MAX_CONTACTS=350 -D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40 -D MAX_GROUP_CHANNELS=40
-D ENABLE_USB_INTERFACE -D ENABLE_USB_INTERFACE
-D UI_SHOW_CLOCK=1 ; show clock and date on home screen by default
; -D BLE_PIN_CODE=123456 ; -D BLE_PIN_CODE=123456
; -D BLE_DEBUG_LOGGING=1 ; -D BLE_DEBUG_LOGGING=1
; -D MESH_PACKET_LOGGING=1 ; -D MESH_PACKET_LOGGING=1