Created
October 15, 2024 08:08
-
-
Save chrisboyle/e7ed03a14d901c915e456bacd48e6e06 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import asyncio | |
import binascii | |
import sys | |
from bleak import BleakClient | |
from bleak.backends.characteristic import BleakGATTCharacteristic | |
NOTIFY_UUID = "aae28f01-71b5-42a1-8c3c-f9cf6ac969d0" | |
WRITE_UUID = "aae28f02-71b5-42a1-8c3c-f9cf6ac969d0" | |
def callback(sender: BleakGATTCharacteristic, data: bytearray): | |
print(f"{sender}: {binascii.hexlify(data)}") | |
async def main(): | |
async with BleakClient(sys.argv[1]) as client: | |
await client.start_notify(NOTIFY_UUID, callback) | |
print("connected") | |
await client.write_gatt_char(WRITE_UUID, bytearray.fromhex(sys.argv[2]), response=True) | |
print("written") | |
await asyncio.sleep(1) # allow for any slow messages | |
await client.stop_notify(NOTIFY_UUID) | |
asyncio.run(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment