Send device telemetry to phone every minute (#1784)

This commit is contained in:
Ben Meadors 2022-10-11 10:21:30 -05:00 committed by GitHub
parent b2c3b405b1
commit 434db4347b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 17 deletions

View File

@ -18,6 +18,9 @@ class SinglePortModule : public MeshModule
SinglePortModule(const char *_name, PortNum _ourPortNum) : MeshModule(_name), ourPortNum(_ourPortNum) {} SinglePortModule(const char *_name, PortNum _ourPortNum) : MeshModule(_name), ourPortNum(_ourPortNum) {}
protected: 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 * @return true if you want to receive the specified portnum
*/ */

View File

@ -144,7 +144,7 @@ int32_t PositionModule::runOnce()
if (lastGpsSend == 0 || (now - lastGpsSend) >= intervalMs) { if (lastGpsSend == 0 || (now - lastGpsSend) >= intervalMs) {
// Only send packets if the channel is less than 40% utilized. // 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)) { if (node->has_position && (node->position.latitude_i != 0 || node->position.longitude_i != 0)) {
lastGpsSend = now; lastGpsSend = now;
@ -165,7 +165,7 @@ int32_t PositionModule::runOnce()
} else if (config.position.position_broadcast_smart_enabled) { } else if (config.position.position_broadcast_smart_enabled) {
// Only send packets if the channel is less than 25% utilized. // 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 NodeInfo *node2 = service.refreshMyNodeInfo(); // should guarantee there is now a position

View File

@ -13,15 +13,16 @@
int32_t DeviceTelemetryModule::runOnce() int32_t DeviceTelemetryModule::runOnce()
{ {
#ifndef ARCH_PORTDUINO #ifndef ARCH_PORTDUINO
if (firstTime) { uint32_t now = millis();
// This is the first time the OSThread library has called this function, so do some setup if ((lastSentToMesh == 0 || (now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.device_update_interval))
firstTime = 0; && airTime->channelUtilizationPercent() < max_channel_util_percent) {
DEBUG_MSG("Device Telemetry: Initializing\n"); sendTelemetry();
lastSentToMesh = now;
} else {
// Just send to phone when it's not our time to send to mesh yet
sendTelemetry(NODENUM_BROADCAST, true);
} }
sendOurTelemetry(); return sendToPhoneIntervalMs;
// OSThread library. Multiply the preference value by 1000 to convert seconds to miliseconds
return getConfiguredOrDefaultMs(moduleConfig.telemetry.device_update_interval);
#endif #endif
} }
@ -45,7 +46,7 @@ bool DeviceTelemetryModule::handleReceivedProtobuf(const MeshPacket &mp, Telemet
return false; // Let others look at this message also if they want 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; Telemetry t;
@ -68,11 +69,16 @@ bool DeviceTelemetryModule::sendOurTelemetry(NodeNum dest, bool wantReplies)
MeshPacket *p = allocDataProtobuf(t); MeshPacket *p = allocDataProtobuf(t);
p->to = dest; p->to = dest;
p->decoded.want_response = wantReplies; p->decoded.want_response = false;
lastMeasurementPacket = packetPool.allocCopy(*p); 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); 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; return true;
} }

View File

@ -24,9 +24,10 @@ class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModu
/** /**
* Send our Telemetry into the mesh * 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: private:
bool firstTime = 1; uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute
uint32_t lastSentToMesh = 0;
const MeshPacket *lastMeasurementPacket; const MeshPacket *lastMeasurementPacket;
}; };

View File

@ -27,7 +27,7 @@ int32_t StoreForwardModule::runOnce()
if (this->busy) { if (this->busy) {
// Only send packets if the channel is less than 25% utilized. // 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); // DEBUG_MSG("--- --- --- In busy loop 1 %d\n", this->packetHistoryTXQueue_index);
storeForwardModule->sendPayload(this->busyTo, this->packetHistoryTXQueue_index); storeForwardModule->sendPayload(this->busyTo, this->packetHistoryTXQueue_index);