From 5fc914cb875248eaef2681cb03f1d2bfe082beb0 Mon Sep 17 00:00:00 2001 From: HarukiToreda <116696711+HarukiToreda@users.noreply.github.com> Date: Fri, 20 Feb 2026 00:56:32 -0500 Subject: [PATCH] Show Local Sensor data if no environment metrice received from the Mesh. --- .../Telemetry/EnvironmentTelemetry.cpp | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/modules/Telemetry/EnvironmentTelemetry.cpp b/src/modules/Telemetry/EnvironmentTelemetry.cpp index b65d4a442..cc4ca635c 100644 --- a/src/modules/Telemetry/EnvironmentTelemetry.cpp +++ b/src/modules/Telemetry/EnvironmentTelemetry.cpp @@ -299,6 +299,29 @@ int32_t EnvironmentTelemetryModule::runOnce() return disable(); } + auto refreshLocalMeasurementPacket = [this]() { + // Keep displaying remote telemetry once we have it. + if (lastMeasurementPacket != nullptr && lastMeasurementPacket->from != nodeDB->getNodeNum()) { + return; + } + + meshtastic_Telemetry local = meshtastic_Telemetry_init_zero; + if (!getEnvironmentTelemetry(&local)) { + return; + } + + meshtastic_MeshPacket *localPacket = allocDataProtobuf(local); + if (localPacket == nullptr) { + return; + } + + if (lastMeasurementPacket != nullptr) { + packetPool.release(lastMeasurementPacket); + } + lastMeasurementPacket = packetPool.allocCopy(*localPacket); + packetPool.release(localPacket); + }; + if (firstTime) { // This is the first time the OSThread library has called this function, so do some setup firstTime = 0; @@ -327,6 +350,7 @@ int32_t EnvironmentTelemetryModule::runOnce() result = rak9154Sensor.runOnce(); #endif #endif + refreshLocalMeasurementPacket(); } // it's possible to have this module enabled, only for displaying values on the screen. // therefore, we should only enable the sensor loop if measurement is also enabled @@ -343,6 +367,7 @@ int32_t EnvironmentTelemetryModule::runOnce() result = delay; } } + refreshLocalMeasurementPacket(); if (((lastSentToMesh == 0) || !Throttle::isWithinTimespanMs(lastSentToMesh, Default::getConfiguredOrDefaultMsScaled( @@ -661,11 +686,14 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) p->priority = meshtastic_MeshPacket_Priority_RELIABLE; else p->priority = meshtastic_MeshPacket_Priority_BACKGROUND; - // release previous packet before occupying a new spot - if (lastMeasurementPacket != nullptr) - packetPool.release(lastMeasurementPacket); + const bool shouldReplaceDisplayPacket = (lastMeasurementPacket == nullptr || lastMeasurementPacket->from == nodeDB->getNodeNum()); + if (shouldReplaceDisplayPacket) { + // release previous packet before occupying a new spot + if (lastMeasurementPacket != nullptr) + packetPool.release(lastMeasurementPacket); - lastMeasurementPacket = packetPool.allocCopy(*p); + lastMeasurementPacket = packetPool.allocCopy(*p); + } if (phoneOnly) { LOG_INFO("Send packet to phone"); service->sendToPhone(p);