Untitled

 avatar
unknown
python
a year ago
1.5 kB
4
Indexable
import asyncio
from bleak import BleakClient, BleakScanner

global sensor_list
global board_sn

async def scan_devices():
    print("Scanning for Bluetooth devices...")
    devices = await BleakScanner.discover()
    for device in devices:
        print(f"Found device: {device.name} - {device.address}")

async def uuid_info(board_sn):
    async with BleakClient(board_sn) as client:
        services = client.services
        uuids = []
        for service in services:
            #print(f"Service: {service.uuid}")
            for characteristic in service.characteristics:
                UUID = characteristic.uuid
                uuids.append(UUID)
                #print(f"  Characteristic: {characteristic.uuid} (Properties: {characteristic.properties})")

            global read_uuid, write_uuid
            read_uuid = uuids[0]
            write_uuid = uuids[1]


async def query_vlf_bt(device_address, write_uuid, read_uuid):
    async with BleakClient(device_address) as client:
        data = []
        #Queries all ports
        for x in sensor_list:
            command = f'P{x+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").strip()
            data.append(value)
            print(f"Response from {command}: {data}")


scan_devices()
uuid_info(board_sn)
query_vlf_bt(board_sn, write_uuid, read_uuid)
Editor is loading...
Leave a Comment