Untitled
unknown
python
a year ago
1.2 kB
12
Indexable
import asyncio
from bleak import BleakClient, BleakScanner
def txt(file_path):
with open(file_path, "r") as file:
lines = file.readlines()
device_address = lines[0].strip()
#print(device_address)
read_uuid = lines[1].strip()
#print(read_uuid)
write_uuid = lines[2].strip()
#print(write_uuid)
return device_address, read_uuid, write_uuid
file_path = "BTinfo.txt"
async def query_vlf_bt(device_address, write_uuid, read_uuid):
async with BleakClient(device_address) as client:
data_dict = {}
#Queries all ports
for x in range(0,32):
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)
data = response.decode("utf-8").strip()
data_dict[command] = data
print(f"Response from {command}: {data}")
return data_dict
async def combine(file_path):
device_address, read_uuid, write_uuid = txt(file_path)
await query_vlf_bt(device_address, write_uuid, read_uuid)
asyncio.run(combine(file_path))Editor is loading...
Leave a Comment