From f8ce9e3089bb85514bf1a6e23a39f85155fba50e Mon Sep 17 00:00:00 2001 From: Shin'ichiro Kawasaki Date: Sun, 20 Jun 2021 21:24:17 +0900 Subject: [PATCH] BLESession: Enrich logs for notification handling To debug the GitHub issue #26, add more debug and error logs to functions to handle notifications. Signed-off-by: Shin'ichiro Kawasaki --- pyscrlink/scratch_link.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pyscrlink/scratch_link.py b/pyscrlink/scratch_link.py index 7d09c46..c5ad71e 100755 --- a/pyscrlink/scratch_link.py +++ b/pyscrlink/scratch_link.py @@ -389,7 +389,8 @@ def run(self): logger.debug("after waitForNotification") logger.debug("released lock for waitForNotification") except Exception as e: - logger.error(e) + logger.error(f"Exception in waitForNotifications: " + f"{type(e).__name__}: {e}") self.session.close() break else: @@ -413,7 +414,8 @@ def __init__(self, session): self.restart_notification_event.set() def add_handle(self, serviceId, charId, handle): - logger.debug(f"add handle for notification: {handle}") + logger.debug(f"add handle for notification: " + f"{serviceId} {charId} {handle}") params = { 'serviceId': UUID(serviceId).getCommonName(), 'characteristicId': charId, 'encoding': 'base64' } @@ -421,6 +423,9 @@ def add_handle(self, serviceId, charId, handle): def handleNotification(self, handle, data): logger.debug(f"BLE notification: {handle} {data}") + if handle not in self.handles: + logger.error(f"Notification with unknown {handle}") + return params = self.handles[handle].copy() params['message'] = base64.standard_b64encode(data).decode('ascii') self.session.notify('characteristicDidChange', params)