diff --git a/mesh_bot.py b/mesh_bot.py index 2e2455f..6e0d9f3 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -2,7 +2,7 @@ # Meshtastic Autoresponder MESH Bot # K7MHI Kelly Keeton 2024 -import asyncio # for the event loop +import asyncio import time # for sleep, get some when you can :) from pubsub import pub # pip install pubsub from modules.settings import * @@ -337,39 +337,6 @@ async def start_rx(): await asyncio.sleep(0.5) pass -async def watchdog(): - # watchdog for connection to the interface - while True: - await asyncio.sleep(5) - try: - interface1.getMyNodeInfo() - except Exception as e: - print(f"{log_timestamp()} System: Watchdog Device1 Error: {e}") - #exit_handler() - if interface2_enabled: - try: - interface2.getMyNodeInfo() - except Exception as e: - print(f"{log_timestamp()} System: Watchdog Device2 Error: {e}") - #exit_handler() - -def exit_handler(): - # Close the interface and save the BBS messages - print(f"\n{log_timestamp()} System: Closing Autoresponder\n") - #rxLoop.cancel() - interface1.close() - print(f"{log_timestamp()} System: Interface1 Closed") - if interface2_enabled: - interface2.close() - print(f"{log_timestamp()} System: Interface2 Closed") - if bbs_enabled: - save_bbsdb() - print(f"{log_timestamp()} System: BBS Messages Saved") - print(f"{log_timestamp()} System: Exiting") - asyncLoop.stop() - asyncLoop.close() - exit (0) - # Hello World async def main(): meshRxTask = asyncio.create_task(start_rx()) @@ -377,7 +344,6 @@ async def main(): await asyncio.wait([meshRxTask, watchdogTask]) try: - asyncLoop = asyncio.new_event_loop() if __name__ == "__main__": asyncio.run(main()) except KeyboardInterrupt: diff --git a/modules/system.py b/modules/system.py index 5fdce53..454421f 100644 --- a/modules/system.py +++ b/modules/system.py @@ -5,11 +5,13 @@ import meshtastic.serial_interface #pip install meshtastic import meshtastic.tcp_interface import meshtastic.ble_interface from datetime import datetime +import asyncio from modules.settings import * # Global Variables trap_list = ("cmd",) # default trap list help_message = "CMD?:" +asyncLoop = asyncio.new_event_loop() # Ping Configuration if ping_enabled: @@ -298,6 +300,7 @@ def messageTrap(msg): if t.lower() == m.lower(): return True return False + def messageTrap(msg): # Check if the message contains a trap word message_list=msg.split(" ") @@ -305,4 +308,42 @@ def messageTrap(msg): for t in trap_list: if t.lower() == m.lower(): return True - return False \ No newline at end of file + return False + +def exit_handler(): + # Close the interface and save the BBS messages + print(f"\n{log_timestamp()} System: Closing Autoresponder\n") + #rxLoop.cancel() + interface1.close() + print(f"{log_timestamp()} System: Interface1 Closed") + if interface2_enabled: + interface2.close() + print(f"{log_timestamp()} System: Interface2 Closed") + if bbs_enabled: + save_bbsdb() + print(f"{log_timestamp()} System: BBS Messages Saved") + print(f"{log_timestamp()} System: Exiting") + asyncLoop.stop() + asyncLoop.close() + exit (0) + +async def watchdog(): + # watchdog for connection to the interface + while True: + await asyncio.sleep(5) + #print(f"{log_timestamp()} System: watchdog running\r", end="") + + try: + myinfo = interface1.getMyNodeInfo() + myNodeNum = myinfo['num'] + print(f"{log_timestamp()} System: Got Device1 {get_name_from_number(myNodeNum, 'long', 1)},") + except Exception as e: + print(f"{log_timestamp()} System: Error getting myNodeNum from interface1: {e}") + + if interface2_enabled: + try: + myinfo = interface2.getMyNodeInfo() + myNodeNum2 = myinfo['num'] + print(f"{log_timestamp()} System: Got Device2 {get_name_from_number(myNodeNum2, 'long', 2)},") + except Exception as e: + print(f"{log_timestamp()} System: Error getting myNodeNum from interface2: {e}") diff --git a/pong_bot.py b/pong_bot.py index 842db03..b307351 100755 --- a/pong_bot.py +++ b/pong_bot.py @@ -2,7 +2,7 @@ # Meshtastic Autoresponder PONG Bot # K7MHI Kelly Keeton 2024 -import asyncio # for the event loop +import asyncio import time # for sleep, get some when you can :) from pubsub import pub # pip install pubsub from modules.settings import * @@ -212,39 +212,6 @@ async def start_rx(): await asyncio.sleep(0.5) pass -async def watchdog(): - # watchdog for connection to the interface - while True: - await asyncio.sleep(5) - try: - interface1.getMyNodeInfo() - except Exception as e: - print(f"{log_timestamp()} System: Watchdog Device1 Error: {e}") - #exit_handler() - if interface2_enabled: - try: - interface2.getMyNodeInfo() - except Exception as e: - print(f"{log_timestamp()} System: Watchdog Device2 Error: {e}") - #exit_handler() - -def exit_handler(): - # Close the interface and save the BBS messages - print(f"\n{log_timestamp()} System: Closing Autoresponder\n") - #rxLoop.cancel() - interface1.close() - print(f"{log_timestamp()} System: Interface1 Closed") - if interface2_enabled: - interface2.close() - print(f"{log_timestamp()} System: Interface2 Closed") - if bbs_enabled: - save_bbsdb() - print(f"{log_timestamp()} System: BBS Messages Saved") - print(f"{log_timestamp()} System: Exiting") - asyncLoop.stop() - asyncLoop.close() - exit (0) - # Hello World async def main(): meshRxTask = asyncio.create_task(start_rx())