From 4c6c20c3273164aeeb3403596230bd5eec437cc5 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Thu, 25 Jul 2024 00:52:58 -0700 Subject: [PATCH] repeaterFunction enhance.. enhance.. --- README.md | 9 +++++++++ config.template | 20 +++++++++++++++----- mesh_bot.py | 19 ++++++++++++++++++- modules/settings.py | 7 ++++++- modules/system.py | 3 --- 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index dd514e0..410e04c 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,15 @@ StoreForward = False ``` The BBS has admin and block lists, see the [`config.template`](config.template) +A repeater function for two different nodes and cross posting messages. The `repeater_channels` is a list of repeater channels ex: [2, 3] which will be consumed and rebroadcasted on the same channel on the other device/node/interface. With great power comes great responsibility, danger could be lurking in use of this feature! If you have the two nodes on the same radio configurations, you could create a feedback loop!!! + +``` +# repeater module +[repeater] +enabled = True +repeater_channels = [2, 3] +``` + # requirements can also be installed with `pip install -r requirements.txt` diff --git a/config.template b/config.template index a58048c..4fd7595 100644 --- a/config.template +++ b/config.template @@ -42,10 +42,10 @@ URL_TIMEOUT = 10 [bbs] enabled = True -# list of banned nodes numbers ex: [2813308004, 4258675309] -bbs_ban_list = [] -# list of admin nodes numbers ex: [2813308004, 4258675309] -bbs_admin_list = [] +# list of banned nodes numbers ex: 2813308004,4258675309 +bbs_ban_list = +# list of admin nodes numbers ex: 2813308004,4258675309 +bbs_admin_list = # location module [location] @@ -59,4 +59,14 @@ ALERT_COUNT = 2 # solar module [solar] -enabled = True \ No newline at end of file +enabled = True + +# repeater module +[repeater] +enabled = False +# list of repeater channels ex: 2,3 which will be consumed +# and rebroadcasted on the same channel on the other device/node/interface +# with great power comes great responsibility, danger could be lurking in use of this feature +# if you have the two nodes on the same radio configurations, you could create a feedback loop +repeater_channels = + diff --git a/mesh_bot.py b/mesh_bot.py index 41ac3a6..bb3f7fd 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -257,6 +257,7 @@ def onReceive(packet, interface): # respond to channel message on the channel itself send_message(auto_response(message_string, snr, rssi, hop, message_from_id, channel_number, rxNode), channel_number, 0, rxNode) else: + # ignore the message but add it to the message history and repeat it if enabled # add the message to the message history but limit if zuluTime: timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") @@ -269,7 +270,21 @@ def onReceive(packet, interface): msg_history.pop(0) msg_history.append((get_name_from_number(message_from_id, 'long', rxNode), message_string, channel_number, timestamp, rxNode)) - print(f"{log_timestamp()} System: Ignoring incoming Device:{rxNode} Channel:{channel_number} Message: {message_string} From: {get_name_from_number(message_from_id)}") + # check if repeater is enabled and the other interface is enabled + if repeater_enabled and interface2_enabled: + # repeat the message on the other device + rMsg = (f"{message_string} From:{get_name_from_number(message_from_id, 'short', rxNode)}") + # if channel found in the repeater list repeat the message + if str(channel_number) in repeater_channels: + if rxNode == 1: + print(f"{log_timestamp()} Repeating message on Device2 Channel:{channel_number}") + send_message(rMsg, channel_number, 0, 2) + elif rxNode == 2: + print(f"{log_timestamp()} Repeating message on Device1 Channel:{channel_number}") + send_message(rMsg, channel_number, 0, 1) + + else: + print(f"{log_timestamp()} System: Ignoring incoming Device:{rxNode} Channel:{channel_number} Message: {message_string} From: {get_name_from_number(message_from_id)}") except KeyError as e: print(f"{log_timestamp()} System: Error processing packet: {e} Device:{rxNode}") @@ -290,6 +305,8 @@ def start_rx(): print(f"System: Store and Forward Enabled") if useDMForResponse: print(f"System: Respond by DM only") + if repeater_enabled: + print(f"System: Repeater Enabled") # Start the receive loop pub.subscribe(onReceive, 'meshtastic.receive') print (f"{log_timestamp()} System: Autoresponder Started for Device1 {get_name_from_number(myNodeNum, 'long', 1)}") diff --git a/modules/settings.py b/modules/settings.py index d8a460d..f436618 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -10,6 +10,7 @@ MOTD = 'Thanks for using MeshBOT! Have a good day!' msg_history = [] # message history for the store and forward feature bbs_ban_list = [] # list of banned users bbs_admin_list = [] # list of admin users +repeater_channels = [] # list of channels to listen on for repeater mode # Read the config file, if it does not exist, create basic config file config = configparser.ConfigParser() @@ -29,6 +30,7 @@ if config.sections() == []: config['bbs'] = {'enabled': 'True', 'bbsdb': 'bbsdb.pkl'} config['location'] = {'enabled': 'True','lat': '48.50', 'lon': '-123.0'} config['solar'] = {'enabled': 'True'} + config['repeater'] = {'enabled': 'false'} config.write(open(config_file, 'w')) print (f"System: Config file created, check {config_file} or review the config.template") @@ -67,4 +69,7 @@ urlTimeoutSeconds = config['general'].getint('URL_TIMEOUT', 10) # default 10 sec forecastDuration = config['general'].getint('DAYS_OF_WEATHER', 4) # default days of weather numWxAlerts = config['general'].getint('ALERT_COUNT', 2) # default 2 alerts bbs_ban_list = config['bbs'].get('ban_list', '').split(',') -bbs_admin_list = config['bbs'].get('admin_list', '').split(',') \ No newline at end of file +bbs_admin_list = config['bbs'].get('admin_list', '').split(',') +repeater_enabled = config['repeater'].getboolean('enabled', False) +repeater_channels = config['repeater'].get('repeater_channels', '').split(',') + diff --git a/modules/system.py b/modules/system.py index 812d8bd..4cbf940 100644 --- a/modules/system.py +++ b/modules/system.py @@ -121,7 +121,6 @@ def get_name_from_number(number, type='long', RXnodeId=1): return name return ERROR_FETCHING_DATA - def get_node_list(nodeInt=1): if interface1.nodes: @@ -181,8 +180,6 @@ def get_node_list(nodeInt=1): return node1 + node2 - - def get_node_location(number, nodeInt=1): # Get the location of a node by its number from nodeDB on device latitude = 0