From 673986caf266fa05edde237e148c7865b3415f2a Mon Sep 17 00:00:00 2001 From: susabolca Date: Sun, 28 Apr 2024 18:42:28 +0800 Subject: [PATCH] fix: show device info. --- tools/ble5_ctrl.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/tools/ble5_ctrl.py b/tools/ble5_ctrl.py index 3bec266..603a829 100644 --- a/tools/ble5_ctrl.py +++ b/tools/ble5_ctrl.py @@ -1,3 +1,5 @@ +import struct +from datetime import datetime import asyncio from bleak import BleakScanner @@ -9,23 +11,43 @@ async def main(): print(d, d.metadata) BleakScanner.discovered_devices_and_advertisement_data = True + async def scan(): stop_event = asyncio.Event() + def mv(v): + return (v>>8)*1000 + (v&0xff*125//32) + + def ShowDevice(device, advertising_data): + #print(device, advertising_data) + name = advertising_data.local_name + data = advertising_data.service_data['0000fff0-0000-1000-8000-00805f9b34fb'] + #print(data) + # 6 bytes of macaddress, + # follow by unt32 of unix timestamp, unt16 of battery, 1 char of temperature + macAddr = data[0:6] + # to string + mac = ":".join("{:02x}".format(x) for x in macAddr) + adv = struct.unpack_from("