From 8861a9694002c27c11ebe9dc460779f38915e5f8 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 21:55:44 -0700 Subject: [PATCH 01/48] Update mesh-bot.py --- mesh-bot.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index 98936b4..03f1811 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -17,7 +17,7 @@ interface = meshtastic.serial_interface.SerialInterface() #serial interface #interface=meshtastic.tcp_interface.TCPInterface(hostname="192.168.0.1") # IP of your device #interface=meshtastic.ble_interface.BLEInterface("AA:BB:CC:DD:EE:FF") # BLE interface -trap_list = ("ping","ack","testing","pong","motd","help","sun","solar","hfcond") #A list of strings to trap and respond to +trap_list = ("ping","ack","testing","pong","motd","help","sun","solar","hfcond","lheard") #A list of strings to trap and respond to welcome_message = "MeshBot, here for you like a friend who is not. Try sending: ping @foo or, help" help_message = "Commands are: ping, ack, motd, sun, solar, hfcond. Use 'motd $foo' to set MOTD." RESPOND_BY_DM_ONLY = True # Set to True to respond messages via DM only (keeps the channel clean) @@ -71,6 +71,8 @@ def auto_response(message,snr,rssi,hop): bot_response = hf_band_conditions() elif "solar" in message.lower(): bot_response = drap_xray_conditions() + "\n" + solar_conditions() + elif "lheard" in message.lower(): + bot_response = "Last 5 nodes heard: " + str(get_node_list()) else: bot_response = "I'm sorry, I'm afraid I can't do that." @@ -146,6 +148,17 @@ def messageTrap(msg): if t.lower() == m.lower(): return True return False + +def get_node_list(): + node_list = [] + if interface.nodes: + + for node in interface.nodes.values(): + #limit list to the last 5 nodes + node_list.append(node['num']) + if len(node_list) > 5: + break + return node_list def send_message(message,ch,nodeid): if nodeid == 0: From 784c8962030db4c5e1511d7f920770d11fddac84 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 21:58:12 -0700 Subject: [PATCH 02/48] Update mesh-bot.py --- mesh-bot.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 03f1811..d2cde92 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -149,14 +149,33 @@ def messageTrap(msg): return True return False +def decimal_to_hex(decimal_number): + return f"!{decimal_number:08x}" + +def get_name_from_number(number, type='long'): + name = "" + for node in interface.nodes.values(): + if number == node['num']: + if type == 'long': + name = node['user']['longName'] + return name + elif type == 'short': + name = node['user']['shortName'] + return name + else: + pass + else: + name = str(decimal_to_hex(number)) # If long name not found, use the ID as string + return name + def get_node_list(): node_list = [] if interface.nodes: for node in interface.nodes.values(): #limit list to the last 5 nodes - node_list.append(node['num']) - if len(node_list) > 5: + node_list.append(get_name_from_number(node['num'])) + if len(node_list) > 4: break return node_list From 528d145ff3746fd749e3d4af1f8e5e66a5a2d392 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 22:00:32 -0700 Subject: [PATCH 03/48] Update mesh-bot.py --- mesh-bot.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index d2cde92..b224942 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -173,9 +173,11 @@ def get_node_list(): if interface.nodes: for node in interface.nodes.values(): - #limit list to the last 5 nodes - node_list.append(get_name_from_number(node['num'])) - if len(node_list) > 4: + #limit list to the last 5 nodes, and ignore own node at 0 + if node['num'] != 0: + node_list.append(get_name_from_number(node['num'])) + + if len(node_list) > 5: break return node_list From cc884c3239aeba749ef58919c70a51089bc7ddf9 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 22:02:52 -0700 Subject: [PATCH 04/48] Update mesh-bot.py --- mesh-bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index b224942..bf5ff8a 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -173,8 +173,8 @@ def get_node_list(): if interface.nodes: for node in interface.nodes.values(): - #limit list to the last 5 nodes, and ignore own node at 0 - if node['num'] != 0: + #limit list to the last 5 nodes, and ignore own + if node['num'] != myNodeNum: node_list.append(get_name_from_number(node['num'])) if len(node_list) > 5: From dd2b51f17267b1eae8ca9b9a6eba61a653951dbf Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 22:10:50 -0700 Subject: [PATCH 05/48] Update mesh-bot.py --- mesh-bot.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index bf5ff8a..7a518de 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -171,11 +171,13 @@ def get_name_from_number(number, type='long'): def get_node_list(): node_list = [] if interface.nodes: - for node in interface.nodes.values(): #limit list to the last 5 nodes, and ignore own if node['num'] != myNodeNum: - node_list.append(get_name_from_number(node['num'])) + #only get recent lastHeard nodes unix timestamp + if node['lastHeard'] > (datetime.now().timestamp() - 500): + node_list.append(get_name_from_number(node['num'])) + if len(node_list) > 5: break From 1df97a843e6481f3c87ad23843d0c4b945755657 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 22:18:21 -0700 Subject: [PATCH 06/48] Update mesh-bot.py --- mesh-bot.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 7a518de..0d7c474 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -172,15 +172,16 @@ def get_node_list(): node_list = [] if interface.nodes: for node in interface.nodes.values(): - #limit list to the last 5 nodes, and ignore own + #ignore own if node['num'] != myNodeNum: - #only get recent lastHeard nodes unix timestamp - if node['lastHeard'] > (datetime.now().timestamp() - 500): - node_list.append(get_name_from_number(node['num'])) + node_list.append(get_name_from_number(node['num'])) - - if len(node_list) > 5: - break + #sort the list by lastHeard + node_list.sort(key=lambda x: x['lastHeard'], reverse=True) + #return only the last 5 nodes + return node_list[:5] + else: + node_list.append("Nothing heard") return node_list def send_message(message,ch,nodeid): From 4a68da6c1439f4e113000b820f6b6d2462d3e7c2 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 22:23:40 -0700 Subject: [PATCH 07/48] Update mesh-bot.py --- mesh-bot.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 0d7c474..4e7eeac 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -176,8 +176,6 @@ def get_node_list(): if node['num'] != myNodeNum: node_list.append(get_name_from_number(node['num'])) - #sort the list by lastHeard - node_list.sort(key=lambda x: x['lastHeard'], reverse=True) #return only the last 5 nodes return node_list[:5] else: From abf6dbe815b93a829336c5b2dfc501efa2cbb9df Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 22:33:36 -0700 Subject: [PATCH 08/48] Update mesh-bot.py --- mesh-bot.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index 4e7eeac..7b076a9 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -107,12 +107,21 @@ def onReceive(packet, interface): hop_start = packet['hopStart'] else: hop_start = 0 + + # check if the packet has a hop count flag use it + if packet.get('hopsAway'): + hop_away = packet['hopsAway'] # set hop to Direct if the message was sent directly otherwise set the hop count if hop_start == hop_limit: hop = "Direct" else: - hop_count = hop_start - hop_limit + if hop_away: + hop_count = hop_away + print (f"Using hopsAway: {hop_count}") + else: + hop_count = hop_start - hop_limit + print (f"calculated hop count: {hop_start} - {hop_limit} = {hop_count}") hop = f"{hop_count} hops" # If the packet is a DM (Direct Message) respond to it, otherwise validate its a message for us From 883c025fca5dc1c6f90c1500abbf6493a8e967da Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 22:45:47 -0700 Subject: [PATCH 09/48] Update mesh-bot.py --- mesh-bot.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 7b076a9..c8c4084 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -183,10 +183,12 @@ def get_node_list(): for node in interface.nodes.values(): #ignore own if node['num'] != myNodeNum: - node_list.append(get_name_from_number(node['num'])) - - #return only the last 5 nodes - return node_list[:5] + node_list.append(get_name_from_number(node['num']),node['lastHeard']) + #sort by last heard + node_list.sort(key=lambda x: x[1], reverse=True) + #return only the last 5 nodes 0 value is the name ignore last heard + node_list = [x[0] for x in node_list[:5]] + return node_list else: node_list.append("Nothing heard") return node_list From a9da8e4f70a59dabda07f92754ce9d0c552f046f Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 22:46:51 -0700 Subject: [PATCH 10/48] Update mesh-bot.py --- mesh-bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index c8c4084..b118f89 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -183,7 +183,7 @@ def get_node_list(): for node in interface.nodes.values(): #ignore own if node['num'] != myNodeNum: - node_list.append(get_name_from_number(node['num']),node['lastHeard']) + node_list.append(get_name_from_number(node['num'])),node['lastHeard'] #sort by last heard node_list.sort(key=lambda x: x[1], reverse=True) #return only the last 5 nodes 0 value is the name ignore last heard From 0f481b08e6291970b8e13266bf60b0feb96d2b8b Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 22:48:58 -0700 Subject: [PATCH 11/48] Update mesh-bot.py --- mesh-bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index b118f89..7d6b306 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -187,7 +187,8 @@ def get_node_list(): #sort by last heard node_list.sort(key=lambda x: x[1], reverse=True) #return only the last 5 nodes 0 value is the name ignore last heard - node_list = [x[0] for x in node_list[:5]] + #node_list = [x[0] for x in node_list[:5]] + print(node_list) return node_list else: node_list.append("Nothing heard") From a1965466c19003991b0cd74f902663af2bb9b825 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 22:50:20 -0700 Subject: [PATCH 12/48] Update mesh-bot.py --- mesh-bot.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 7d6b306..0c4dca4 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -183,13 +183,10 @@ def get_node_list(): for node in interface.nodes.values(): #ignore own if node['num'] != myNodeNum: - node_list.append(get_name_from_number(node['num'])),node['lastHeard'] - #sort by last heard - node_list.sort(key=lambda x: x[1], reverse=True) - #return only the last 5 nodes 0 value is the name ignore last heard - #node_list = [x[0] for x in node_list[:5]] - print(node_list) - return node_list + node_list.append(get_name_from_number(node['num'])) + + #return only the last 5 nodes + return node_list[:5] else: node_list.append("Nothing heard") return node_list From cc87be8c796c6806df0a6210fa5e3b9f12ef1bf2 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 22:54:32 -0700 Subject: [PATCH 13/48] Update mesh-bot.py --- mesh-bot.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 0c4dca4..569066f 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -183,8 +183,10 @@ def get_node_list(): for node in interface.nodes.values(): #ignore own if node['num'] != myNodeNum: - node_list.append(get_name_from_number(node['num'])) - + node_list.append([get_name_from_number(node['num']),node['lastHeard']]) + node_list.sort(key=lambda x: x[1],reverse=True) + + #return only the last 5 nodes return node_list[:5] else: From 582e310b5948ac95bfa526a385db5983b0f97507 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 23:06:05 -0700 Subject: [PATCH 14/48] Update mesh-bot.py --- mesh-bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index 569066f..d0edb2d 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -183,7 +183,8 @@ def get_node_list(): for node in interface.nodes.values(): #ignore own if node['num'] != myNodeNum: - node_list.append([get_name_from_number(node['num']),node['lastHeard']]) + #append the name and the lastHeard value + node_list.append((get_name_from_number(node['num']),node['lastHeard'])) node_list.sort(key=lambda x: x[1],reverse=True) From a46ddedf9ee908c623c2b18bee3e0ddcc616da6b Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 23:08:20 -0700 Subject: [PATCH 15/48] Update mesh-bot.py --- mesh-bot.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index d0edb2d..29c0027 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -111,12 +111,14 @@ def onReceive(packet, interface): # check if the packet has a hop count flag use it if packet.get('hopsAway'): hop_away = packet['hopsAway'] + else: + hop_away = 0 # set hop to Direct if the message was sent directly otherwise set the hop count if hop_start == hop_limit: hop = "Direct" else: - if hop_away: + if hop_away > 0: hop_count = hop_away print (f"Using hopsAway: {hop_count}") else: From 2c1b4457346b4313839cd45764396443c0cda5b8 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 23:13:11 -0700 Subject: [PATCH 16/48] Update mesh-bot.py --- mesh-bot.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index 29c0027..94bf503 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -186,7 +186,10 @@ def get_node_list(): #ignore own if node['num'] != myNodeNum: #append the name and the lastHeard value - node_list.append((get_name_from_number(node['num']),node['lastHeard'])) + node_name = get_name_from_number(node['num']) + last_heard = node['lastHeard'] + node_list.append((node_name,last_heard)) + node_list.sort(key=lambda x: x[1],reverse=True) From 90eebfd4dfe4d924185e6cd76545ebaf3abb32fd Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 23:19:51 -0700 Subject: [PATCH 17/48] Update mesh-bot.py --- mesh-bot.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 94bf503..60b3e25 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -188,9 +188,10 @@ def get_node_list(): #append the name and the lastHeard value node_name = get_name_from_number(node['num']) last_heard = node['lastHeard'] - node_list.append((node_name,last_heard)) - - node_list.sort(key=lambda x: x[1],reverse=True) + node_list.append([node_name,last_heard]) + + #sort matrix by lastHeard + node_list.sort(key=lambda x: x[1], reverse=True) #return only the last 5 nodes From 763e3c63873af9ebd786f57cd0d62556bd7f664b Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 23:22:03 -0700 Subject: [PATCH 18/48] Update mesh-bot.py --- mesh-bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 60b3e25..e07542d 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -188,10 +188,10 @@ def get_node_list(): #append the name and the lastHeard value node_name = get_name_from_number(node['num']) last_heard = node['lastHeard'] - node_list.append([node_name,last_heard]) + print (f"Node: {node_name} Last Heard: {last_heard}") #sort matrix by lastHeard - node_list.sort(key=lambda x: x[1], reverse=True) + #node_list.sort(key=lambda x: x[1], reverse=True) #return only the last 5 nodes From 3cb65d369f7f8e7d37ea0a0e8aa3634b54d450dd Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 23:24:59 -0700 Subject: [PATCH 19/48] Update mesh-bot.py --- mesh-bot.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index e07542d..40d4076 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -185,13 +185,13 @@ def get_node_list(): for node in interface.nodes.values(): #ignore own if node['num'] != myNodeNum: - #append the name and the lastHeard value - node_name = get_name_from_number(node['num']) - last_heard = node['lastHeard'] + if node['lastHeard']: + node_name = get_name_from_number(node['num']) + last_heard = node['lastHeard'] + print (f"Node: {node_name} Last Heard: {last_heard}") - #sort matrix by lastHeard - #node_list.sort(key=lambda x: x[1], reverse=True) + node_list.sort(key=lambda x: x[1], reverse=True) #return only the last 5 nodes From c92b46a951e9eba8e4cd5495b3f1143eafac70c0 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 23:27:52 -0700 Subject: [PATCH 20/48] Update mesh-bot.py --- mesh-bot.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 40d4076..783eb89 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -181,17 +181,20 @@ def get_name_from_number(number, type='long'): def get_node_list(): node_list = [] + node_name = "" + last_heard = "" + if interface.nodes: for node in interface.nodes.values(): #ignore own if node['num'] != myNodeNum: - if node['lastHeard']: - node_name = get_name_from_number(node['num']) - last_heard = node['lastHeard'] + node_name = get_name_from_number(node['num']) + if node['lastHeard']: + last_heard = node['lastHeard'] - print (f"Node: {node_name} Last Heard: {last_heard}") + print (f"Node: {node_name} Last Heard: {last_heard}") - node_list.sort(key=lambda x: x[1], reverse=True) + #node_list.sort(key=lambda x: x[1], reverse=True) #return only the last 5 nodes From eb6b685969952f569e99fbe4028417133b2cd3ef Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 23:30:45 -0700 Subject: [PATCH 21/48] Update mesh-bot.py --- mesh-bot.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 783eb89..30b642d 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -191,8 +191,9 @@ def get_node_list(): node_name = get_name_from_number(node['num']) if node['lastHeard']: last_heard = node['lastHeard'] - - print (f"Node: {node_name} Last Heard: {last_heard}") + node_list.append((node_name,last_heard)) + + print (node_list) #node_list.sort(key=lambda x: x[1], reverse=True) From 7bdf363ccde5811d696226fd6b2dc937a25deee1 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 23:34:46 -0700 Subject: [PATCH 22/48] Update mesh-bot.py --- mesh-bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index 30b642d..9cbc035 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -191,7 +191,8 @@ def get_node_list(): node_name = get_name_from_number(node['num']) if node['lastHeard']: last_heard = node['lastHeard'] - node_list.append((node_name,last_heard)) + item = (node_name,last_heard) + node_list.append(item) print (node_list) From fca2f9f0008932baf64e2edfba362499f322e20a Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 23:43:22 -0700 Subject: [PATCH 23/48] Update mesh-bot.py --- mesh-bot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 9cbc035..d8b6a21 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -151,6 +151,7 @@ def onReceive(packet, interface): except KeyError as e: print(f"System: Error processing packet: {e}") print(packet) # print the packet for debugging + print("END of packet \n") def messageTrap(msg): message_list=msg.split(" ") @@ -194,11 +195,10 @@ def get_node_list(): item = (node_name,last_heard) node_list.append(item) + #sort by last heard + node_list.sort(key=lambda x: x[1], reverse=True) print (node_list) - #node_list.sort(key=lambda x: x[1], reverse=True) - - #return only the last 5 nodes return node_list[:5] else: From 1fd13f98a1675a5d2254b582bf766bc2614b82bd Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 23:46:04 -0700 Subject: [PATCH 24/48] Update mesh-bot.py --- mesh-bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index d8b6a21..882871a 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -193,7 +193,7 @@ def get_node_list(): if node['lastHeard']: last_heard = node['lastHeard'] item = (node_name,last_heard) - node_list.append(item) + node_list += [item] #sort by last heard node_list.sort(key=lambda x: x[1], reverse=True) From fcc16e27eb36b705bab86a889cfd10b294d70804 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 23:55:41 -0700 Subject: [PATCH 25/48] Update mesh-bot.py --- mesh-bot.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mesh-bot.py b/mesh-bot.py index 882871a..507626a 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -9,6 +9,8 @@ import meshtastic.serial_interface #pip install meshtastic import meshtastic.tcp_interface import meshtastic.ble_interface from datetime import datetime +import sys + from solarconditions import * # from the spudgunman/meshing-around repo @@ -150,6 +152,8 @@ def onReceive(packet, interface): except KeyError as e: print(f"System: Error processing packet: {e}") + #get line number of error + print(sys.exc_info()[-1].tb_lineno) print(packet) # print the packet for debugging print("END of packet \n") From 43c7352b04dd0e8f8e3098366b2b55f21c477cee Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 23:57:58 -0700 Subject: [PATCH 26/48] Update mesh-bot.py --- mesh-bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index 507626a..b1454c2 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -74,7 +74,7 @@ def auto_response(message,snr,rssi,hop): elif "solar" in message.lower(): bot_response = drap_xray_conditions() + "\n" + solar_conditions() elif "lheard" in message.lower(): - bot_response = "Last 5 nodes heard: " + str(get_node_list()) + bot_response = "Last 5 nodes heard: " #+ str(get_node_list()) else: bot_response = "I'm sorry, I'm afraid I can't do that." From d9337cbb1567dfd90251da1b960ca395f69f9015 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 18 Jun 2024 23:59:14 -0700 Subject: [PATCH 27/48] Update mesh-bot.py --- mesh-bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mesh-bot.py b/mesh-bot.py index b1454c2..952b740 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -74,6 +74,7 @@ def auto_response(message,snr,rssi,hop): elif "solar" in message.lower(): bot_response = drap_xray_conditions() + "\n" + solar_conditions() elif "lheard" in message.lower(): + get_node_list() bot_response = "Last 5 nodes heard: " #+ str(get_node_list()) else: bot_response = "I'm sorry, I'm afraid I can't do that." From 697c7681cd9326a8612ce6c29a4d0cab58ec6df8 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:02:19 -0700 Subject: [PATCH 28/48] Update mesh-bot.py --- mesh-bot.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 952b740..1878b3c 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -9,8 +9,6 @@ import meshtastic.serial_interface #pip install meshtastic import meshtastic.tcp_interface import meshtastic.ble_interface from datetime import datetime -import sys - from solarconditions import * # from the spudgunman/meshing-around repo @@ -74,8 +72,7 @@ def auto_response(message,snr,rssi,hop): elif "solar" in message.lower(): bot_response = drap_xray_conditions() + "\n" + solar_conditions() elif "lheard" in message.lower(): - get_node_list() - bot_response = "Last 5 nodes heard: " #+ str(get_node_list()) + bot_response = "Last 5 nodes heard: " + str(get_node_list()) else: bot_response = "I'm sorry, I'm afraid I can't do that." @@ -153,8 +150,6 @@ def onReceive(packet, interface): except KeyError as e: print(f"System: Error processing packet: {e}") - #get line number of error - print(sys.exc_info()[-1].tb_lineno) print(packet) # print the packet for debugging print("END of packet \n") @@ -198,17 +193,12 @@ def get_node_list(): if node['lastHeard']: last_heard = node['lastHeard'] item = (node_name,last_heard) - node_list += [item] - #sort by last heard - node_list.sort(key=lambda x: x[1], reverse=True) - print (node_list) - #return only the last 5 nodes return node_list[:5] else: node_list.append("Nothing heard") - return node_list + return node_list def send_message(message,ch,nodeid): if nodeid == 0: From 6f951500b667a6ac973f98b8acabea79508f46a9 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:03:33 -0700 Subject: [PATCH 29/48] Update mesh-bot.py --- mesh-bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index 1878b3c..173ee59 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -190,7 +190,7 @@ def get_node_list(): #ignore own if node['num'] != myNodeNum: node_name = get_name_from_number(node['num']) - if node['lastHeard']: + if node['lastHeard'] != None: last_heard = node['lastHeard'] item = (node_name,last_heard) From fa7a808fba0f62986c1c6369cb8e2b197ec201cb Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:07:38 -0700 Subject: [PATCH 30/48] Update mesh-bot.py --- mesh-bot.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index 173ee59..34de7d3 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -9,6 +9,7 @@ import meshtastic.serial_interface #pip install meshtastic import meshtastic.tcp_interface import meshtastic.ble_interface from datetime import datetime +import time from solarconditions import * # from the spudgunman/meshing-around repo @@ -184,7 +185,8 @@ def get_node_list(): node_list = [] node_name = "" last_heard = "" - + #pause for a second + time.sleep(2) if interface.nodes: for node in interface.nodes.values(): #ignore own From d0111dd3039f42d35cccbc4a09dabef4292f02d0 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:11:21 -0700 Subject: [PATCH 31/48] Update mesh-bot.py --- mesh-bot.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 34de7d3..1cc147c 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -9,7 +9,6 @@ import meshtastic.serial_interface #pip install meshtastic import meshtastic.tcp_interface import meshtastic.ble_interface from datetime import datetime -import time from solarconditions import * # from the spudgunman/meshing-around repo @@ -185,22 +184,24 @@ def get_node_list(): node_list = [] node_name = "" last_heard = "" - #pause for a second - time.sleep(2) - if interface.nodes: - for node in interface.nodes.values(): - #ignore own - if node['num'] != myNodeNum: - node_name = get_name_from_number(node['num']) - if node['lastHeard'] != None: - last_heard = node['lastHeard'] - item = (node_name,last_heard) - - #return only the last 5 nodes - return node_list[:5] - else: - node_list.append("Nothing heard") - return node_list + try: + if interface.nodes: + for node in interface.nodes.values(): + #ignore own + if node['num'] != myNodeNum: + node_name = get_name_from_number(node['num']) + if node['lastHeard'] != None: + last_heard = node['lastHeard'] + item = (node_name,last_heard) + + #return only the last 5 nodes + return node_list[:5] + else: + node_list.append("Nothing heard") + return node_list + except Exception as e: + print(f"System: Error getting node list: {e}") + return "node_list_error" def send_message(message,ch,nodeid): if nodeid == 0: From 72d0470c8b5debcdea976e4acbeff425f219786d Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:13:36 -0700 Subject: [PATCH 32/48] Update mesh-bot.py --- mesh-bot.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 1cc147c..e59914e 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -184,24 +184,24 @@ def get_node_list(): node_list = [] node_name = "" last_heard = "" - try: - if interface.nodes: - for node in interface.nodes.values(): - #ignore own - if node['num'] != myNodeNum: - node_name = get_name_from_number(node['num']) + if interface.nodes: + for node in interface.nodes.values(): + #ignore own + if node['num'] != myNodeNum: + node_name = get_name_from_number(node['num']) + try: if node['lastHeard'] != None: last_heard = node['lastHeard'] - item = (node_name,last_heard) - - #return only the last 5 nodes - return node_list[:5] - else: - node_list.append("Nothing heard") - return node_list - except Exception as e: - print(f"System: Error getting node list: {e}") - return "node_list_error" + except: + print(f"System: Error getting node list: {e}") + last_heard = 0 + item = (node_name,last_heard) + + #return only the last 5 nodes + return node_list[:5] + else: + node_list.append("Nothing heard") + return node_list def send_message(message,ch,nodeid): if nodeid == 0: From 3f0cced459f5a105cb76063ae5cb3c15e3edf657 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:15:03 -0700 Subject: [PATCH 33/48] Update mesh-bot.py --- mesh-bot.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index e59914e..3e1cef9 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -190,9 +190,8 @@ def get_node_list(): if node['num'] != myNodeNum: node_name = get_name_from_number(node['num']) try: - if node['lastHeard'] != None: - last_heard = node['lastHeard'] - except: + last_heard = node['lastHeard'] + except Exception as e: print(f"System: Error getting node list: {e}") last_heard = 0 item = (node_name,last_heard) From 05a1d43bb69280a0dff223bbaf66f7944b4190db Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:16:45 -0700 Subject: [PATCH 34/48] Update mesh-bot.py --- mesh-bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index 3e1cef9..b4d9f72 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -189,12 +189,13 @@ def get_node_list(): #ignore own if node['num'] != myNodeNum: node_name = get_name_from_number(node['num']) + try: last_heard = node['lastHeard'] except Exception as e: - print(f"System: Error getting node list: {e}") last_heard = 0 item = (node_name,last_heard) + node_list.append(item) #return only the last 5 nodes return node_list[:5] From 46ae8a4d781dc3fad276f2f110b4bd595c44e91e Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:20:06 -0700 Subject: [PATCH 35/48] Update mesh-bot.py --- mesh-bot.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index b4d9f72..7c626bb 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -182,13 +182,13 @@ def get_name_from_number(number, type='long'): def get_node_list(): node_list = [] - node_name = "" - last_heard = "" if interface.nodes: for node in interface.nodes.values(): #ignore own if node['num'] != myNodeNum: - node_name = get_name_from_number(node['num']) + name = get_name_from_number(node['num']) + if name != "": + node_name = get_name_from_number(node['num']) try: last_heard = node['lastHeard'] @@ -197,6 +197,8 @@ def get_node_list(): item = (node_name,last_heard) node_list.append(item) + node_list.sort(key=lambda x: x[1], reverse=True) + #return only the last 5 nodes return node_list[:5] else: From 4f70f4ca14ac0e9f9b0365ccdbf13660d0fcc90b Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:23:10 -0700 Subject: [PATCH 36/48] Update mesh-bot.py --- mesh-bot.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index 7c626bb..b1a987e 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -189,6 +189,8 @@ def get_node_list(): name = get_name_from_number(node['num']) if name != "": node_name = get_name_from_number(node['num']) + else: + continue try: last_heard = node['lastHeard'] @@ -198,7 +200,7 @@ def get_node_list(): node_list.append(item) node_list.sort(key=lambda x: x[1], reverse=True) - + #return only the last 5 nodes return node_list[:5] else: From 06d2a6a4e8049f8211d803dfb0088cb82963bc98 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:26:05 -0700 Subject: [PATCH 37/48] Update mesh-bot.py --- mesh-bot.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index b1a987e..08080df 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -190,8 +190,7 @@ def get_node_list(): if name != "": node_name = get_name_from_number(node['num']) else: - continue - + node_name = "Unknown" try: last_heard = node['lastHeard'] except Exception as e: From 924fedbc2cecd61c1e2d0939785641be08f518b3 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:28:29 -0700 Subject: [PATCH 38/48] Update mesh-bot.py --- mesh-bot.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 08080df..cffe277 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -186,15 +186,13 @@ def get_node_list(): for node in interface.nodes.values(): #ignore own if node['num'] != myNodeNum: - name = get_name_from_number(node['num']) - if name != "": - node_name = get_name_from_number(node['num']) - else: - node_name = "Unknown" + node_name = get_name_from_number(node['num']) + try: last_heard = node['lastHeard'] except Exception as e: last_heard = 0 + item = (node_name,last_heard) node_list.append(item) From a9bf1253d61870f196f8bf852cd0509dd72a4ca3 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:30:17 -0700 Subject: [PATCH 39/48] Update mesh-bot.py --- mesh-bot.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index cffe277..bc3b9bd 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -188,13 +188,13 @@ def get_node_list(): if node['num'] != myNodeNum: node_name = get_name_from_number(node['num']) - try: - last_heard = node['lastHeard'] - except Exception as e: - last_heard = 0 - - item = (node_name,last_heard) - node_list.append(item) + try: + last_heard = node['lastHeard'] + except Exception as e: + last_heard = 0 + + item = (node_name,last_heard) + node_list.append(item) node_list.sort(key=lambda x: x[1], reverse=True) From a73aa25856adc3c725d1f533e9fb155946f83550 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:32:30 -0700 Subject: [PATCH 40/48] Update mesh-bot.py --- mesh-bot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index bc3b9bd..58ac37d 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -199,7 +199,8 @@ def get_node_list(): node_list.sort(key=lambda x: x[1], reverse=True) #return only the last 5 nodes - return node_list[:5] + nice_node_list = [x[0] for x in node_list[:5]] + return nice_node_list[:5] else: node_list.append("Nothing heard") return node_list From 554a8d4dcddc2fd0334fdb65b23771d79c6acc37 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:35:42 -0700 Subject: [PATCH 41/48] Update mesh-bot.py --- mesh-bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 58ac37d..b52e80c 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -197,10 +197,10 @@ def get_node_list(): node_list.append(item) node_list.sort(key=lambda x: x[1], reverse=True) - + print (f"Node List: {node_list[:5]}\n") #return only the last 5 nodes nice_node_list = [x[0] for x in node_list[:5]] - return nice_node_list[:5] + return nice_node_list else: node_list.append("Nothing heard") return node_list From 86247d87316fe9b53d6da1a0997db6f2e12a9426 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:39:41 -0700 Subject: [PATCH 42/48] Update mesh-bot.py --- mesh-bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index b52e80c..1c199db 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -197,7 +197,7 @@ def get_node_list(): node_list.append(item) node_list.sort(key=lambda x: x[1], reverse=True) - print (f"Node List: {node_list[:5]}\n") + #print (f"Node List: {node_list[:5]}\n") #return only the last 5 nodes nice_node_list = [x[0] for x in node_list[:5]] return nice_node_list @@ -222,7 +222,7 @@ def exit_handler(signum, frame): print ("\nMeshtastic Autoresponder PONG Bot CTL+C to exit\n") pub.subscribe(onReceive, 'meshtastic.receive') -print (f"System: Autoresponder Started for device {myNodeNum}") +print (f"System: Autoresponder Started for device {get_name_from_number(myNodeNum)}") while True: signal.signal(signal.SIGINT, exit_handler) From 9c6bb740bfed715720f03154a9e6c044e5cc0005 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:42:29 -0700 Subject: [PATCH 43/48] Update mesh-bot.py --- mesh-bot.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mesh-bot.py b/mesh-bot.py index 1c199db..7bbedb4 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -129,16 +129,16 @@ def onReceive(packet, interface): # If the packet is a DM (Direct Message) respond to it, otherwise validate its a message for us if packet['to'] == myNodeNum: if messageTrap(message_string): - print(f"{log_timestamp()} Received DM: {message_string} on Channel: {channel_number} From: {message_from_id}") + print(f"{log_timestamp()} Received DM: {message_string} on Channel: {channel_number} From: {get_name_from_number(message_from_id)}") # respond with a direct message send_message(auto_response(message_string,snr,rssi,hop),channel_number,message_from_id) else: #respond with welcome message - print(f"{log_timestamp()} Ignoring DM: {message_string} From: {message_from_id}") + print(f"{log_timestamp()} Ignoring DM: {message_string} From: {get_name_from_number(message_from_id)}") send_message(welcome_message,channel_number,message_from_id) else: if messageTrap(message_string): - print(f"{log_timestamp()} Received On Channel {channel_number}: {message_string} From: {message_from_id}") + print(f"{log_timestamp()} Received On Channel {channel_number}: {message_string} From: {get_name_from_number(message_from_id)}") if RESPOND_BY_DM_ONLY: # respond to channel message via direct message to keep the channel clean send_message(auto_response(message_string,snr,rssi,hop),channel_number,message_from_id) @@ -146,7 +146,7 @@ def onReceive(packet, interface): # or respond to channel message on the channel itself send_message(auto_response(message_string,snr,rssi),channel_number,0) else: - print(f"{log_timestamp()} System: Ignoring incoming channel {channel_number}: {message_string} From: {message_from_id}") + print(f"{log_timestamp()} System: Ignoring incoming channel {channel_number}: {message_string} From: {get_name_from_number(message_from_id)}") except KeyError as e: print(f"System: Error processing packet: {e}") @@ -212,7 +212,7 @@ def send_message(message,ch,nodeid): print (f"{log_timestamp()} System: Sending: {message} on Channel: {ch}") else: #Send to DM - print (f"{log_timestamp()} System: Sending: {message} To: {nodeid}") + print (f"{log_timestamp()} System: Sending: {message} To: {get_name_from_number(nodeid)}") interface.sendText(text=message,channelIndex=ch,destinationId=nodeid) def exit_handler(signum, frame): From ffe03837cb07249015c3878682c93fa0f9bb1e1e Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:46:00 -0700 Subject: [PATCH 44/48] Update mesh-bot.py --- mesh-bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesh-bot.py b/mesh-bot.py index 7bbedb4..6e4ff8f 100644 --- a/mesh-bot.py +++ b/mesh-bot.py @@ -19,7 +19,7 @@ interface = meshtastic.serial_interface.SerialInterface() #serial interface trap_list = ("ping","ack","testing","pong","motd","help","sun","solar","hfcond","lheard") #A list of strings to trap and respond to welcome_message = "MeshBot, here for you like a friend who is not. Try sending: ping @foo or, help" -help_message = "Commands are: ping, ack, motd, sun, solar, hfcond. Use 'motd $foo' to set MOTD." +help_message = "Commands are: ping, ack, motd, sun, solar, hfcond, lheard. Use 'motd $foo' to set MOTD." RESPOND_BY_DM_ONLY = True # Set to True to respond messages via DM only (keeps the channel clean) MOTD = "Thanks for using PongBOT! Have a good day!" # Message of the Day From c3ebc9c838ba09cd59fc89bd4d5d4c18a926b1e9 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:46:51 -0700 Subject: [PATCH 45/48] Update pong-bot.py --- pong-bot.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 9 deletions(-) diff --git a/pong-bot.py b/pong-bot.py index 0a98dd6..8e73579 100644 --- a/pong-bot.py +++ b/pong-bot.py @@ -16,9 +16,9 @@ interface = meshtastic.serial_interface.SerialInterface() #serial interface #interface=meshtastic.tcp_interface.TCPInterface(hostname="192.168.0.1") # IP of your device #interface=meshtastic.ble_interface.BLEInterface("AA:BB:CC:DD:EE:FF") # BLE interface -trap_list = ("ping","ack","testing","pong","motd","help") #A list of strings to trap and respond to +trap_list = ("ping","ack","testing","pong","motd","help","lheard") #A list of strings to trap and respond to welcome_message = "PongBot, here for you like a friend who is not. Try sending: ping @foo or, help" -help_message = "Commands are: ping, ack, motd, help. Use 'motd $foo' to set MOTD." +help_message = "Commands are: ping, ack, motd, lheard. Use 'motd $foo' to set MOTD." RESPOND_BY_DM_ONLY = True # Set to True to respond messages via DM only (keeps the channel clean) MOTD = "Thanks for using PongBOT! Have a good day!" # Message of the Day @@ -63,6 +63,8 @@ def auto_response(message,snr,rssi,hop): bot_response = MOTD elif "help" in message.lower(): bot_response = help_message + elif "lheard" in message.lower(): + bot_response = "Last 5 nodes heard: " + str(get_node_list()) else: bot_response = "I'm sorry, I'm afraid I can't do that." @@ -97,27 +99,38 @@ def onReceive(packet, interface): hop_start = packet['hopStart'] else: hop_start = 0 + + # check if the packet has a hop count flag use it + if packet.get('hopsAway'): + hop_away = packet['hopsAway'] + else: + hop_away = 0 # set hop to Direct if the message was sent directly otherwise set the hop count if hop_start == hop_limit: hop = "Direct" else: - hop_count = hop_start - hop_limit + if hop_away > 0: + hop_count = hop_away + print (f"Using hopsAway: {hop_count}") + else: + hop_count = hop_start - hop_limit + print (f"calculated hop count: {hop_start} - {hop_limit} = {hop_count}") hop = f"{hop_count} hops" # If the packet is a DM (Direct Message) respond to it, otherwise validate its a message for us if packet['to'] == myNodeNum: if messageTrap(message_string): - print(f"{log_timestamp()} Received DM: {message_string} on Channel: {channel_number} From: {message_from_id}") + print(f"{log_timestamp()} Received DM: {message_string} on Channel: {channel_number} From: {get_name_from_number(message_from_id)}") # respond with a direct message send_message(auto_response(message_string,snr,rssi,hop),channel_number,message_from_id) else: #respond with welcome message - print(f"{log_timestamp()} Ignoring DM: {message_string} From: {message_from_id}") + print(f"{log_timestamp()} Ignoring DM: {message_string} From: {get_name_from_number(message_from_id)}") send_message(welcome_message,channel_number,message_from_id) else: if messageTrap(message_string): - print(f"{log_timestamp()} Received On Channel {channel_number}: {message_string} From: {message_from_id}") + print(f"{log_timestamp()} Received On Channel {channel_number}: {message_string} From: {get_name_from_number(message_from_id)}") if RESPOND_BY_DM_ONLY: # respond to channel message via direct message to keep the channel clean send_message(auto_response(message_string,snr,rssi,hop),channel_number,message_from_id) @@ -125,7 +138,7 @@ def onReceive(packet, interface): # or respond to channel message on the channel itself send_message(auto_response(message_string,snr,rssi),channel_number,0) else: - print(f"{log_timestamp()} System: Ignoring incoming channel {channel_number}: {message_string} From: {message_from_id}") + print(f"{log_timestamp()} System: Ignoring incoming channel {channel_number}: {message_string} From: {get_name_from_number(message_from_id)}") except KeyError as e: print(f"System: Error processing packet: {e}") @@ -138,6 +151,50 @@ def messageTrap(msg): if t.lower() == m.lower(): return True return False + +def decimal_to_hex(decimal_number): + return f"!{decimal_number:08x}" + +def get_name_from_number(number, type='long'): + name = "" + for node in interface.nodes.values(): + if number == node['num']: + if type == 'long': + name = node['user']['longName'] + return name + elif type == 'short': + name = node['user']['shortName'] + return name + else: + pass + else: + name = str(decimal_to_hex(number)) # If long name not found, use the ID as string + return name + +def get_node_list(): + node_list = [] + if interface.nodes: + for node in interface.nodes.values(): + #ignore own + if node['num'] != myNodeNum: + node_name = get_name_from_number(node['num']) + + try: + last_heard = node['lastHeard'] + except Exception as e: + last_heard = 0 + + item = (node_name,last_heard) + node_list.append(item) + + node_list.sort(key=lambda x: x[1], reverse=True) + #print (f"Node List: {node_list[:5]}\n") + #return only the last 5 nodes + nice_node_list = [x[0] for x in node_list[:5]] + return nice_node_list + else: + node_list.append("Nothing heard") + return node_list def send_message(message,ch,nodeid): if nodeid == 0: @@ -146,7 +203,7 @@ def send_message(message,ch,nodeid): print (f"{log_timestamp()} System: Sending: {message} on Channel: {ch}") else: #Send to DM - print (f"{log_timestamp()} System: Sending: {message} To: {nodeid}") + print (f"{log_timestamp()} System: Sending: {message} To: {get_name_from_number(nodeid)}") interface.sendText(text=message,channelIndex=ch,destinationId=nodeid) def exit_handler(signum, frame): @@ -156,7 +213,7 @@ def exit_handler(signum, frame): print ("\nMeshtastic Autoresponder PONG Bot CTL+C to exit\n") pub.subscribe(onReceive, 'meshtastic.receive') -print (f"System: Autoresponder Started for device {myNodeNum}") +print (f"System: Autoresponder Started for device {get_name_from_number(myNodeNum)}") while True: signal.signal(signal.SIGINT, exit_handler) From 3d553cce75c22479ef494372ae42077df08b4d06 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:49:34 -0700 Subject: [PATCH 46/48] Update solarconditions.py --- solarconditions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/solarconditions.py b/solarconditions.py index 4d520a1..c106d8d 100644 --- a/solarconditions.py +++ b/solarconditions.py @@ -7,6 +7,7 @@ import xml.dom.minidom from datetime import timedelta from dateutil import tz # pip install python-dateutil from suntime import Sun, SunTimeException # pip install suntime +import datetime # pip install datetime LATITUDE = 48.50 LONGITUDE = -123.0 From 1331bc1f138d347f4d7ffe3a31a78cdbc4828d65 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:50:58 -0700 Subject: [PATCH 47/48] Update solarconditions.py --- solarconditions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solarconditions.py b/solarconditions.py index c106d8d..64fc713 100644 --- a/solarconditions.py +++ b/solarconditions.py @@ -7,7 +7,7 @@ import xml.dom.minidom from datetime import timedelta from dateutil import tz # pip install python-dateutil from suntime import Sun, SunTimeException # pip install suntime -import datetime # pip install datetime +from datetime import datetime LATITUDE = 48.50 LONGITUDE = -123.0 From 02d5fb6743ffe900c4fa449815164a9653ae3abc Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 19 Jun 2024 00:53:34 -0700 Subject: [PATCH 48/48] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e3caf6b..5049bd8 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Little bot which will trap keywords like ping and respond on a DM with pong. The other features - MOTD with ability to set remotely - `motd` or `motd $New Message Of the day` + - `lheard` returns the last 5 heard nodes ## mesh-bot.sh