This commit is contained in:
SpudGunMan
2024-07-31 13:16:46 -07:00
parent 5eb753e1e1
commit 833da28480
3 changed files with 44 additions and 70 deletions
+1 -35
View File
@@ -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:
+42 -1
View File
@@ -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
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}")
+1 -34
View File
@@ -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())