-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathnotify-and-write.py
More file actions
executable file
·44 lines (33 loc) · 913 Bytes
/
notify-and-write.py
File metadata and controls
executable file
·44 lines (33 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python3
from bleak import BleakClient, BleakScanner
import asyncio
import sys
import binascii
import time
address = ""
rx_uuid = ""
tx_uuid = ""
pkts = []
pkts.append(bytes.fromhex(""))
def notify_callback(sender, data):
print(f"RX: {data}")
async def bleuart():
ret = True
try:
print("Trying to connect...")
async with BleakClient(address) as client:
print(f"Connected to {client.address}")
await client.start_notify(rx_uuid,notify_callback)
await asyncio.sleep(1.0)
for pkt in pkts:
print(f"TX: {pkt}")
await client.write_gatt_char(tx_uuid,pkt)
await asyncio.sleep(1.0)
await client.stop_notify(rx_uuid)
except Exception as e:
print(e)
ret = False
return ret
ret = asyncio.run(bleuart())
if not ret:
print("write error")