cooperlees

Untitled

Jan 25th, 2022
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. """
  2. Connect by BLEDevice
  3. """
  4.  
  5. import asyncio
  6. import bitstruct
  7. import platform
  8. import sys
  9.  
  10. from bleak import BleakClient, BleakScanner
  11. from bleak.exc import BleakError, BleakDBusError
  12.  
  13.  
  14. # Battery 1
  15. #address = "64:69:4E:35:CE:71"
  16. # dev_name = "Li3-093020432"
  17. # Battery 2
  18. address = "64:69:4E:38:44:B3"
  19. # dev_name = ""
  20. service_uuid = "0000ffe0-0000-1000-8000-00805f9b34fb"
  21. characteristic_uuid = "0000ffe1-0000-1000-8000-00805f9b34fb"
  22.  
  23.  
  24. async def main(ble_address: str):
  25.     device = await BleakScanner.find_device_by_address(ble_address, timeout=5.0)
  26.     if not device:
  27.         raise BleakError(f"A device with address {ble_address} could not be found.")
  28.  
  29.     async with BleakClient(device) as client:
  30.         # aprint(dir(client))  # COOPER
  31.  
  32.         services = await client.get_services()
  33.         for service in services:
  34.             if service.uuid != service_uuid:
  35.                 continue
  36.  
  37.             for character in service.characteristics:
  38.                 # print(dir(character))  # COOPER
  39.                 chars = await client.read_gatt_char(character)
  40.                 print(f"Service: {service} - Character: {character}:")
  41.                 print(len(chars), chars)
  42.                 # How the fuck do I unpack this 47 bits into usable shit ... I've tried struct, ctyes and other 3rd party shit
  43.                 # No idea how to get the a CSV string or seperate ints
  44.  
  45.         return 0
  46.  
  47.  
  48. if __name__ == "__main__":
  49.     asyncio.run(main(address))
Add Comment
Please, Sign In to add comment