Skip to content

Commit

Permalink
Add handler for new log-record BLE characteristic
Browse files Browse the repository at this point in the history
  • Loading branch information
thebentern committed Jul 1, 2024
1 parent 98b7a7d commit 188f9d5
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion meshtastic/ble_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from threading import Thread
from typing import List, Optional

from .protobuf import (
mesh_pb2,
)

import print_color # type: ignore[import-untyped]
from bleak import BleakClient, BleakScanner, BLEDevice
from bleak.exc import BleakDBusError, BleakError
Expand All @@ -18,7 +22,8 @@
TORADIO_UUID = "f75c76d2-129e-4dad-a1dd-7866124401e7"
FROMRADIO_UUID = "2c55e69e-4993-11ed-b878-0242ac120002"
FROMNUM_UUID = "ed9da18c-a800-4f66-a670-aa7547e34453"
LOGRADIO_UUID = "6c6fd238-78fa-436b-aacf-15c5be1ef2e2"
LEGACY_LOGRADIO_UUID = "6c6fd238-78fa-436b-aacf-15c5be1ef2e2"
LOGRADIO_UUID = "5a3d6e49-06e6-4423-9944-e9de8cdf9547"


class BLEInterface(MeshInterface):
Expand Down Expand Up @@ -56,6 +61,7 @@ def __init__(
self.close()
raise e

#self.client.start_notify(LEGACY_LOGRADIO_UUID, self.legacy_log_radio_handler)
self.client.start_notify(LOGRADIO_UUID, self.log_radio_handler)

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

async def log_radio_handler(self, _, b): # pylint: disable=C0116
if b is not mesh_pb2.LogRecord:
return

log_record = b
if log_record.DEBUG:
print_color.print(log_record.message, color="cyan", end=None)
elif log_record.INFO:
print_color.print(log_record.message, color="white", end=None)
elif log_record.WARNING:
print_color.print(log_record.message, color="yellow", end=None)
elif log_record.ERROR:
print_color.print(log_record.message, color="red", end=None)
else:
print_color.print(log_record.message, end=None)

async def legacy_log_radio_handler(self, _, b): # pylint: disable=C0116
log_radio = b.decode("utf-8").replace("\n", "")
if log_radio.startswith("DEBUG"):
print_color.print(log_radio, color="cyan", end=None)
Expand Down

0 comments on commit 188f9d5

Please sign in to comment.