diff --git a/message_handlers/rx_handler.py b/message_handlers/rx_handler.py index 3ba0276..5d2d9e2 100644 --- a/message_handlers/rx_handler.py +++ b/message_handlers/rx_handler.py @@ -1,5 +1,7 @@ import logging import time +from datetime import datetime + from utilities.utils import refresh_node_list from datetime import datetime from ui.curses_ui import draw_packetlog_win, draw_node_list, draw_messages_window, draw_channel_list, add_notification @@ -8,8 +10,6 @@ import default_config as config import globals -from datetime import datetime - def on_receive(packet, interface): with globals.lock: diff --git a/message_handlers/tx_handler.py b/message_handlers/tx_handler.py index 4bc0552..c9b545d 100644 --- a/message_handlers/tx_handler.py +++ b/message_handlers/tx_handler.py @@ -1,7 +1,6 @@ from datetime import datetime import google.protobuf.json_format from meshtastic import BROADCAST_NUM - from meshtastic.protobuf import mesh_pb2, portnums_pb2 from db_handler import save_message_to_db, update_ack_nak, get_name_from_database, is_chat_archived, update_node_info_in_db diff --git a/utilities/config_io.py b/utilities/config_io.py index 3fd52a5..92c916f 100644 --- a/utilities/config_io.py +++ b/utilities/config_io.py @@ -1,4 +1,3 @@ - import yaml import logging from typing import List diff --git a/utilities/watchdog.py b/utilities/watchdog.py index 9018fc1..eab834c 100644 --- a/utilities/watchdog.py +++ b/utilities/watchdog.py @@ -3,7 +3,6 @@ import io import contextlib import socket import logging -import logging from .interfaces import initialize_interface import globals @@ -26,21 +25,27 @@ def getNodeFirmware(interface): return -1 except (socket.error, BrokenPipeError, ConnectionResetError, Exception) as e: - logging.info(f"Error retrieving firmware: {e}") + logging.warning(f"Error retrieving firmware: {e}") raise e # Propagate the error to handle reconnection # Async function to retry connection async def retry_interface(args): - logging.info("Retrying connection to the interface...") + logging.warning("Retrying connection to the interface...") await asyncio.sleep(retry_connection_seconds) # Wait before retrying try: globals.interface = initialize_interface(args) + if globals.interface and hasattr(globals.interface, 'localNode'): + logging.warning("Interface reinitialized successfully.") + return globals.interface + else: + logging.error("Failed to reinitialize interface: Missing localNode or invalid interface.") + globals.interface = None # Clear invalid interface + return None - logging.info("Interface reinitialized successfully.") - return globals.interface except (ConnectionRefusedError, socket.error, Exception) as e: logging.error(f"Failed to reinitialize interface: {e}") + globals.interface = None return None # Function to check connection and reconnect if needed @@ -60,6 +65,7 @@ async def check_and_reconnect(args): except (socket.error, BrokenPipeError, ConnectionResetError, Exception) as e: logging.error(f"Error with the interface, setting to None and attempting reconnect: {e}") + globals.interface = None return await retry_interface(args) # Main watchdog loop @@ -70,6 +76,4 @@ async def watchdog(args): if globals.interface: pass # Interface is connected else: - logging.error("Interface connection failed. Retrying...") - - + logging.error("Interface connection failed. Retrying...") \ No newline at end of file