From e11d14e6cc5924823bc32476d829ec8972008b2b Mon Sep 17 00:00:00 2001 From: "Valentin V. Bartenev" Date: Wed, 20 May 2026 19:53:12 +0300 Subject: [PATCH] Fix: expand HistorySample::recv_errors from uint16_t to uint32_t The error_rate graph showed all zeros after ~65535 receive errors had accumulated. Root cause was a two-part bug: 1. In MyMesh::updateStatsHistory(), recv_errors was clamped to 0xFFFF via min(..., 0xFFFF). Once the counter reached 65535, every subsequent sample stored the same constant value, making the per-interval delta always zero and therefore error_rate always zero. 2. HistorySample::recv_errors was declared as uint16_t while the underlying counter (n_recv_errors) is uint32_t. parseSummaryLine() also truncated the restored value back to uint16_t. Fix: - Remove the clamp in MyMesh::updateStatsHistory(); assign getPacketsRecvErrors() (uint32_t) directly. - Change HistorySample::recv_errors from uint16_t to uint32_t, moving it next to the other uint32_t fields. - Update both parseSummaryLine() code paths to cast recv_errors to uint32_t instead of uint16_t. The archive format is unchanged: recv_errors is written as %u and read back into an unsigned local, which is correct for a 32-bit value on ESP32. --- examples/simple_repeater/MyMesh.cpp | 2 +- src/helpers/StatsHistory.cpp | 4 ++-- src/helpers/StatsHistory.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index f8446648..d0b4d3c8 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -1876,7 +1876,7 @@ void MyMesh::updateStatsHistory(unsigned long now_ms) { sample.battery_mv = battery_mv; sample.queue_len = static_cast(_mgr->getOutboundTotal()); sample.error_flags = _err_flags; - sample.recv_errors = static_cast(min(radio_driver.getPacketsRecvErrors(), 0xFFFF)); + sample.recv_errors = radio_driver.getPacketsRecvErrors(); sample.neighbour_count = static_cast(min(getNeighbourCount(), 0xFFFF)); sample.direct_dups = static_cast(min(((SimpleMeshTables *)getTables())->getNumDirectDups(), 0xFFFF)); diff --git a/src/helpers/StatsHistory.cpp b/src/helpers/StatsHistory.cpp index 4a6fc754..7b23bc47 100644 --- a/src/helpers/StatsHistory.cpp +++ b/src/helpers/StatsHistory.cpp @@ -687,6 +687,7 @@ bool StatsHistory::parseSummaryLine(const char* line, HistorySample& sample) con sample.uptime_secs = static_cast(uptime_secs); sample.packets_sent = static_cast(packets_sent); sample.packets_recv = static_cast(packets_recv); + sample.recv_errors = static_cast(recv_errors); sample.heap_free = static_cast(heap_free); sample.heap_min = static_cast(heap_free); sample.psram_free = static_cast(psram_free); @@ -694,7 +695,6 @@ bool StatsHistory::parseSummaryLine(const char* line, HistorySample& sample) con sample.battery_mv = static_cast(battery_mv); sample.queue_len = static_cast(queue_len); sample.error_flags = static_cast(error_flags); - sample.recv_errors = static_cast(recv_errors); sample.neighbour_count = static_cast(neighbour_count); sample.direct_dups = static_cast(direct_dups); sample.flood_dups = static_cast(flood_dups); @@ -777,6 +777,7 @@ bool StatsHistory::parseSummaryLine(const char* line, HistorySample& sample) con sample.uptime_secs = static_cast(uptime_secs); sample.packets_sent = static_cast(packets_sent); sample.packets_recv = static_cast(packets_recv); + sample.recv_errors = static_cast(recv_errors); sample.heap_free = static_cast(heap_free); sample.heap_min = static_cast(heap_free); sample.psram_free = static_cast(psram_free); @@ -784,7 +785,6 @@ bool StatsHistory::parseSummaryLine(const char* line, HistorySample& sample) con sample.battery_mv = static_cast(battery_mv); sample.queue_len = static_cast(queue_len); sample.error_flags = static_cast(error_flags); - sample.recv_errors = static_cast(recv_errors); sample.neighbour_count = static_cast(neighbour_count); sample.direct_dups = static_cast(direct_dups); sample.flood_dups = static_cast(flood_dups); diff --git a/src/helpers/StatsHistory.h b/src/helpers/StatsHistory.h index e5fb8c4a..1620ec24 100644 --- a/src/helpers/StatsHistory.h +++ b/src/helpers/StatsHistory.h @@ -10,6 +10,7 @@ struct HistorySample { uint32_t uptime_secs; uint32_t packets_sent; uint32_t packets_recv; + uint32_t recv_errors; uint32_t heap_free; uint32_t heap_min; uint32_t psram_free; @@ -17,7 +18,6 @@ struct HistorySample { uint16_t battery_mv; uint16_t queue_len; uint16_t error_flags; - uint16_t recv_errors; uint16_t neighbour_count; uint16_t direct_dups; uint16_t flood_dups;