Merge pull request #1148 from mc-hamster/master

position plugin - only send if channel utilization is <50 percent
This commit is contained in:
Jm Casler 2022-01-26 22:40:52 -08:00 committed by GitHub
commit 7613c7bf83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 37 deletions

View File

@ -3,6 +3,7 @@
#include "NodeDB.h" #include "NodeDB.h"
#include "RTC.h" #include "RTC.h"
#include "Router.h" #include "Router.h"
#include "airtime.h"
#include "configuration.h" #include "configuration.h"
#include "gps/GeoCoord.h" #include "gps/GeoCoord.h"
@ -127,12 +128,15 @@ int32_t PositionPlugin::runOnce()
{ {
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
//radioConfig.preferences.position_broadcast_smart = true; // radioConfig.preferences.position_broadcast_smart = true;
// We limit our GPS broadcasts to a max rate // We limit our GPS broadcasts to a max rate
uint32_t now = millis(); uint32_t now = millis();
if (lastGpsSend == 0 || now - lastGpsSend >= getPref_position_broadcast_secs() * 1000) { if (lastGpsSend == 0 || now - lastGpsSend >= getPref_position_broadcast_secs() * 1000) {
// Only send packets if the channel is less than 40% utilized.
if (airTime->channelUtilizationPercent() < 40) {
lastGpsSend = now; lastGpsSend = now;
lastGpsLatitude = node->position.latitude_i; lastGpsLatitude = node->position.latitude_i;
@ -143,8 +147,18 @@ int32_t PositionPlugin::runOnce()
currentGeneration = radioGeneration; currentGeneration = radioGeneration;
DEBUG_MSG("Sending pos@%x:6 to mesh (wantReplies=%d)\n", node->position.pos_timestamp, requestReplies); DEBUG_MSG("Sending pos@%x:6 to mesh (wantReplies=%d)\n", node->position.pos_timestamp, requestReplies);
sendOurPosition(NODENUM_BROADCAST, requestReplies); sendOurPosition(NODENUM_BROADCAST, requestReplies);
} else {
DEBUG_MSG("Channel utilization is >50 percent. Skipping this opportunity to send.\n");
}
} else if (radioConfig.preferences.position_broadcast_smart == true) { } else if (radioConfig.preferences.position_broadcast_smart == true) {
// Only send packets if the channel is less than 40% utilized.
if (airTime->channelUtilizationPercent() < 40) {
NodeInfo *node2 = service.refreshMyNodeInfo(); // should guarantee there is now a position NodeInfo *node2 = service.refreshMyNodeInfo(); // should guarantee there is now a position
if (node2->has_position && (node2->position.latitude_i != 0 || node2->position.longitude_i != 0)) { if (node2->has_position && (node2->position.latitude_i != 0 || node2->position.longitude_i != 0)) {
@ -159,21 +173,22 @@ int32_t PositionPlugin::runOnce()
node->position.latitude_i * 1e-7, node->position.longitude_i * 1e-7); node->position.latitude_i * 1e-7, node->position.longitude_i * 1e-7);
// Yes, this has a bunch of magic numbers. Sorry. This is to make the scale non-linear. // Yes, this has a bunch of magic numbers. Sorry. This is to make the scale non-linear.
const float distanceTravelMath = 1203 / (sqrt( pow(myNodeInfo.bitrate, 1.5) / 1.1 ) ) ; const float distanceTravelMath = 1203 / (sqrt(pow(myNodeInfo.bitrate, 1.5) / 1.1));
uint32_t distanceTravel = (distanceTravelMath >= distanceTravelMinimum) ? distanceTravelMath : distanceTravelMinimum; uint32_t distanceTravel =
(distanceTravelMath >= distanceTravelMinimum) ? distanceTravelMath : distanceTravelMinimum;
// Yes, this has a bunch of magic numbers. Sorry. // Yes, this has a bunch of magic numbers. Sorry.
uint32_t timeTravel = ((1500 / myNodeInfo.bitrate) >= timeTravelMinimum) ? (1500 / myNodeInfo.bitrate) : timeTravelMinimum; uint32_t timeTravel =
((1500 / myNodeInfo.bitrate) >= timeTravelMinimum) ? (1500 / myNodeInfo.bitrate) : timeTravelMinimum;
// If the distance traveled since the last update is greater than 100 meters // If the distance traveled since the last update is greater than 100 meters
// and it's been at least 60 seconds since the last update // and it's been at least 60 seconds since the last update
if ((abs(distance) >= distanceTravel) && if ((abs(distance) >= distanceTravel) && (now - lastGpsSend >= timeTravel * 1000)) {
(now - lastGpsSend >= timeTravel * 1000)
) {
bool requestReplies = currentGeneration != radioGeneration; bool requestReplies = currentGeneration != radioGeneration;
currentGeneration = radioGeneration; currentGeneration = radioGeneration;
DEBUG_MSG("Sending smart pos@%x:6 to mesh (wantReplies=%d, dt=%d, tt=%d)\n", node2->position.pos_timestamp, requestReplies, distanceTravel, timeTravel); DEBUG_MSG("Sending smart pos@%x:6 to mesh (wantReplies=%d, dt=%d, tt=%d)\n", node2->position.pos_timestamp,
requestReplies, distanceTravel, timeTravel);
sendOurPosition(NODENUM_BROADCAST, requestReplies); sendOurPosition(NODENUM_BROADCAST, requestReplies);
/* Update lastGpsSend to now. This means if the device is stationary, then /* Update lastGpsSend to now. This means if the device is stationary, then
@ -182,6 +197,9 @@ int32_t PositionPlugin::runOnce()
lastGpsSend = now; lastGpsSend = now;
} }
} }
} else {
DEBUG_MSG("Channel utilization is >40 percent. Skipping this opportunity to send.\n");
}
} }
return 5000; // to save power only wake for our callback occasionally return 5000; // to save power only wake for our callback occasionally

View File

@ -78,7 +78,7 @@ int32_t RangeTestPlugin::runOnce()
if (airTime->channelUtilizationPercent() < 25) { if (airTime->channelUtilizationPercent() < 25) {
rangeTestPluginRadio->sendPayload(); rangeTestPluginRadio->sendPayload();
} else { } else {
DEBUG_MSG("rangeTest - Channel utilization is too high. Skipping this opportunity to send and will retry later.\n"); DEBUG_MSG("rangeTest - Channel utilization is >25 percent. Skipping this opportunity to send.\n");
} }
return (senderHeartbeat); return (senderHeartbeat);