From 473eccbdea475c9b6af839018cdbdb44f70976f2 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 27 Aug 2024 20:31:00 -0700 Subject: [PATCH] fix BLE --- README.md | 2 +- mesh_bot.py | 14 ++++++++++++++ pong_bot.py | 13 +++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c58e2a..321854a 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Optionally: - `launch.sh` will activate and launch the app in the venv if built. ### Configurations -Copy the [config.template](config.template) to `config.ini` and set the appropriate interface for your method (serial/ble/tcp). While BLE and TCP will work, they are not as reliable as serial connections. There is a watchdog to reconnect tcp if possible. To get BLE mac `meshtastic --ble-scan` +Copy the [config.template](config.template) to `config.ini` and set the appropriate interface for your method (serial/ble/tcp). While BLE and TCP will work, they are not as reliable as serial connections. There is a watchdog to reconnect tcp if possible. To get BLE mac `meshtastic --ble-scan` **NOTE** I have only tested with a single BLE device and the code is written to only have one interface be a BLE port ``` #config.ini diff --git a/mesh_bot.py b/mesh_bot.py index f3d083a..b837da1 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -219,11 +219,19 @@ def onDisconnect(interface): retry_int1 = True elif interface2_enabled and hostname2 in rxHost and interface2_type == 'tcp': retry_int2 = True + + if rxType == 'BLEInterface': + logger.critical(f"System: Lost Connection to Device BLE") + if interface1_type == 'ble': + retry_int1 = True + elif interface2_enabled and interface2_type == 'ble': + retry_int2 = True def onReceive(packet, interface): # extract interface defailts from interface object rxType = type(interface).__name__ rxNode = 0 + #logger.debug(f"System: Packet Received on {rxType}") # Debug print the interface object #for item in interface.__dict__.items(): print (item) @@ -241,6 +249,12 @@ def onReceive(packet, interface): elif interface2_enabled and hostname2 in rxHost and interface2_type == 'tcp': rxNode = 2 + if rxType == 'BLEInterface': + if interface1_type == 'ble': + rxNode = 1 + elif interface2_enabled and interface2_type == 'ble': + rxNode = 2 + # Debug print the packet for debugging #print(f"Packet Received\n {packet} \n END of packet \n") message_from_id = 0 diff --git a/pong_bot.py b/pong_bot.py index 9f56d10..2e72429 100755 --- a/pong_bot.py +++ b/pong_bot.py @@ -104,6 +104,13 @@ def onDisconnect(interface): elif interface2_enabled and hostname2 in rxHost and interface2_type == 'tcp': retry_int2 = True + if rxType == 'BLEInterface': + logger.critical(f"System: Lost Connection to Device BLE") + if interface1_type == 'ble': + retry_int1 = True + elif interface2_enabled and interface2_type == 'ble': + retry_int2 = True + def onReceive(packet, interface): # extract interface defailts from interface object rxType = type(interface).__name__ @@ -125,6 +132,12 @@ def onReceive(packet, interface): elif interface2_enabled and hostname2 in rxHost and interface2_type == 'tcp': rxNode = 2 + if rxType == 'BLEInterface': + if interface1_type == 'ble': + rxNode = 1 + elif interface2_enabled and interface2_type == 'ble': + rxNode = 2 + # Debug print the packet for debugging #print(f"Packet Received\n {packet} \n END of packet \n") message_from_id = 0