From 2dc00eaa76ee378a8e90229cf972a724ee8c3017 Mon Sep 17 00:00:00 2001 From: medentem Date: Sun, 15 Dec 2024 15:26:38 -0600 Subject: [PATCH] adding userpref option for decoupling the auto discovery channel from auto position updates --- src/modules/NodeInfoModule.cpp | 6 ++++++ src/modules/PositionModule.cpp | 8 ++++++++ userPrefs.jsonc | 1 + 3 files changed, 15 insertions(+) diff --git a/src/modules/NodeInfoModule.cpp b/src/modules/NodeInfoModule.cpp index b55d47d5b..f175bf7a4 100644 --- a/src/modules/NodeInfoModule.cpp +++ b/src/modules/NodeInfoModule.cpp @@ -53,6 +53,12 @@ void NodeInfoModule::sendOurNodeInfo(NodeNum dest, bool wantReplies, uint8_t cha LOG_DEBUG("Send ourNodeInfo to channel %d", channel); p->channel = channel; } +#ifdef USERPREFS_CONFIG_DISCOVERY_CHANNEL + // If this is a broadcast over the default channel, we can safely change this to the discovery channel if defined + if (dest === NODENUM_BROADCAST && channel === 0) { + p->channel = USERPREFS_CONFIG_DISCOVERY_CHANNEL; + } +#endif prevPacketId = p->id; diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index 6285d7aa5..0a7bae335 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -1,5 +1,6 @@ #if !MESHTASTIC_EXCLUDE_GPS #include "PositionModule.h" +#include "NodeInfoModule.h" #include "Default.h" #include "GPS.h" #include "MeshService.h" @@ -315,6 +316,13 @@ void PositionModule::sendOurPosition() // If we changed channels, ask everyone else for their latest info LOG_INFO("Send pos@%x:6 to mesh (wantReplies=%d)", localPosition.timestamp, requestReplies); sendOurPosition(NODENUM_BROADCAST, requestReplies); + +#ifdef USERPREFS_CONFIG_DISCOVERY_CHANNEL + // If the user wants discovery on a different channel, send only nodeinfo to that channel + // sendOurNodeInfo() will automatically handle routing a nodeinfo packet to the correct channel + assert(nodeInfoModule); + nodeInfoModule->sendOurNodeInfo(); +#endif } void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t channel) diff --git a/userPrefs.jsonc b/userPrefs.jsonc index 055f59273..8b6d3d36f 100644 --- a/userPrefs.jsonc +++ b/userPrefs.jsonc @@ -34,4 +34,5 @@ // "USERPREFS_USE_ADMIN_KEY_0": "{ 0xcd, 0xc0, 0xb4, 0x3c, 0x53, 0x24, 0xdf, 0x13, 0xca, 0x5a, 0xa6, 0x0c, 0x0d, 0xec, 0x85, 0x5a, 0x4c, 0xf6, 0x1a, 0x96, 0x04, 0x1a, 0x3e, 0xfc, 0xbb, 0x8e, 0x33, 0x71, 0xe5, 0xfc, 0xff, 0x3c }", // "USERPREFS_USE_ADMIN_KEY_1": "{}", // "USERPREFS_USE_ADMIN_KEY_2": "{}" + // "USERPREFS_CONFIG_DISCOVERY_CHANNEL": "2" } \ No newline at end of file