mirror of
https://github.com/pyMC-dev/pyMC_Repeater.git
synced 2026-06-21 02:25:25 +02:00
0251304407
Every MQTT-published packet has shipped with duration="0" since the PacketRecord factory was introduced. The repeater already computes LoRa time-on-air via AirtimeManager.calculate_airtime() (the canonical Semtech reference formula) for duty-cycle gating and TX delay, but the result was thrown away after each packet - never stored on the packet_record dict that flows to MQTT/SQLite/Glass/websocket. What changes - engine.py: RepeaterHandler._build_packet_record() now computes airtime_ms once per packet (Semtech formula via AirtimeManager) and stores it as packet_record['airtime_ms']. Single source of truth for every downstream consumer. - storage_utils.py: PacketRecord.from_packet_record() reads the new airtime_ms field and serializes it as a rounded integer in the 'duration' field of the published JSON. Falls back to 0 if the field is missing (backward compatibility for any older code path). - storage_collector.py: _publish_packet_to_mqtt() simplified - no recomputation, no helper. The publish path is now a passthrough. Why MQTT consumers (firmware-compatible analyzers, dashboards, the upstream meshcoretomqtt project) expect the same time-on-air value the firmware emits. Hard-coded "0" makes airtime/utilization charts derived from the mqtt stream useless and silently diverges from firmware behavior. Plumbing the value through packet_record (instead of recomputing in the publish path) means any future consumer - SQLite schema, web UI charts, Glass telemetry - reads the same number without separate calculations. Tests tests/test_packet_duration.py - 5 tests covering: - backward compat (legacy packet_record without airtime_ms => '0') - airtime_ms field flows through to duration as rounded integer string - explicit zero stays '0' - AirtimeManager output matches an independently-implemented Semtech reference for typical MeshCore EU settings (SF8/62.5kHz/CR4-8) - low-data-rate optimization branch (SF12/125kHz triggers DE=1) Co-Authored-By: Oz <oz-agent@warp.dev>