From ad7e48d028b761740148e8a1910e7512149039dd Mon Sep 17 00:00:00 2001 From: agessaman Date: Thu, 29 Jan 2026 20:41:48 -0800 Subject: [PATCH] add support for recv_errors in STATUS_PACKETS response --- README.md | 2 +- examples/ble_stats.py | 5 +++++ src/meshcore/reader.py | 12 +++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 926a5c3..827467c 100644 --- a/README.md +++ b/README.md @@ -523,7 +523,7 @@ All commands are async methods that return `Event` objects. Commands are organiz | **Statistics** |||| | `get_stats_core()` | None | `STATS_CORE` | Get core statistics (voltage, uptime, errors, queue length) | | `get_stats_radio()` | None | `STATS_RADIO` | Get radio statistics (noise floor, last RSSI/SNR, tx/rx time stats) | -| `get_stats_packets()` | None | `STATS_PACKETS` | Get packet statistics (rx/tx totals, breakdown by flood vs. direct) | +| `get_stats_packets()` | None | `STATS_PACKETS` | Get packet statistics (rx/tx totals, flood vs. direct, recv_errors when present) | | **Advanced Configuration** |||| | `set_multi_acks(multi_acks)` | `multi_acks: int` | `OK` | Set multi-acks mode (experimental ack repeats) | diff --git a/examples/ble_stats.py b/examples/ble_stats.py index 91bff5e..0a63c99 100755 --- a/examples/ble_stats.py +++ b/examples/ble_stats.py @@ -53,6 +53,11 @@ async def main(): else: print("📦 Packet Statistics:") print(json.dumps(result.payload, indent=2)) + recv_errors = result.payload.get("recv_errors") + if recv_errors is not None: + print(f" Receive/CRC errors (RadioLib): {recv_errors}") + else: + print(" Receive/CRC errors (RadioLib): not reported (legacy 26-byte frame)") print() except Exception as e: diff --git a/src/meshcore/reader.py b/src/meshcore/reader.py index c65a8eb..584b4fd 100644 --- a/src/meshcore/reader.py +++ b/src/meshcore/reader.py @@ -346,10 +346,11 @@ class MessageReader: await self.dispatcher.dispatch(Event(EventType.ERROR, {"reason": f"binary_parse_error: {e}"})) elif stats_type == 2: # STATS_TYPE_PACKETS - # RESP_CODE_STATS + STATS_TYPE_PACKETS: 26 bytes total - # Format: = 30: + (recv_errors,) = struct.unpack('