From 9d7e42aa604933dfffc0aabcfd014bf37a5078c1 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 27 Aug 2024 13:08:59 -0700 Subject: [PATCH] onDisconnect add monitor for ondisconnect --- mesh_bot.py | 20 ++++++++++++++++++++ pong_bot.py | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/mesh_bot.py b/mesh_bot.py index aaa5f30..dfedffd 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -201,6 +201,25 @@ def handle_testing(hop, snr, rssi): else: return "🏓Testing 1,2,3 " + hop +def onDisconnect(interface): + global retry_int1, retry_int2 + rxType = type(interface).__name__ + if rxType == 'SerialInterface': + rxInterface = interface.__dict__.get('devPath', 'unknown') + logger.critical(f"System: Lost Connection to Device {rxInterface}") + if port1 in rxInterface: + retry_int1 = True + elif interface2_enabled and port2 in rxInterface: + retry_int2 = True + + if rxType == 'TCPInterface': + rxHost = interface.__dict__.get('hostname', 'unknown') + logger.critical(f"System: Lost Connection to Device {rxHost}") + if hostname1 in rxHost and interface1_type == 'tcp': + retry_int1 = True + elif interface2_enabled and hostname2 in rxHost and interface2_type == 'tcp': + retry_int2 = True + def onReceive(packet, interface): # extract interface defailts from interface object rxType = type(interface).__name__ @@ -369,6 +388,7 @@ async def start_rx(): print (CustomFormatter.bold_white + f"\nMeshtastic Autoresponder Bot CTL+C to exit\n" + CustomFormatter.reset) # Start the receive subscriber using pubsub via meshtastic library pub.subscribe(onReceive, 'meshtastic.receive') + pub.subscribe(onDisconnect, 'meshtastic.connection.lost') logger.info(f"System: Autoresponder Started for Device1 {get_name_from_number(myNodeNum1, 'long', 1)}," f"{get_name_from_number(myNodeNum1, 'short', 1)}. NodeID: {myNodeNum1}, {decimal_to_hex(myNodeNum1)}") if interface2_enabled: diff --git a/pong_bot.py b/pong_bot.py index a47f02b..7ed0298 100755 --- a/pong_bot.py +++ b/pong_bot.py @@ -85,6 +85,25 @@ def handle_testing(hop, snr, rssi): else: return "🏓Testing 1,2,3 " + hop +def onDisconnect(interface): + global retry_int1, retry_int2 + rxType = type(interface).__name__ + if rxType == 'SerialInterface': + rxInterface = interface.__dict__.get('devPath', 'unknown') + logger.critical(f"System: Lost Connection to Device {rxInterface}") + if port1 in rxInterface: + retry_int1 = True + elif interface2_enabled and port2 in rxInterface: + retry_int2 = True + + if rxType == 'TCPInterface': + rxHost = interface.__dict__.get('hostname', 'unknown') + logger.critical(f"System: Lost Connection to Device {rxHost}") + if hostname1 in rxHost and interface1_type == 'tcp': + retry_int1 = True + elif interface2_enabled and hostname2 in rxHost and interface2_type == 'tcp': + retry_int2 = True + def onReceive(packet, interface): # extract interface defailts from interface object rxType = type(interface).__name__ @@ -238,6 +257,7 @@ async def start_rx(): print (CustomFormatter.bold_white + f"\nMeshtastic Autoresponder Bot CTL+C to exit\n" + CustomFormatter.reset) # Start the receive subscriber using pubsub via meshtastic library pub.subscribe(onReceive, 'meshtastic.receive') + pub.subscribe(onDisconnect, 'meshtastic.connection.lost') logger.info(f"System: Autoresponder Started for Device1 {get_name_from_number(myNodeNum1, 'long', 1)}," f"{get_name_from_number(myNodeNum1, 'short', 1)}. NodeID: {myNodeNum1}, {decimal_to_hex(myNodeNum1)}") if interface2_enabled: