Untitled

mail@pastecode.io avatar
unknown
python
8 days ago
1.3 kB
1
Indexable
Never
import asyncio
from bleak import BleakClient

async def query_vlf_ble(address):
    async with BleakClient(address) as client:
        data_dict = {}
        for x in range(1, 30):  # Assuming sensors P01 to P29 based on your description
            sensor = f'P{x:02d}'
            # Example command: Assuming each sensor is queried with a command like "P01", "P02", etc.
            command = sensor.encode('utf-8')
            # Write the command to the BLE device
            await client.write_gatt_char("UUID_OF_YOUR_CHARACTERISTIC", command)
            
            # Example read: Assuming data is received in a similar format to serial communication
            data = await client.read_gatt_char("UUID_OF_YOUR_CHARACTERISTIC")
            data = data.decode("utf-8").replace(';', '').strip()  # Process received data as needed
            
            data_dict[sensor] = data
        
        return data_dict

async def main():
    device_address = "XX:XX:XX:XX:XX:XX"  # Replace with your BLE device address
    try:
        sensor_data = await query_vlf_ble(device_address)
        print("Sensor Data:")
        for sensor, data in sensor_data.items():
            print(f"{sensor}: {data}")
    except Exception as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    asyncio.run(main())
Leave a Comment