Merge remote-tracking branch 'origin/master' into develop

This commit is contained in:
Ben Meadors
2026-03-28 07:26:46 -05:00
41 changed files with 625 additions and 130 deletions
@@ -1,3 +1,9 @@
Meta:
name: BananaPi-BPI-R4-sx1262
support: community
compatible:
- bananapi_bpi-r4 # OpenWrt target
Lora: Lora:
Module: sx1262 # BananaPi-BPI-R4 SPI via 26p GPIO Header Module: sx1262 # BananaPi-BPI-R4 SPI via 26p GPIO Header
## CS: 28 ## CS: 28
@@ -1,4 +1,10 @@
## https://www.mikroe.com/lr-iot-click ## https://www.mikroe.com/lr-iot-click
Meta:
name: OpenWRT One mikroBUS LR-IOT-CLICK
support: community
compatible:
- openwrt_one # OpenWrt target
Lora: Lora:
Module: lr1110 # OpenWRT ONE mikroBUS with LR-IOT-CLICK Module: lr1110 # OpenWRT ONE mikroBUS with LR-IOT-CLICK
# CS: 25 # CS: 25
@@ -1,3 +1,9 @@
Meta:
name: OpenWRT One mikroBUS sx1262
support: community
compatible:
- openwrt_one # OpenWrt target
Lora: Lora:
Module: sx1262 Module: sx1262
IRQ: 10 IRQ: 10
+28
View File
@@ -0,0 +1,28 @@
# meshtasticd configuration files
This directory contains YAML configuration files for meshtasticd. Each file describes a specific hardware configuration, including the LoRa module and pin assignments. These configurations are used by meshtasticd to correctly interface with the hardware.
## Metadata structure
Each configuration file includes a `Meta` section that provides information about the configuration.
This configuration is consumed by configuration-selection tools.
```yaml
Meta:
name: MeshAdv-Pi E22-900M30S # A unique identifier for this configuration.
support: community # community, official, or deprecated; determined by Meshtastic Leads.
compatible: # A list of compatible products or platforms.
- raspberry-pi
```
`name`: A unique identifier for the configuration, typically reflecting the hardware it supports.
`support`: Indicates the level of support for this configuration. It can be one of the following:
- `community`: Supported by the Meshtastic community. Meshtastic Members may not possess, or have not tested this configuration.
- `official`: Fully supported by Meshtastic. Meshtastic Members have tested and verified this configuration.
- `deprecated`: No longer recommended for deployment by Meshtastic.
`compatible`: A list of compatible products or platforms that can use this configuration.
This will vary depending on the intended use case / platform.
Multiple compatible entries can be included. E.g. Armbian `BOARD` value or OpenWrt `TARGET` value.
These tags can be consumed by different configuration-selection tools, filtering based upon their platform/etc.
+6
View File
@@ -1,3 +1,9 @@
Meta:
name: Waveshare 1.44inch LCD HAT
support: community
compatible:
- raspberry-pi
### Waveshare 1.44inch LCD HAT ### Waveshare 1.44inch LCD HAT
Display: Display:
Panel: ST7735S Panel: ST7735S
+6
View File
@@ -1,3 +1,9 @@
Meta:
name: Waveshare 2.8inch LCD HAT
support: community
compatible:
- raspberry-pi
Display: Display:
### Waveshare 2.8inch RPi LCD ### Waveshare 2.8inch RPi LCD
+6
View File
@@ -1,3 +1,9 @@
Meta:
name: Adafruit RFM9x
support: deprecated
compatible:
- raspberry-pi
Lora: Lora:
Module: RF95 # Adafruit RFM9x Module: RF95 # Adafruit RFM9x
Reset: 25 Reset: 25
+6
View File
@@ -1,5 +1,11 @@
# MeshAdv-Pi E22-900M30S # MeshAdv-Pi E22-900M30S
# https://github.com/chrismyers2000/MeshAdv-Pi-Hat # https://github.com/chrismyers2000/MeshAdv-Pi-Hat
Meta:
name: MeshAdv-Pi E22-900M30S
support: community
compatible:
- raspberry-pi
Lora: Lora:
Module: sx1262 Module: sx1262
CS: 21 CS: 21
@@ -1,5 +1,11 @@
# MeshAdv Mini E22-900M22S # MeshAdv Mini E22-900M22S
# https://github.com/chrismyers2000/MeshAdv-Mini # https://github.com/chrismyers2000/MeshAdv-Mini
Meta:
name: MeshAdv Mini E22-900M22S
support: community
compatible:
- raspberry-pi
Lora: Lora:
Module: sx1262 # Ebyte E22-900M22S Module: sx1262 # Ebyte E22-900M22S
CS: 8 CS: 8
+7 -1
View File
@@ -1,6 +1,12 @@
Meta:
name: RAK6421 + RAK13300 Slot 1
support: official
compatible:
- raspberry-pi
Lora: Lora:
### RAK13300in Slot 1 ### RAK13300 in Slot 1
Module: sx1262 Module: sx1262
IRQ: 22 #IO6 IRQ: 22 #IO6
Reset: 16 # IO4 Reset: 16 # IO4
+7 -1
View File
@@ -1,5 +1,11 @@
Meta:
name: RAK6421 + RAK13300 Slot 2
support: official
compatible:
- raspberry-pi
Lora: Lora:
### RAK13300in Slot 2 pins ### RAK13300 in Slot 2 pins
IRQ: 18 #IO6 IRQ: 18 #IO6
Reset: 24 # IO4 Reset: 24 # IO4
Busy: 19 # IO5 Busy: 19 # IO5
+7 -1
View File
@@ -1,6 +1,12 @@
Meta:
name: RAK6421 + RAK13302 Slot 1
support: official
compatible:
- raspberry-pi
Lora: Lora:
### RAK13300in Slot 1 ### RAK13302 in Slot 1
Module: sx1262 Module: sx1262
IRQ: 22 #IO6 IRQ: 22 #IO6
Reset: 16 # IO4 Reset: 16 # IO4
+7 -1
View File
@@ -1,5 +1,11 @@
Meta:
name: RAK6421 + RAK13302 Slot 2
support: official
compatible:
- raspberry-pi
Lora: Lora:
### RAK13300in Slot 2 pins ### RAK13302 in Slot 2 pins
IRQ: 18 #IO6 IRQ: 18 #IO6
Reset: 24 # IO4 Reset: 24 # IO4
Busy: 19 # IO5 Busy: 19 # IO5
@@ -1,4 +1,10 @@
--- ---
Meta:
name: Femtofox Ebyte E80-900M22S with TCXO
support: community
compatible:
- luckfox-pico-mini # Armbian
Lora: Lora:
## Ebyte E80-900M22S ## Ebyte E80-900M22S
## This is a bit experimental ## This is a bit experimental
@@ -12,9 +18,5 @@ Lora:
Busy: 22 #pin16 / GPIO54 1C6 Busy: 22 #pin16 / GPIO54 1C6
Reset: 25 #pin13 / GPIO57 1D1 Reset: 25 #pin13 / GPIO57 1D1
spidev: spidev0.0 #pins are (CS=16, CLK=17, MOSI=18, MISO=19) spidev: spidev0.0 #pins are (CS=16, CLK=17, MOSI=18, MISO=19)
spiSpeed: 2000000 spiSpeed: 2000000
General:
MACAddressSource: eth0
@@ -1,4 +1,10 @@
--- ---
Meta:
name: Femtofox SX1262 TCXO
support: community
compatible:
- luckfox-pico-mini # Armbian
Lora: Lora:
## Ebyte E22-900M30S, E22-900M22S with or without external RF switching setup ## Ebyte E22-900M30S, E22-900M22S with or without external RF switching setup
## HT-RA62 (Has internal switching, but whatever) ## HT-RA62 (Has internal switching, but whatever)
@@ -16,6 +22,3 @@ Lora:
# TXen: bridge to DIO2 on E22 module # TXen: bridge to DIO2 on E22 module
spidev: spidev0.0 #pins are (CS=16, CLK=17, MOSI=18, MISO=19) spidev: spidev0.0 #pins are (CS=16, CLK=17, MOSI=18, MISO=19)
spiSpeed: 2000000 spiSpeed: 2000000
General:
MACAddressSource: eth0
@@ -1,4 +1,10 @@
--- ---
Meta:
name: Femtofox SX1262 XTAL
support: community
compatible:
- luckfox-pico-mini # Armbian
Lora: Lora:
## Ebyte E22-900MM22S with no external RF switching setup ## Ebyte E22-900MM22S with no external RF switching setup
## Waveshare SX126X XXXM, AI Thinker RA-01SH ## Waveshare SX126X XXXM, AI Thinker RA-01SH
@@ -16,6 +22,3 @@ Lora:
# TXen: bridge to DIO2 on E22 module # TXen: bridge to DIO2 on E22 module
spidev: spidev0.0 #pins are (CS=16, CLK=17, MOSI=18, MISO=19) spidev: spidev0.0 #pins are (CS=16, CLK=17, MOSI=18, MISO=19)
spiSpeed: 2000000 spiSpeed: 2000000
General:
MACAddressSource: eth0
+7 -1
View File
@@ -1,6 +1,12 @@
Meta:
name: RAK6421 + RAK13300 Slot 1 (Autoconf default)
support: official
compatible:
- raspberry-pi
Lora: Lora:
### RAK13300in Slot 1 ### RAK13300 in Slot 1
Module: sx1262 Module: sx1262
IRQ: 22 #IO6 IRQ: 22 #IO6
Reset: 16 # IO4 Reset: 16 # IO4
@@ -1,3 +1,9 @@
Meta:
name: Luckfox Lyra PicoCalc Wio LoRa SX1262
support: official
compatible:
- luckfox-lyra-plus # Armbian
Lora: Lora:
Module: sx1262 Module: sx1262
DIO2_AS_RF_SWITCH: true DIO2_AS_RF_SWITCH: true
+7
View File
@@ -2,6 +2,13 @@
# Enable overlay 'luckfox-lyra-ultra-w-spi0-cs0-spidev' with armbian-config # Enable overlay 'luckfox-lyra-ultra-w-spi0-cs0-spidev' with armbian-config
# https://github.com/wehooper4/Meshtastic-Hardware/tree/main/Luckfox%20Ultra%20Hat # https://github.com/wehooper4/Meshtastic-Hardware/tree/main/Luckfox%20Ultra%20Hat
# 1 Watt Lyra Ultra hat # 1 Watt Lyra Ultra hat
Meta:
name: wehooper4 Luckfox Ultra 1W
support: community
compatible:
- luckfox-pico-ultra # Armbian
- luckfox-lyra-ultra # Armbian
Lora: Lora:
Module: sx1262 Module: sx1262
DIO2_AS_RF_SWITCH: true DIO2_AS_RF_SWITCH: true
+7
View File
@@ -2,6 +2,13 @@
# Enable overlay 'luckfox-lyra-ultra-w-spi0-cs0-spidev' with armbian-config # Enable overlay 'luckfox-lyra-ultra-w-spi0-cs0-spidev' with armbian-config
# https://github.com/wehooper4/Meshtastic-Hardware/tree/main/Luckfox%20Ultra%20Hat # https://github.com/wehooper4/Meshtastic-Hardware/tree/main/Luckfox%20Ultra%20Hat
# 2 Watt Lyra Ultra hat # 2 Watt Lyra Ultra hat
Meta:
name: wehooper4 Luckfox Ultra 2W
support: community
compatible:
- luckfox-pico-ultra # Armbian
- luckfox-lyra-ultra # Armbian
Lora: Lora:
Module: sx1262 Module: sx1262
DIO2_AS_RF_SWITCH: true DIO2_AS_RF_SWITCH: true
@@ -2,6 +2,12 @@
# Enable overlay 'luckfox-lyra-plus-spi0-cs0_rmio13-spidev' with armbian-config # Enable overlay 'luckfox-lyra-plus-spi0-cs0_rmio13-spidev' with armbian-config
# Waveshare LoRa HAT for Raspberry Pi Pico # Waveshare LoRa HAT for Raspberry Pi Pico
# https://www.waveshare.com/wiki/Pico-LoRa-SX1262 # https://www.waveshare.com/wiki/Pico-LoRa-SX1262
Meta:
name: Waveshare LoRa HAT for Raspberry Pi Pico
support: community
compatible:
- luckfox-lyra-plus # Armbian
Lora: Lora:
Module: sx1262 Module: sx1262
DIO2_AS_RF_SWITCH: true DIO2_AS_RF_SWITCH: true
+6
View File
@@ -1,3 +1,9 @@
Meta:
name: Lora Meshstick SX1262
support: official
compatible:
- usb
Lora: Lora:
Module: sx1262 Module: sx1262
CS: 0 CS: 0
+6
View File
@@ -1,3 +1,9 @@
Meta:
name: Lora Meshstick SX1262
support: community
compatible:
- usb
Lora: Lora:
Module: lr1121 Module: lr1121
CS: 0 CS: 0
@@ -1,3 +1,9 @@
Meta:
name: Pinedio USB SX1262
support: deprecated
compatible:
- usb
Lora: Lora:
Module: sx1262 Module: sx1262
CS: 0 CS: 0
@@ -1,3 +1,9 @@
Meta:
name: raxda-rock2f-starter-edition-hat
support: community
compatible:
- rock-2f # Armbian
Lora: Lora:
### Raxda Rock 2F running Armbian Linux 6.1.99-vendor-rk35xx ### Raxda Rock 2F running Armbian Linux 6.1.99-vendor-rk35xx
@@ -1,5 +1,11 @@
# https://www.waveshare.com/core1262-868m.htm # https://www.waveshare.com/core1262-868m.htm
# https://github.com/markbirss/lora-starter-edition-sx1262-i2c # https://github.com/markbirss/lora-starter-edition-sx1262-i2c
Meta:
name: lora-starter-edition-sx1262-i2c
support: community
compatible:
- raspberry-pi
Lora: Lora:
Module: sx1262 # Starter Edition SX1262 I2C Raspberry Pi HAT Module: sx1262 # Starter Edition SX1262 I2C Raspberry Pi HAT
DIO2_AS_RF_SWITCH: true DIO2_AS_RF_SWITCH: true
@@ -1,3 +1,9 @@
Meta:
name: meshstick-1262
support: official
compatible:
- usb
Lora: Lora:
Module: sx1262 Module: sx1262
CS: 0 CS: 0
+6
View File
@@ -1,3 +1,9 @@
Meta:
name: meshtoad-e22
support: official
compatible:
- usb
Lora: Lora:
Module: sx1262 Module: sx1262
CS: 0 CS: 0
@@ -1,3 +1,9 @@
Meta:
name: umesh-1262-30dbm
support: community
compatible:
- clockwork-uconsole
Lora: Lora:
Module: sx1262 Module: sx1262
CS: 0 CS: 0
@@ -1,3 +1,9 @@
Meta:
name: umesh-1268-30dbm
support: community
compatible:
- clockwork-uconsole
Lora: Lora:
Module: sx1268 Module: sx1268
CS: 0 CS: 0
+6
View File
@@ -1,3 +1,9 @@
Meta:
name: Waveshare SX1262
support: deprecated
compatible:
- raspberry-pi
Lora: Lora:
Module: sx1262 # Waveshare SX126X XXXM Module: sx1262 # Waveshare SX126X XXXM
DIO2_AS_RF_SWITCH: true DIO2_AS_RF_SWITCH: true
@@ -1,5 +1,12 @@
# https://www.waveshare.com/pico-lora-sx1262-868m.htm # https://www.waveshare.com/pico-lora-sx1262-868m.htm
# https://github.com/markbirss/lora-ws-raspberry-pi-pico-to-rpi-adapter # https://github.com/markbirss/lora-ws-raspberry-pi-pico-to-rpi-adapter
Meta:
name: ws-raspberry-pico-to-rpi-adapter
support: community
compatible:
- raspberry-pi
Lora: Lora:
Module: sx1262 # Waveshare Raspberry Pi Pico to Raspberry Pi HAT Adapter Module: sx1262 # Waveshare Raspberry Pi Pico to Raspberry Pi HAT Adapter
DIO2_AS_RF_SWITCH: true DIO2_AS_RF_SWITCH: true
@@ -15,6 +15,12 @@
# 5 CS 24 # 5 CS 24
# 26 DIO1/IRQ 26 # 26 DIO1/IRQ 26
Meta:
name: ws-raspberry-pico-to-orangepi-03
support: community
compatible:
- orange-pi-zero-3 # Armbian
Lora: Lora:
Module: sx1262 # Waveshare Raspberry Pico Lora module Module: sx1262 # Waveshare Raspberry Pico Lora module
DIO2_AS_RF_SWITCH: true DIO2_AS_RF_SWITCH: true
+28
View File
@@ -2,6 +2,7 @@
#include "configuration.h" #include "configuration.h"
#include "detect/ScanI2C.h" #include "detect/ScanI2C.h"
#include "main.h" #include "main.h"
#include "modules/NodeInfoModule.h"
#include <Throttle.h> #include <Throttle.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
@@ -12,6 +13,14 @@ uint32_t lastSetFromPhoneNtpOrGps = 0;
static uint32_t lastTimeValidationWarning = 0; static uint32_t lastTimeValidationWarning = 0;
static const uint32_t TIME_VALIDATION_WARNING_INTERVAL_MS = 15000; // 15 seconds static const uint32_t TIME_VALIDATION_WARNING_INTERVAL_MS = 15000; // 15 seconds
static void triggerNodeInfoCheckOnTimeSource(RTCQuality oldQuality, RTCQuality newQuality)
{
if (oldQuality == RTCQualityNone && newQuality > RTCQualityNone && nodeInfoModule) {
LOG_DEBUG("Time source acquired (%s -> %s), triggering NodeInfo recheck", RtcName(oldQuality), RtcName(newQuality));
nodeInfoModule->triggerImmediateNodeInfoCheck();
}
}
RTCQuality getRTCQuality() RTCQuality getRTCQuality()
{ {
return currentQuality; return currentQuality;
@@ -61,9 +70,11 @@ RTCSetResult readFromRTC()
LOG_DEBUG("Read RTC time from RV3028 getTime as %02d-%02d-%02d %02d:%02d:%02d (%ld)", t.tm_year + 1900, t.tm_mon + 1, LOG_DEBUG("Read RTC time from RV3028 getTime as %02d-%02d-%02d %02d:%02d:%02d (%ld)", t.tm_year + 1900, t.tm_mon + 1,
t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, printableEpoch); t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, printableEpoch);
if (currentQuality == RTCQualityNone) { if (currentQuality == RTCQualityNone) {
RTCQuality oldQuality = currentQuality;
timeStartMsec = now; timeStartMsec = now;
zeroOffsetSecs = tv.tv_sec; zeroOffsetSecs = tv.tv_sec;
currentQuality = RTCQualityDevice; currentQuality = RTCQualityDevice;
triggerNodeInfoCheckOnTimeSource(oldQuality, currentQuality);
} }
return RTCSetResultSuccess; return RTCSetResultSuccess;
} else { } else {
@@ -105,9 +116,11 @@ RTCSetResult readFromRTC()
LOG_DEBUG("Read RTC time from %s getDateTime as %02d-%02d-%02d %02d:%02d:%02d (%ld)", rtc.getChipName(), t.tm_year + 1900, LOG_DEBUG("Read RTC time from %s getDateTime as %02d-%02d-%02d %02d:%02d:%02d (%ld)", rtc.getChipName(), t.tm_year + 1900,
t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, printableEpoch); t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, printableEpoch);
if (currentQuality == RTCQualityNone) { if (currentQuality == RTCQualityNone) {
RTCQuality oldQuality = currentQuality;
timeStartMsec = now; timeStartMsec = now;
zeroOffsetSecs = tv.tv_sec; zeroOffsetSecs = tv.tv_sec;
currentQuality = RTCQualityDevice; currentQuality = RTCQualityDevice;
triggerNodeInfoCheckOnTimeSource(oldQuality, currentQuality);
} }
return RTCSetResultSuccess; return RTCSetResultSuccess;
} else { } else {
@@ -139,9 +152,11 @@ RTCSetResult readFromRTC()
} }
#endif #endif
if (currentQuality == RTCQualityNone) { if (currentQuality == RTCQualityNone) {
RTCQuality oldQuality = currentQuality;
timeStartMsec = now; timeStartMsec = now;
zeroOffsetSecs = tv.tv_sec; zeroOffsetSecs = tv.tv_sec;
currentQuality = RTCQualityDevice; currentQuality = RTCQualityDevice;
triggerNodeInfoCheckOnTimeSource(oldQuality, currentQuality);
} }
return RTCSetResultSuccess; return RTCSetResultSuccess;
} }
@@ -214,6 +229,7 @@ RTCSetResult perhapsSetRTC(RTCQuality q, const struct timeval *tv, bool forceUpd
} }
if (shouldSet) { if (shouldSet) {
RTCQuality oldQuality = currentQuality;
currentQuality = q; currentQuality = q;
lastSetMsec = now; lastSetMsec = now;
if (currentQuality >= RTCQualityNTP) { if (currentQuality >= RTCQualityNTP) {
@@ -281,6 +297,7 @@ RTCSetResult perhapsSetRTC(RTCQuality q, const struct timeval *tv, bool forceUpd
#endif #endif
readFromRTC(); readFromRTC();
triggerNodeInfoCheckOnTimeSource(oldQuality, currentQuality);
return RTCSetResultSuccess; return RTCSetResultSuccess;
} else { } else {
return RTCSetResultNotSet; // RTC was already set with a higher quality time return RTCSetResultNotSet; // RTC was already set with a higher quality time
@@ -397,6 +414,17 @@ uint32_t getValidTime(RTCQuality minQuality, bool local)
return (currentQuality >= minQuality) ? getTime(local) : 0; return (currentQuality >= minQuality) ? getTime(local) : 0;
} }
#ifdef PIO_UNIT_TESTING
void setBootRelativeTimeForUnitTest(uint32_t secondsSinceBoot)
{
currentQuality = RTCQualityNone;
zeroOffsetSecs = 0;
timeStartMsec = millis() - (secondsSinceBoot * 1000);
lastSetFromPhoneNtpOrGps = 0;
lastTimeValidationWarning = 0;
}
#endif
time_t gm_mktime(const struct tm *tm) time_t gm_mktime(const struct tm *tm)
{ {
#if !MESHTASTIC_EXCLUDE_TZ #if !MESHTASTIC_EXCLUDE_TZ
+4
View File
@@ -54,6 +54,10 @@ uint32_t getValidTime(RTCQuality minQuality, bool local = false);
RTCSetResult readFromRTC(); RTCSetResult readFromRTC();
#ifdef PIO_UNIT_TESTING
void setBootRelativeTimeForUnitTest(uint32_t secondsSinceBoot);
#endif
time_t gm_mktime(const struct tm *tm); time_t gm_mktime(const struct tm *tm);
#define SEC_PER_DAY 86400 #define SEC_PER_DAY 86400
+2 -1
View File
@@ -31,5 +31,6 @@ bool Throttle::execute(uint32_t *lastExecutionMs, uint32_t minumumIntervalMs, vo
/// @param timeSpanMs The interval in milliseconds of the timespan /// @param timeSpanMs The interval in milliseconds of the timespan
bool Throttle::isWithinTimespanMs(uint32_t lastExecutionMs, uint32_t timeSpanMs) bool Throttle::isWithinTimespanMs(uint32_t lastExecutionMs, uint32_t timeSpanMs)
{ {
return (millis() - lastExecutionMs) < timeSpanMs; uint32_t now = millis();
return (now - lastExecutionMs) < timeSpanMs;
} }
+127 -36
View File
@@ -16,6 +16,20 @@ TransmitHistory *TransmitHistory::getInstance()
return transmitHistory; return transmitHistory;
} }
TransmitHistory::StoredTimestamp TransmitHistory::makeStoredTimestamp(uint32_t seconds, uint8_t flags)
{
StoredTimestamp stored;
stored.seconds = seconds;
stored.flags = flags;
return stored;
}
TransmitHistory::StoredTimestamp TransmitHistory::decodeLegacyTimestamp(uint32_t seconds)
{
const bool isProbablyBootRelative = seconds > 0 && seconds <= LEGACY_BOOT_RELATIVE_MAX_SEC;
return makeStoredTimestamp(seconds, isProbablyBootRelative ? ENTRY_FLAG_BOOT_RELATIVE : ENTRY_FLAG_NONE);
}
void TransmitHistory::loadFromDisk() void TransmitHistory::loadFromDisk()
{ {
spiLock->lock(); spiLock->lock();
@@ -23,16 +37,33 @@ void TransmitHistory::loadFromDisk()
if (file) { if (file) {
FileHeader header{}; FileHeader header{};
if (file.read((uint8_t *)&header, sizeof(header)) == sizeof(header) && header.magic == MAGIC && if (file.read((uint8_t *)&header, sizeof(header)) == sizeof(header) && header.magic == MAGIC &&
header.version == VERSION && header.count <= MAX_ENTRIES) { (header.version == 1 || header.version == VERSION) && header.count <= MAX_ENTRIES) {
for (uint8_t i = 0; i < header.count; i++) { for (uint8_t i = 0; i < header.count; i++) {
Entry entry{}; if (header.version == 1) {
if (file.read((uint8_t *)&entry, sizeof(entry)) == sizeof(entry)) { LegacyEntry entry{};
if (entry.epochSeconds > 0) { if (file.read((uint8_t *)&entry, sizeof(entry)) == sizeof(entry) && entry.epochSeconds > 0) {
history[entry.key] = entry.epochSeconds; history[entry.key] = decodeLegacyTimestamp(entry.epochSeconds);
// Seed in-memory millis so throttle works even without RTC/GPS. }
// Treating stored entries as "just sent" is safe — worst case the } else {
// node waits one full interval before its first broadcast. Entry entry{};
lastMillis[entry.key] = millis(); if (file.read((uint8_t *)&entry, sizeof(entry)) == sizeof(entry) && entry.epochSeconds > 0) {
history[entry.key] = makeStoredTimestamp(entry.epochSeconds, entry.flags);
// Do NOT seed lastMillis here.
//
// getLastSentToMeshMillis() reconstructs a millis()-relative value
// from the stored epoch, and Throttle::isWithinTimespanMs() uses
// the same unsigned subtraction pattern. Once getTime() has a valid
// wall-clock epoch comparable to stored values, recent reboots still
// throttle correctly while long power-off periods no longer look like
// "just sent" and incorrectly suppress the first send.
//
// Before RTC/NTP/GPS time is valid, persisted absolute epochs do not
// contribute, but boot-relative entries still suppress near-term reboot
// chatter via a narrow recovery window.
//
// If we seeded lastMillis to millis() here, every loaded entry would
// appear to have been sent at boot time, regardless of the true age
// of the last transmission. That was the regression behind #9901.
} }
} }
} }
@@ -53,7 +84,8 @@ void TransmitHistory::setLastSentToMesh(uint16_t key)
lastMillis[key] = millis(); lastMillis[key] = millis();
uint32_t now = getTime(); uint32_t now = getTime();
if (now >= 2) { if (now >= 2) {
history[key] = now; const uint8_t flags = (getRTCQuality() == RTCQualityNone) ? ENTRY_FLAG_BOOT_RELATIVE : ENTRY_FLAG_NONE;
history[key] = makeStoredTimestamp(now, flags);
dirty = true; dirty = true;
// Don't flush to disk on every transmit — flash has limited write endurance. // Don't flush to disk on every transmit — flash has limited write endurance.
// The in-memory lastMillis map handles throttle during normal operation. // The in-memory lastMillis map handles throttle during normal operation.
@@ -68,15 +100,84 @@ void TransmitHistory::setLastSentToMesh(uint16_t key)
} }
} }
#ifdef PIO_UNIT_TESTING
void TransmitHistory::setLastSentAtEpoch(uint16_t key, uint32_t epochSeconds)
{
if (epochSeconds > 0) {
history[key] = makeStoredTimestamp(epochSeconds, ENTRY_FLAG_NONE);
dirty = true;
} else {
history.erase(key);
lastMillis.erase(key);
}
}
void TransmitHistory::setLastSentAtBootRelative(uint16_t key, uint32_t secondsSinceBoot)
{
if (secondsSinceBoot > 0) {
history[key] = makeStoredTimestamp(secondsSinceBoot, ENTRY_FLAG_BOOT_RELATIVE);
dirty = true;
} else {
history.erase(key);
lastMillis.erase(key);
}
}
#endif
uint32_t TransmitHistory::getLastSentToMeshEpoch(uint16_t key) const uint32_t TransmitHistory::getLastSentToMeshEpoch(uint16_t key) const
{ {
auto it = history.find(key); auto it = history.find(key);
if (it != history.end()) { if (it != history.end()) {
return it->second; return it->second.seconds;
} }
return 0; return 0;
} }
uint32_t TransmitHistory::getLastSentAbsoluteMillis(uint32_t storedEpoch) const
{
uint32_t now = getTime();
if (now < 2) {
return 0;
}
if (storedEpoch > now) {
return 0;
}
uint32_t secondsAgo = now - storedEpoch;
uint32_t msAgo = secondsAgo * 1000;
if (secondsAgo > 86400 || msAgo / 1000 != secondsAgo) {
return 0;
}
return millis() - msAgo;
}
uint32_t TransmitHistory::getLastSentBootRelativeMillis(uint32_t storedSeconds) const
{
if (getRTCQuality() != RTCQualityNone) {
return 0;
}
uint32_t now = getTime();
if (storedSeconds <= now) {
uint32_t secondsAgo = now - storedSeconds;
if (secondsAgo > BOOT_RELATIVE_RECOVERY_WINDOW_SEC) {
return 0;
}
return millis() - (secondsAgo * 1000);
}
uint32_t secondsAhead = storedSeconds - now;
if (secondsAhead > BOOT_RELATIVE_RECOVERY_WINDOW_SEC) {
return 0;
}
return millis();
}
uint32_t TransmitHistory::getLastSentToMeshMillis(uint16_t key) const uint32_t TransmitHistory::getLastSentToMeshMillis(uint16_t key) const
{ {
// Prefer runtime millis value (accurate within this boot) // Prefer runtime millis value (accurate within this boot)
@@ -86,34 +187,23 @@ uint32_t TransmitHistory::getLastSentToMeshMillis(uint16_t key) const
} }
// Fall back to epoch conversion (loaded from disk after reboot) // Fall back to epoch conversion (loaded from disk after reboot)
uint32_t storedEpoch = getLastSentToMeshEpoch(key); auto it = history.find(key);
if (storedEpoch == 0) { if (it == history.end() || it->second.seconds == 0) {
return 0; // No stored time — module has never sent return 0; // No stored time — module has never sent
} }
uint32_t now = getTime(); // Convert to a millis()-relative timestamp: millis() - msAgo.
if (now < 2) { //
// No valid RTC time yet — can't convert to millis. Return 0 so throttle doesn't block. // The result may wrap if msAgo is larger than the current uptime, and that is
return 0; // intentional. Throttle::isWithinTimespanMs() also uses unsigned subtraction,
// so the reconstructed age is preserved across wraparound:
// - recent reboot, 5 min ago -> (millis() - lastMs) == 300000, still throttled
// - long reboot, 30 min ago -> (millis() - lastMs) == 1800000, allowed
if ((it->second.flags & ENTRY_FLAG_BOOT_RELATIVE) != 0) {
return getLastSentBootRelativeMillis(it->second.seconds);
} }
if (storedEpoch > now) { return getLastSentAbsoluteMillis(it->second.seconds);
// Stored time is in the future (clock went backwards?) — treat as stale
return 0;
}
uint32_t secondsAgo = now - storedEpoch;
uint32_t msAgo = secondsAgo * 1000;
// Guard against overflow: if the transmit was very long ago, just return 0 (won't throttle)
if (secondsAgo > 86400 || msAgo / 1000 != secondsAgo) {
return 0;
}
// Convert to a millis()-relative timestamp: millis() - msAgo
// This gives a value that, when passed to Throttle::isWithinTimespanMs(value, interval),
// correctly reports whether the transmit was within interval ms.
return millis() - msAgo;
} }
bool TransmitHistory::saveToDisk() bool TransmitHistory::saveToDisk()
@@ -141,12 +231,13 @@ bool TransmitHistory::saveToDisk()
file.write((uint8_t *)&header, sizeof(header)); file.write((uint8_t *)&header, sizeof(header));
uint8_t written = 0; uint8_t written = 0;
for (const auto &[key, epochSeconds] : history) { for (const auto &[key, stored] : history) {
if (written >= MAX_ENTRIES) if (written >= MAX_ENTRIES)
break; break;
Entry entry{}; Entry entry{};
entry.key = key; entry.key = key;
entry.epochSeconds = epochSeconds; entry.epochSeconds = stored.seconds;
entry.flags = stored.flags;
file.write((uint8_t *)&entry, sizeof(entry)); file.write((uint8_t *)&entry, sizeof(entry));
written++; written++;
} }
+44 -4
View File
@@ -35,8 +35,25 @@ class TransmitHistory
*/ */
void setLastSentToMesh(uint16_t key); void setLastSentToMesh(uint16_t key);
#ifdef PIO_UNIT_TESTING
/** /**
* Get the last transmit epoch seconds for a given key, or 0 if unknown. * Directly set the stored epoch for a key without touching the runtime lastMillis map.
* Intended for testing purposes: lets tests simulate "the last broadcast happened N
* seconds ago" without needing to fake the system clock.
*/
void setLastSentAtEpoch(uint16_t key, uint32_t epochSeconds);
/**
* Directly set a boot-relative timestamp (seconds since boot) for testing.
*/
void setLastSentAtBootRelative(uint16_t key, uint32_t secondsSinceBoot);
#endif
/**
* Get the raw persisted timestamp seconds for a given key, or 0 if unknown.
*
* The returned value is an absolute epoch when persisted with valid RTC/NTP/GPS time,
* or boot-relative seconds when ENTRY_FLAG_BOOT_RELATIVE is set.
*/ */
uint32_t getLastSentToMeshEpoch(uint16_t key) const; uint32_t getLastSentToMeshEpoch(uint16_t key) const;
@@ -64,13 +81,31 @@ class TransmitHistory
static constexpr const char *FILENAME = "/prefs/transmit_history.dat"; static constexpr const char *FILENAME = "/prefs/transmit_history.dat";
static constexpr uint32_t MAGIC = 0x54485354; // "THST" static constexpr uint32_t MAGIC = 0x54485354; // "THST"
static constexpr uint8_t VERSION = 1; static constexpr uint8_t VERSION = 2;
static constexpr uint8_t MAX_ENTRIES = 16; static constexpr uint8_t MAX_ENTRIES = 16;
static constexpr uint32_t SAVE_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes static constexpr uint32_t SAVE_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes
static constexpr uint32_t BOOT_RELATIVE_RECOVERY_WINDOW_SEC = 2 * 60;
static constexpr uint32_t LEGACY_BOOT_RELATIVE_MAX_SEC = 365UL * 24 * 60 * 60;
enum EntryFlags : uint8_t {
ENTRY_FLAG_NONE = 0,
ENTRY_FLAG_BOOT_RELATIVE = 0x01,
};
struct StoredTimestamp {
uint32_t seconds = 0;
uint8_t flags = ENTRY_FLAG_NONE;
};
struct __attribute__((packed)) Entry { struct __attribute__((packed)) Entry {
uint16_t key; uint16_t key;
uint32_t epochSeconds; uint32_t epochSeconds;
uint8_t flags;
};
struct __attribute__((packed)) LegacyEntry {
uint16_t key;
uint32_t epochSeconds;
}; };
struct __attribute__((packed)) FileHeader { struct __attribute__((packed)) FileHeader {
@@ -79,8 +114,13 @@ class TransmitHistory
uint8_t count; uint8_t count;
}; };
std::map<uint16_t, uint32_t> history; // key -> epoch seconds (for disk persistence) uint32_t getLastSentAbsoluteMillis(uint32_t storedEpoch) const;
std::map<uint16_t, uint32_t> lastMillis; // key -> millis() value (for runtime throttle) uint32_t getLastSentBootRelativeMillis(uint32_t storedSeconds) const;
static StoredTimestamp makeStoredTimestamp(uint32_t seconds, uint8_t flags = ENTRY_FLAG_NONE);
static StoredTimestamp decodeLegacyTimestamp(uint32_t seconds);
std::map<uint16_t, StoredTimestamp> history; // key -> persisted transmit time
std::map<uint16_t, uint32_t> lastMillis; // key -> millis() value (for runtime throttle)
bool dirty = false; bool dirty = false;
uint32_t lastDiskSave = 0; // millis() of last disk flush uint32_t lastDiskSave = 0; // millis() of last disk flush
}; };
+6
View File
@@ -118,6 +118,12 @@ void NodeInfoModule::sendOurNodeInfo(NodeNum dest, bool wantReplies, uint8_t cha
} }
} }
void NodeInfoModule::triggerImmediateNodeInfoCheck()
{
LOG_DEBUG("NodeInfo: scheduling immediate periodic check");
setIntervalFromNow(0);
}
meshtastic_MeshPacket *NodeInfoModule::allocReply() meshtastic_MeshPacket *NodeInfoModule::allocReply()
{ {
// Only apply suppression when actually replying to someone else's request, not for periodic broadcasts. // Only apply suppression when actually replying to someone else's request, not for periodic broadcasts.
+6
View File
@@ -24,6 +24,12 @@ class NodeInfoModule : public ProtobufModule<meshtastic_User>, private concurren
void sendOurNodeInfo(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false, uint8_t channel = 0, void sendOurNodeInfo(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false, uint8_t channel = 0,
bool _shorterTimeout = false); bool _shorterTimeout = false);
/**
* Schedule an immediate NodeInfo periodic check.
* Used when external conditions change (for example time source quality).
*/
void triggerImmediateNodeInfoCheck();
protected: protected:
/** Called to handle a particular incoming message /** Called to handle a particular incoming message
+127 -21
View File
@@ -1,5 +1,6 @@
#include "TestUtil.h" #include "TestUtil.h"
#include "TransmitHistory.h" #include "TransmitHistory.h"
#include "gps/RTC.h"
#include <Throttle.h> #include <Throttle.h>
#include <unity.h> #include <unity.h>
@@ -161,44 +162,141 @@ static void test_save_and_load_round_trip()
// After loadFromDisk, millis should be seeded (non-zero) for stored entries // After loadFromDisk, millis should be seeded (non-zero) for stored entries
uint32_t restoredMillis = transmitHistory->getLastSentToMeshMillis(meshtastic_PortNum_NODEINFO_APP); uint32_t restoredMillis = transmitHistory->getLastSentToMeshMillis(meshtastic_PortNum_NODEINFO_APP);
if (restoredNodeInfo > 0) { if (restoredNodeInfo > 0) {
// If epoch was stored, millis should be seeded from load // If epoch was stored (set seconds ago), epoch-conversion gives elapsed ≈ 0 s,
// so getLastSentToMeshMillis() should return a non-zero value.
TEST_ASSERT_NOT_EQUAL(0, restoredMillis); TEST_ASSERT_NOT_EQUAL(0, restoredMillis);
} }
} }
// --- Boot without RTC scenario --- // --- Boot without RTC scenario ---
static void test_load_seeds_millis_even_without_rtc() // Crash-reboot protection: a send that happened moments before the reboot must still
// throttle after reload. This works because getLastSentToMeshMillis() reconstructs
// a millis()-relative timestamp from the stored epoch, and Throttle uses unsigned
// subtraction so the age survives wraparound even when uptime is near zero.
static void test_boot_after_recent_send_still_throttles()
{ {
// This tests the critical crash-reboot scenario:
// After loadFromDisk(), even if getTime() returns 0 (no RTC),
// lastMillis should be seeded so throttle blocks immediate re-broadcast.
transmitHistory->setLastSentToMesh(meshtastic_PortNum_NODEINFO_APP); transmitHistory->setLastSentToMesh(meshtastic_PortNum_NODEINFO_APP);
transmitHistory->saveToDisk(); transmitHistory->saveToDisk();
// Simulate reboot: destroy and recreate // Simulate reboot
delete transmitHistory; delete transmitHistory;
transmitHistory = nullptr; transmitHistory = nullptr;
transmitHistory = TransmitHistory::getInstance(); transmitHistory = TransmitHistory::getInstance();
transmitHistory->loadFromDisk(); transmitHistory->loadFromDisk();
// The key insight: after load, getLastSentToMeshMillis should return non-zero // Epoch was set seconds ago; reconstructed age is still within the 10-min window.
// because loadFromDisk seeds lastMillis[key] = millis() for every loaded entry.
// This ensures throttle works even without RTC.
uint32_t result = transmitHistory->getLastSentToMeshMillis(meshtastic_PortNum_NODEINFO_APP); uint32_t result = transmitHistory->getLastSentToMeshMillis(meshtastic_PortNum_NODEINFO_APP);
uint32_t epoch = transmitHistory->getLastSentToMeshEpoch(meshtastic_PortNum_NODEINFO_APP); uint32_t epoch = transmitHistory->getLastSentToMeshEpoch(meshtastic_PortNum_NODEINFO_APP);
if (epoch > 0) { if (epoch == 0) {
// Data was persisted — millis must be seeded TEST_IGNORE_MESSAGE("Epoch not persisted; skipping");
TEST_ASSERT_NOT_EQUAL(0, result); return;
// And it should cause throttle to block (treating as "just sent")
bool withinInterval = Throttle::isWithinTimespanMs(result, 10 * 60 * 1000);
TEST_ASSERT_TRUE(withinInterval);
} }
// If epoch == 0, RTC wasn't available — no data was saved, so nothing to restore.
// This is expected on platforms without RTC during the very first boot. TEST_ASSERT_NOT_EQUAL(0, result);
bool withinInterval = Throttle::isWithinTimespanMs(result, 10 * 60 * 1000);
TEST_ASSERT_TRUE(withinInterval);
}
// Regression test for issue #9901:
// A device powered off for longer than the throttle window must broadcast NodeInfo
// on its next boot — it must not be silenced because loadFromDisk() once treated
// every loaded entry as "just sent" by seeding lastMillis to millis() at boot.
static void test_boot_after_long_gap_allows_nodeinfo()
{
if (getRTCQuality() <= RTCQualityNone) {
TEST_IGNORE_MESSAGE("No RTC available; skipping epoch-dependent test");
return;
}
uint32_t now = getTime();
// Simulate: last NodeInfo sent 30 minutes ago (outside the 10-min throttle window)
transmitHistory->setLastSentAtEpoch(meshtastic_PortNum_NODEINFO_APP, now - (30 * 60));
transmitHistory->saveToDisk();
// Simulate reboot
delete transmitHistory;
transmitHistory = nullptr;
transmitHistory = TransmitHistory::getInstance();
transmitHistory->loadFromDisk();
uint32_t restoredEpoch = transmitHistory->getLastSentToMeshEpoch(meshtastic_PortNum_NODEINFO_APP);
if (restoredEpoch == 0) {
TEST_IGNORE_MESSAGE("Epoch not persisted; skipping");
return;
}
uint32_t restoredMs = transmitHistory->getLastSentToMeshMillis(meshtastic_PortNum_NODEINFO_APP);
bool throttled = (restoredMs != 0) && Throttle::isWithinTimespanMs(restoredMs, 10 * 60 * 1000);
TEST_ASSERT_FALSE_MESSAGE(throttled, "NodeInfo must not be throttled after a 30-min gap (#9901)");
}
// Complementary: a rapid reboot must still throttle (crash-loop protection), even
// though the reconstructed lastMs may wrap because current uptime is small.
static void test_boot_within_throttle_window_still_throttles()
{
if (getRTCQuality() <= RTCQualityNone) {
TEST_IGNORE_MESSAGE("No RTC available; skipping epoch-dependent test");
return;
}
uint32_t now = getTime();
// Simulate: last NodeInfo sent 5 minutes ago (inside the 10-min throttle window)
transmitHistory->setLastSentAtEpoch(meshtastic_PortNum_NODEINFO_APP, now - (5 * 60));
transmitHistory->saveToDisk();
// Simulate reboot
delete transmitHistory;
transmitHistory = nullptr;
transmitHistory = TransmitHistory::getInstance();
transmitHistory->loadFromDisk();
uint32_t restoredEpoch = transmitHistory->getLastSentToMeshEpoch(meshtastic_PortNum_NODEINFO_APP);
if (restoredEpoch == 0) {
TEST_IGNORE_MESSAGE("Epoch not persisted; skipping");
return;
}
uint32_t restoredMs = transmitHistory->getLastSentToMeshMillis(meshtastic_PortNum_NODEINFO_APP);
bool throttled = (restoredMs != 0) && Throttle::isWithinTimespanMs(restoredMs, 10 * 60 * 1000);
TEST_ASSERT_TRUE_MESSAGE(throttled, "NodeInfo must still be throttled when last send was within the 10-min window");
}
static void test_boot_without_time_source_still_throttles_recent_restart()
{
setBootRelativeTimeForUnitTest(32);
transmitHistory->setLastSentAtBootRelative(meshtastic_PortNum_NODEINFO_APP, 32);
transmitHistory->saveToDisk();
delete transmitHistory;
transmitHistory = nullptr;
transmitHistory = TransmitHistory::getInstance();
setBootRelativeTimeForUnitTest(31);
transmitHistory->loadFromDisk();
uint32_t restoredMs = transmitHistory->getLastSentToMeshMillis(meshtastic_PortNum_NODEINFO_APP);
bool throttled = (restoredMs != 0) && Throttle::isWithinTimespanMs(restoredMs, 10 * 60 * 1000);
TEST_ASSERT_TRUE_MESSAGE(throttled, "Recent no-RTC reboots should still suppress duplicate NodeInfo");
}
static void test_boot_without_time_source_expires_boot_relative_history()
{
setBootRelativeTimeForUnitTest(32);
transmitHistory->setLastSentAtBootRelative(meshtastic_PortNum_NODEINFO_APP, 32);
transmitHistory->saveToDisk();
delete transmitHistory;
transmitHistory = nullptr;
transmitHistory = TransmitHistory::getInstance();
setBootRelativeTimeForUnitTest(400);
transmitHistory->loadFromDisk();
uint32_t restoredMs = transmitHistory->getLastSentToMeshMillis(meshtastic_PortNum_NODEINFO_APP);
TEST_ASSERT_EQUAL_UINT32_MESSAGE(0, restoredMs, "Boot-relative history should only suppress near-term restarts");
} }
void setup() void setup()
@@ -222,7 +320,15 @@ void setup()
// Persistence // Persistence
RUN_TEST(test_save_and_load_round_trip); RUN_TEST(test_save_and_load_round_trip);
RUN_TEST(test_load_seeds_millis_even_without_rtc); RUN_TEST(test_boot_after_recent_send_still_throttles);
// Issue #9901 regression tests
RUN_TEST(test_boot_after_long_gap_allows_nodeinfo);
RUN_TEST(test_boot_within_throttle_window_still_throttles);
// No-RTC regression tests
RUN_TEST(test_boot_without_time_source_still_throttles_recent_restart);
RUN_TEST(test_boot_without_time_source_expires_boot_relative_history);
exit(UNITY_END()); exit(UNITY_END());
} }