Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Connect by BLEDevice
- """
- import asyncio
- import bitstruct
- import platform
- import sys
- from bleak import BleakClient, BleakScanner
- from bleak.exc import BleakError, BleakDBusError
- # Battery 1
- #address = "64:69:4E:35:CE:71"
- # dev_name = "Li3-093020432"
- # Battery 2
- address = "64:69:4E:38:44:B3"
- # dev_name = ""
- service_uuid = "0000ffe0-0000-1000-8000-00805f9b34fb"
- characteristic_uuid = "0000ffe1-0000-1000-8000-00805f9b34fb"
- async def main(ble_address: str):
- device = await BleakScanner.find_device_by_address(ble_address, timeout=5.0)
- if not device:
- raise BleakError(f"A device with address {ble_address} could not be found.")
- async with BleakClient(device) as client:
- # aprint(dir(client)) # COOPER
- services = await client.get_services()
- for service in services:
- if service.uuid != service_uuid:
- continue
- for character in service.characteristics:
- # print(dir(character)) # COOPER
- chars = await client.read_gatt_char(character)
- print(f"Service: {service} - Character: {character}:")
- print(len(chars), chars)
- # How the fuck do I unpack this 47 bits into usable shit ... I've tried struct, ctyes and other 3rd party shit
- # No idea how to get the a CSV string or seperate ints
- return 0
- if __name__ == "__main__":
- asyncio.run(main(address))
Add Comment
Please, Sign In to add comment