Skip to content

Commit 188f9d5

Browse files
committed
Add handler for new log-record BLE characteristic
1 parent 98b7a7d commit 188f9d5

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

meshtastic/ble_interface.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
from threading import Thread
99
from typing import List, Optional
1010

11+
from .protobuf import (
12+
mesh_pb2,
13+
)
14+
1115
import print_color # type: ignore[import-untyped]
1216
from bleak import BleakClient, BleakScanner, BLEDevice
1317
from bleak.exc import BleakDBusError, BleakError
@@ -18,7 +22,8 @@
1822
TORADIO_UUID = "f75c76d2-129e-4dad-a1dd-7866124401e7"
1923
FROMRADIO_UUID = "2c55e69e-4993-11ed-b878-0242ac120002"
2024
FROMNUM_UUID = "ed9da18c-a800-4f66-a670-aa7547e34453"
21-
LOGRADIO_UUID = "6c6fd238-78fa-436b-aacf-15c5be1ef2e2"
25+
LEGACY_LOGRADIO_UUID = "6c6fd238-78fa-436b-aacf-15c5be1ef2e2"
26+
LOGRADIO_UUID = "5a3d6e49-06e6-4423-9944-e9de8cdf9547"
2227

2328

2429
class BLEInterface(MeshInterface):
@@ -56,6 +61,7 @@ def __init__(
5661
self.close()
5762
raise e
5863

64+
#self.client.start_notify(LEGACY_LOGRADIO_UUID, self.legacy_log_radio_handler)
5965
self.client.start_notify(LOGRADIO_UUID, self.log_radio_handler)
6066

6167
logging.debug("Mesh configure starting")
@@ -81,6 +87,22 @@ def from_num_handler(self, _, b): # pylint: disable=C0116
8187
self.should_read = True
8288

8389
async def log_radio_handler(self, _, b): # pylint: disable=C0116
90+
if b is not mesh_pb2.LogRecord:
91+
return
92+
93+
log_record = b
94+
if log_record.DEBUG:
95+
print_color.print(log_record.message, color="cyan", end=None)
96+
elif log_record.INFO:
97+
print_color.print(log_record.message, color="white", end=None)
98+
elif log_record.WARNING:
99+
print_color.print(log_record.message, color="yellow", end=None)
100+
elif log_record.ERROR:
101+
print_color.print(log_record.message, color="red", end=None)
102+
else:
103+
print_color.print(log_record.message, end=None)
104+
105+
async def legacy_log_radio_handler(self, _, b): # pylint: disable=C0116
84106
log_radio = b.decode("utf-8").replace("\n", "")
85107
if log_radio.startswith("DEBUG"):
86108
print_color.print(log_radio, color="cyan", end=None)

0 commit comments

Comments
 (0)