From fd37ac33bb03f87f5a9f4e2f7ba6e720cca4aa54 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 6 Nov 2024 05:53:48 -0600 Subject: [PATCH] Smarter traffic scaling --- src/mesh/Default.cpp | 5 +++++ src/mesh/Default.h | 27 +++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/mesh/Default.cpp b/src/mesh/Default.cpp index 653528b607..ba1dafe702 100644 --- a/src/mesh/Default.cpp +++ b/src/mesh/Default.cpp @@ -1,5 +1,6 @@ #include "Default.h" #include "../userPrefs.h" +#include "meshUtils.h" uint32_t Default::getConfiguredOrDefaultMs(uint32_t configuredInterval, uint32_t defaultInterval) { @@ -40,6 +41,10 @@ uint32_t Default::getConfiguredOrDefaultMsScaled(uint32_t configured, uint32_t d if (config.device.role == meshtastic_Config_DeviceConfig_Role_ROUTER) return getConfiguredOrDefaultMs(configured, defaultValue); + // Additionally if we're a tracker or sensor, we want priority to send position and telemetry + if (IS_ONE_OF(config.device.role, meshtastic_Config_DeviceConfig_Role_SENSOR, meshtastic_Config_DeviceConfig_Role_TRACKER)) + return getConfiguredOrDefaultMs(configured, defaultValue); + return getConfiguredOrDefaultMs(configured, defaultValue) * congestionScalingCoefficient(numOnlineNodes); } diff --git a/src/mesh/Default.h b/src/mesh/Default.h index 2406dafc52..7a7507c84e 100644 --- a/src/mesh/Default.h +++ b/src/mesh/Default.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include #define ONE_DAY 24 * 60 * 60 #define ONE_MINUTE_MS 60 * 1000 #define THIRTY_SECONDS_MS 30 * 1000 @@ -41,12 +42,30 @@ class Default private: static float congestionScalingCoefficient(int numOnlineNodes) { - if (numOnlineNodes <= 40) { - return 1.0; // No scaling for 40 or fewer nodes + // Increase frequency of broadcasts for small networks regardless of preset + if (numOnlineNodes <= 10) { + return 0.6; + } else if (numOnlineNodes <= 20) { + return 0.7; + } else if (numOnlineNodes <= 30) { + return 0.8; + } else if (numOnlineNodes <= 40) { + return 1.0; } else { - // Sscaling based on number of nodes over 40 + float throttlingFactor = 0.075; + if (config.lora.use_preset && config.lora.modem_preset == meshtastic_Config_LoRaConfig_ModemPreset_MEDIUM_SLOW) + throttlingFactor = 0.04; + else if (config.lora.use_preset && config.lora.modem_preset == meshtastic_Config_LoRaConfig_ModemPreset_MEDIUM_FAST) + throttlingFactor = 0.02; + else if (config.lora.use_preset && config.lora.modem_preset == meshtastic_Config_LoRaConfig_ModemPreset_SHORT_SLOW) + throttlingFactor = 0.01; + else if (config.lora.use_preset && + IS_ONE_OF(config.lora.modem_preset, meshtastic_Config_LoRaConfig_ModemPreset_SHORT_FAST, + meshtastic_Config_LoRaConfig_ModemPreset_SHORT_TURBO)) + return 1.0; // Don't bother throttling for highest bandwidth presets + // Scaling up traffic based on number of nodes over 40 int nodesOverForty = (numOnlineNodes - 40); - return 1.0 + (nodesOverForty * 0.075); // Each number of online node scales by 0.075 + return 1.0 + (nodesOverForty * throttlingFactor); // Each number of online node scales by 0.075 (default) } } }; \ No newline at end of file