From 08115e975c3bae4a8a82c9ba9625d7faf3d3c7a0 Mon Sep 17 00:00:00 2001 From: Geoff Whittington Date: Fri, 12 May 2023 10:47:23 -0400 Subject: [PATCH] Move logging after plugins because sometimes the room doesn't get notified. Add method for lost connection, used in a future commit --- meshtastic_utils.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/meshtastic_utils.py b/meshtastic_utils.py index 9a32043..5ff0b7d 100644 --- a/meshtastic_utils.py +++ b/meshtastic_utils.py @@ -33,6 +33,11 @@ def connect_meshtastic(): return meshtastic_client +def on_lost_meshtastic_connection(interface): + logger.error("Lost connection. Reconnecting...") + connect_meshtastic() + + # Callback for new messages from Meshtastic def on_meshtastic_message(packet, loop=None): from matrix_utils import matrix_relay @@ -70,9 +75,6 @@ def on_meshtastic_message(packet, loop=None): meshnet_name = relay_config["meshtastic"]["meshnet_name"] formatted_message = f"[{longname}/{meshnet_name}]: {text}" - logger.info( - f"Relaying Meshtastic message from {longname} to Matrix: {formatted_message}" - ) # Plugin functionality plugins = load_plugins() @@ -93,6 +95,10 @@ def on_meshtastic_message(packet, loop=None): if found_matching_plugin: return + logger.info( + f"Relaying Meshtastic message from {longname} to Matrix: {formatted_message}" + ) + for room in matrix_rooms: if room["meshtastic_channel"] == channel: asyncio.run_coroutine_threadsafe(