Untitled
unknown
python
a month ago
1.2 kB
3
Indexable
Never
import asyncio from bleak import BleakClient, BleakScanner from loguru import logger board_sn = board_config["board_sn"] sensor_list = board_config["sensor_list"] async def read_data(): async with BleakClient(board_sn) as client: services = client.services for service in services: for characteristic in service.characteristics: if characteristic.handle == 44: write_uuid = characteristic.uuid elif characteristic.handle == 41: read_uuid = characteristic.uuid global data data = [] for sensor in sensor_list: command = f"P{sensor['port']+1:02d}" await client.write_gatt_char(write_uuid, command.encode()) # Reads the data from the Controller response = await client.read_gatt_char(read_uuid) value = response.decode("utf-8").rstrip('\x00') if value: data.append(float(value)) logger.info(f"Response from {command}: {value}") else: logger.info(f"No value fetched for P{sensor['port']+1:02d}")
Leave a Comment