Merge pull request #61 from Nestpebble/main

Nestpebble enhancements
This commit is contained in:
Kelly
2024-09-20 20:26:24 -07:00
committed by GitHub
5 changed files with 59 additions and 22 deletions
+6 -1
View File
@@ -113,4 +113,9 @@ signalDetectionThreshold = -10
signalHoldTime = 10
# the following are combined to reset the monitor
signalCooldown = 5
signalCycleLimit = 5
signalCycleLimit = 5
[messagingSettings]
responseDelay = 0.7 # delay in seconds for response to avoid message collision
splitDelay = 0.7 # delay in seconds for splits in messages to avoid message collision
MESSAGE_CHUNK_SIZE = 160 # message chunk size for sending at high success rate
+43 -15
View File
@@ -8,8 +8,6 @@ from pubsub import pub # pip install pubsub
from modules.log import *
from modules.system import *
responseDelay = 0.7 # delay in seconds for response to avoid message collision
def auto_response(message, snr, rssi, hop, message_from_id, channel_number, deviceID):
#Auto response to messages
message_lower = message.lower()
@@ -18,7 +16,7 @@ def auto_response(message, snr, rssi, hop, message_from_id, channel_number, devi
command_handler = {
"ping": lambda: handle_ping(message, hop, snr, rssi),
"pong": lambda: "🏓PING!!",
"motd": lambda: handle_motd(message),
"motd": lambda: handle_motd(message, message_from_id),
"bbshelp": bbs_help,
"wxalert": lambda: handle_wxalert(message_from_id, deviceID, message),
"wxa": lambda: handle_wxalert(message_from_id, deviceID, message),
@@ -50,8 +48,9 @@ def auto_response(message, snr, rssi, hop, message_from_id, channel_number, devi
"tide": lambda: handle_tide(message_from_id, deviceID, channel_number),
"moon": lambda: handle_moon(message_from_id, deviceID, channel_number),
"ack": lambda: handle_ack(hop, snr, rssi),
"testing": lambda: handle_testing(hop, snr, rssi),
"test": lambda: handle_testing(hop, snr, rssi),
"testing": lambda: handle_testing(message, hop, snr, rssi),
"test": lambda: handle_testing(message, hop, snr, rssi),
"whoami": lambda: handle_whoami(message_from_id, deviceID),
}
cmds = [] # list to hold the commands found in the message
for key in command_handler:
@@ -73,21 +72,36 @@ def auto_response(message, snr, rssi, hop, message_from_id, channel_number, devi
def handle_ping(message, hop, snr, rssi):
if "@" in message:
if hop == "Direct":
return "🏓PONG, " + f"SNR:{snr} RSSI:{rssi}" + " and copy: " + message.split("@")[1]
return "🏓PONG, " + f"SNR:{snr} RSSI:{rssi}" + " at: " + message.split("@")[1]
else:
return "🏓PONG, " + hop + " and copy: " + message.split("@")[1]
return "🏓PONG, " + hop + " at: " + message.split("@")[1]
elif "#" in message:
if hop == "Direct":
return "🏓PONG, " + f"SNR:{snr} RSSI:{rssi}" + " #" + message.split("#")[1]
else:
return "🏓PONG, " + hop + " #" + message.split("#")[1]
else:
if hop == "Direct":
return "🏓PONG, " + f"SNR:{snr} RSSI:{rssi}"
else:
return "🏓PONG, " + hop
def handle_motd(message):
def handle_motd(message, message_from_id):
global MOTD
if "$" in message:
if "?" in message and not "$": #basic help message - borked
return "Message of the day, set with 'motd $ motd'"
elif "$" in message and str(message_from_id) in str(bbs_admin_list): #access control via bbs admin list - works
motd = message.split("$")[1]
MOTD = motd.rstrip()
logger.debug(f"System: node changed MOTD: ", {message_from_id})
return "MOTD Set to: " + MOTD
elif "$" in message and not str(bbs_admin_list).strip(): #no names in bbs admin list - borked
motd = message.split("$")[1]
MOTD = motd.rstrip()
return "MOTD Set to: " + MOTD
elif "$" in message and str(bbs_admin_list).strip(''):
logger.debug(f"System: node tried to change MOTD: ", str({message_from_id}))
return "I can't do that for you "
else:
return MOTD
@@ -446,15 +460,29 @@ def handle_moon(message_from_id, deviceID, channel_number):
def handle_ack(hop, snr, rssi):
if hop == "Direct":
return "🏓ACK-ACK! " + f"SNR:{snr} RSSI:{rssi}"
return "ACK-ACK! " + f"SNR:{snr} RSSI:{rssi}"
else:
return "🏓ACK-ACK! " + hop
return "ACK-ACK! " + hop
def handle_testing(hop, snr, rssi):
if hop == "Direct":
return "🏓Testing 1,2,3 " + f"SNR:{snr} RSSI:{rssi}"
def handle_testing(message, hop, snr, rssi):
if "@" in message:
if hop == "Direct":
return "🎙Testing, " + f"SNR:{snr} RSSI:{rssi}" + " at: " + message.split("@")[1]
else:
return "🎙Testing, " + hop + " at: " + message.split("@")[1]
elif "#" in message:
if hop == "Direct":
return "🎙Testing " + f"SNR:{snr} RSSI:{rssi}" + " #" + message.split("#")[1]
else:
return "🎙Testing " + hop + " #" + message.split("#")[1]
else:
return "🏓Testing 1,2,3 " + hop
if hop == "Direct":
return "🎙Testing 1,2,3 " + f"SNR:{snr} RSSI:{rssi}"
else:
return "🎙Testing 1,2,3 " + hop
def handle_whoami(message_from_id, deviceID):
return "You are " + str(message_from_id) + " AKA " + str(get_name_from_number(message_from_id, 'long', deviceID))
def onDisconnect(interface):
global retry_int1, retry_int2
+4 -1
View File
@@ -10,7 +10,6 @@ MOTD = 'Thanks for using MeshBOT! Have a good day!'
NO_ALERTS = "No weather alerts found."
# setup the global variables
MESSAGE_CHUNK_SIZE = 160 # message chunk size for sending at high success rate
SITREP_NODE_COUNT = 3 # number of nodes to report in the sitrep
msg_history = [] # message history for the store and forward feature
bbs_ban_list = [] # list of banned users, imported from config
@@ -145,6 +144,10 @@ try:
blackjack_enabled = config['games'].getboolean('blackjack', True)
videoPoker_enabled = config['games'].getboolean('videoPoker', True)
responseDelay = config['messagingSettings'].getfloat('responseDelay', 0.7) # default 0.7
splitDelay = config['messagingSettings'].getfloat('splitDelay', 0) # default 0
MESSAGE_CHUNK_SIZE = config['messagingSettings'].getint('MESSAGE_CHUNK_SIZE', 160) # default 160
except KeyError as e:
print(f"System: Error reading config file: {e}")
print(f"System: Check the config.ini against config.template file for missing sections or values.")
+2 -1
View File
@@ -10,7 +10,7 @@ import contextlib # for suppressing output on watchdog
from modules.log import *
# Global Variables
trap_list = ("cmd","cmd?") # default trap list
trap_list = ("cmd","cmd?","whoami") # default trap list
help_message = "CMD?:"
asyncLoop = asyncio.new_event_loop()
games_enabled = False
@@ -516,6 +516,7 @@ def send_message(message, ch, nodeid=0, nodeInt=1):
interface1.sendText(text=m, channelIndex=ch, destinationId=nodeid)
if nodeInt == 2:
interface2.sendText(text=m, channelIndex=ch, destinationId=nodeid)
time.sleep(splitDelay) # wait an amout of time between sending each split message
else: # message is less than MESSAGE_CHUNK_SIZE characters
if nodeid == 0:
# Send to channel
+4 -4
View File
@@ -77,15 +77,15 @@ def handle_lheard(interface1, interface2_enabled, myNodeNum1, myNodeNum2):
def handle_ack(hop, snr, rssi):
if hop == "Direct":
return "🏓ACK-ACK! " + f"SNR:{snr} RSSI:{rssi}"
return "ACK-ACK! " + f"SNR:{snr} RSSI:{rssi}"
else:
return "🏓ACK-ACK! " + hop
return "ACK-ACK! " + hop
def handle_testing(hop, snr, rssi):
if hop == "Direct":
return "🏓Testing 1,2,3 " + f"SNR:{snr} RSSI:{rssi}"
return "🎙Testing 1,2,3 " + f"SNR:{snr} RSSI:{rssi}"
else:
return "🏓Testing 1,2,3 " + hop
return "🎙Testing 1,2,3 " + hop
def onDisconnect(interface):
global retry_int1, retry_int2