Skip to content

Commit 897adfb

Browse files
committed
Adds support for ble logging characteristic
1 parent f5febc5 commit 897adfb

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

meshtastic/ble_interface.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import asyncio
77
from threading import Thread, Event
88
from typing import Optional
9+
from print_color import print
910

1011
from bleak import BleakScanner, BleakClient
1112

@@ -16,6 +17,8 @@
1617
TORADIO_UUID = "f75c76d2-129e-4dad-a1dd-7866124401e7"
1718
FROMRADIO_UUID = "2c55e69e-4993-11ed-b878-0242ac120002"
1819
FROMNUM_UUID = "ed9da18c-a800-4f66-a670-aa7547e34453"
20+
LOGRADIO_UUID = "6c6fd238-78fa-436b-aacf-15c5be1ef2e2"
21+
1922

2023

2124
class BLEInterface(MeshInterface):
@@ -70,13 +73,28 @@ def __init__(self, address: Optional[str], noProto: bool = False, debugOut = Non
7073

7174
logging.debug("Register FROMNUM notify callback")
7275
self.client.start_notify(FROMNUM_UUID, self.from_num_handler)
76+
self.client.start_notify(LOGRADIO_UUID, self.log_radio_handler)
7377

7478

7579
async def from_num_handler(self, _, b): # pylint: disable=C0116
7680
from_num = struct.unpack('<I', bytes(b))[0]
7781
logging.debug(f"FROMNUM notify: {from_num}")
7882
self.should_read = True
7983

84+
async def log_radio_handler(self, _, b): # pylint: disable=C0116
85+
log_radio = b.decode('utf-8').replace('\n', '')
86+
if log_radio.startswith("DEBUG"):
87+
print(log_radio, color="cyan", end=None)
88+
elif log_radio.startswith("INFO"):
89+
print(log_radio, color="white", end=None)
90+
elif log_radio.startswith("WARN"):
91+
print(log_radio, color="yellow", end=None)
92+
elif log_radio.startswith("ERROR"):
93+
print(log_radio, color="red", end=None)
94+
else:
95+
print(log_radio, end=None)
96+
97+
self.should_read = False
8098

8199
def scan(self):
82100
"Scan for available BLE devices"

poetry.lock

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pyyaml = "^6.0.1"
2121
pypubsub = "^4.0.3"
2222
bleak = "^0.21.1"
2323
packaging = "^24.0"
24+
print-color = "^0.4.6"
2425

2526
[tool.poetry.group.dev.dependencies]
2627
hypothesis = "^6.103.2"

0 commit comments

Comments
 (0)