diff --git a/src/mesh/SinglePortModule.h b/src/mesh/SinglePortModule.h index 2e587cb89..57db73221 100644 --- a/src/mesh/SinglePortModule.h +++ b/src/mesh/SinglePortModule.h @@ -18,6 +18,9 @@ class SinglePortModule : public MeshModule SinglePortModule(const char *_name, PortNum _ourPortNum) : MeshModule(_name), ourPortNum(_ourPortNum) {} protected: + uint32_t max_channel_util_percent = 40; + uint32_t polite_channel_util_percent = 25; + /** * @return true if you want to receive the specified portnum */ diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index 572d7063b..9e4a44679 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -144,7 +144,7 @@ int32_t PositionModule::runOnce() if (lastGpsSend == 0 || (now - lastGpsSend) >= intervalMs) { // Only send packets if the channel is less than 40% utilized. - if (airTime->channelUtilizationPercent() < 40) { + if (airTime->channelUtilizationPercent() < max_channel_util_percent) { if (node->has_position && (node->position.latitude_i != 0 || node->position.longitude_i != 0)) { lastGpsSend = now; @@ -165,7 +165,7 @@ int32_t PositionModule::runOnce() } else if (config.position.position_broadcast_smart_enabled) { // Only send packets if the channel is less than 25% utilized. - if (airTime->channelUtilizationPercent() < 25) { + if (airTime->channelUtilizationPercent() < polite_channel_util_percent) { NodeInfo *node2 = service.refreshMyNodeInfo(); // should guarantee there is now a position diff --git a/src/modules/Telemetry/DeviceTelemetry.cpp b/src/modules/Telemetry/DeviceTelemetry.cpp index 612cf6c1f..9e541efd4 100644 --- a/src/modules/Telemetry/DeviceTelemetry.cpp +++ b/src/modules/Telemetry/DeviceTelemetry.cpp @@ -13,15 +13,16 @@ int32_t DeviceTelemetryModule::runOnce() { #ifndef ARCH_PORTDUINO - if (firstTime) { - // This is the first time the OSThread library has called this function, so do some setup - firstTime = 0; - DEBUG_MSG("Device Telemetry: Initializing\n"); + uint32_t now = millis(); + if ((lastSentToMesh == 0 || (now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.device_update_interval)) + && airTime->channelUtilizationPercent() < max_channel_util_percent) { + sendTelemetry(); + lastSentToMesh = now; + } else { + // Just send to phone when it's not our time to send to mesh yet + sendTelemetry(NODENUM_BROADCAST, true); } - sendOurTelemetry(); - // OSThread library. Multiply the preference value by 1000 to convert seconds to miliseconds - - return getConfiguredOrDefaultMs(moduleConfig.telemetry.device_update_interval); + return sendToPhoneIntervalMs; #endif } @@ -45,7 +46,7 @@ bool DeviceTelemetryModule::handleReceivedProtobuf(const MeshPacket &mp, Telemet return false; // Let others look at this message also if they want } -bool DeviceTelemetryModule::sendOurTelemetry(NodeNum dest, bool wantReplies) +bool DeviceTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) { Telemetry t; @@ -68,11 +69,16 @@ bool DeviceTelemetryModule::sendOurTelemetry(NodeNum dest, bool wantReplies) MeshPacket *p = allocDataProtobuf(t); p->to = dest; - p->decoded.want_response = wantReplies; + p->decoded.want_response = false; lastMeasurementPacket = packetPool.allocCopy(*p); - DEBUG_MSG("Device Telemetry: Sending packet to mesh\n"); - service.sendToMesh(p, RX_SRC_LOCAL, true); nodeDB.updateTelemetry(nodeDB.getNodeNum(), t, RX_SRC_LOCAL); + if (phoneOnly) { + DEBUG_MSG("Device Telemetry: Sending packet to phone\n"); + service.sendToPhone(p); + } else { + DEBUG_MSG("Device Telemetry: Sending packet to mesh\n"); + service.sendToMesh(p, RX_SRC_LOCAL, true); + } return true; } diff --git a/src/modules/Telemetry/DeviceTelemetry.h b/src/modules/Telemetry/DeviceTelemetry.h index 1a10ffcfa..a59e9c000 100644 --- a/src/modules/Telemetry/DeviceTelemetry.h +++ b/src/modules/Telemetry/DeviceTelemetry.h @@ -24,9 +24,10 @@ class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModu /** * Send our Telemetry into the mesh */ - bool sendOurTelemetry(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false); + bool sendTelemetry(NodeNum dest = NODENUM_BROADCAST, bool phoneOnly = false); private: - bool firstTime = 1; + uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute + uint32_t lastSentToMesh = 0; const MeshPacket *lastMeasurementPacket; }; diff --git a/src/modules/esp32/StoreForwardModule.cpp b/src/modules/esp32/StoreForwardModule.cpp index 95aeef709..e51296824 100644 --- a/src/modules/esp32/StoreForwardModule.cpp +++ b/src/modules/esp32/StoreForwardModule.cpp @@ -27,7 +27,7 @@ int32_t StoreForwardModule::runOnce() if (this->busy) { // Only send packets if the channel is less than 25% utilized. - if (airTime->channelUtilizationPercent() < 25) { + if (airTime->channelUtilizationPercent() < polite_channel_util_percent) { // DEBUG_MSG("--- --- --- In busy loop 1 %d\n", this->packetHistoryTXQueue_index); storeForwardModule->sendPayload(this->busyTo, this->packetHistoryTXQueue_index);