diff --git a/db_handler.py b/db_handler.py index ef0255c..5427772 100644 --- a/db_handler.py +++ b/db_handler.py @@ -5,7 +5,7 @@ from utilities.utils import get_nodeNum, get_name_from_number def get_table_name(channel): # Construct the table name - table_name = f"{str(get_nodeNum())}_{channel}_messages" + table_name = f"{str(globals.myNodeNum)}_{channel}_messages" quoted_table_name = f'"{table_name}"' # Quote the table name becuase we begin with numerics and contain spaces return quoted_table_name @@ -54,7 +54,7 @@ def update_ack_nak(channel, timestamp, message, ack): update_query = f""" UPDATE {get_table_name(channel)} SET ack_type = '{ack}' - WHERE user_id = {str(get_nodeNum())} AND + WHERE user_id = {str(globals.myNodeNum)} AND timestamp = {timestamp} AND message_text = '{message}' """ @@ -76,7 +76,7 @@ def load_messages_from_db(): # Retrieve all table names that match the pattern query = "SELECT name FROM sqlite_master WHERE type='table' AND name LIKE ?" - db_cursor.execute(query, (f"{str(get_nodeNum())}_%_messages",)) + db_cursor.execute(query, (f"{str(globals.myNodeNum)}_%_messages",)) tables = [row[0] for row in db_cursor.fetchall()] # Iterate through each table and fetch its messages @@ -110,7 +110,7 @@ def load_messages_from_db(): # Add messages to globals.all_messages in tuple format for user_id, message, ack_type in db_messages: - if user_id == str(get_nodeNum()): + if user_id == str(globals.myNodeNum): ack_str = globals.ack_unknown_str if(ack_type == "Implicit"): ack_str = globals.ack_implicit_str @@ -140,7 +140,7 @@ def init_nodedb(): db_cursor = db_connection.cursor() # Table name construction - table_name = f"{str(get_nodeNum())}_nodedb" + table_name = f"{str(globals.myNodeNum)}_nodedb" nodeinfo_table = f'"{table_name}"' # Quote the table name because it might begin with numerics # Create the table if it doesn't exist @@ -191,7 +191,7 @@ def maybe_store_nodeinfo_in_db(packet): try: with sqlite3.connect(globals.db_file_path) as db_connection: - table_name = f"{str(get_nodeNum())}_nodedb" + table_name = f"{str(globals.myNodeNum)}_nodedb" nodeinfo_table = f'"{table_name}"' # Quote the table name becuase we might begin with numerics db_cursor = db_connection.cursor() diff --git a/main.py b/main.py index da36c87..b48e12b 100644 --- a/main.py +++ b/main.py @@ -16,7 +16,7 @@ from utilities.arg_parser import setup_parser from utilities.interfaces import initialize_interface from message_handlers.rx_handler import on_receive from ui.curses_ui import main_ui, draw_splash -from utilities.utils import get_channels, get_node_list +from utilities.utils import get_channels, get_node_list, get_nodeNum from db_handler import init_nodedb, load_messages_from_db import globals @@ -39,9 +39,10 @@ def main(stdscr): parser = setup_parser() args = parser.parse_args() globals.interface = initialize_interface(args) + globals.myNodeNum = get_nodeNum() globals.channel_list = get_channels() - pub.subscribe(on_receive, 'meshtastic.receive') globals.node_list = get_node_list() + pub.subscribe(on_receive, 'meshtastic.receive') init_nodedb() load_messages_from_db() main_ui(stdscr) diff --git a/message_handlers/rx_handler.py b/message_handlers/rx_handler.py index dab6ca3..1104496 100644 --- a/message_handlers/rx_handler.py +++ b/message_handlers/rx_handler.py @@ -36,8 +36,7 @@ def on_receive(packet, interface): channel_number = packet['channel'] else: channel_number = 0 - myNodeNum = get_nodeNum() - if packet['to'] == myNodeNum: + if packet['to'] == globals.myNodeNum: if packet['from'] in globals.channel_list: pass else: diff --git a/message_handlers/tx_handler.py b/message_handlers/tx_handler.py index 58bca4d..0a50903 100644 --- a/message_handlers/tx_handler.py +++ b/message_handlers/tx_handler.py @@ -19,7 +19,7 @@ def onAckNak(packet): confirm_string = " " ack_type = None if(packet['decoded']['routing']['errorReason'] == "NONE"): - if(packet['from'] == get_nodeNum()): # Ack "from" ourself means implicit ACK + if(packet['from'] == globals.myNodeNum): # Ack "from" ourself means implicit ACK confirm_string = globals.ack_implicit_str ack_type = "Implicit" else: @@ -37,7 +37,7 @@ def onAckNak(packet): def send_message(message, destination=BROADCAST_NUM, channel=0): - myid = get_nodeNum() + myid = globals.myNodeNum send_on_channel = 0 channel_id = globals.channel_list[channel] if isinstance(channel_id, int):