-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathread.py
More file actions
executable file
·42 lines (34 loc) · 960 Bytes
/
read.py
File metadata and controls
executable file
·42 lines (34 loc) · 960 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
#!/usr/bin/env python3
from bleak import BleakClient, BleakScanner
import asyncio
import sys
import binascii
async def read(address,uuid):
data = False
try:
async with BleakClient(address) as client:
print(client.mtu_size)
#client.mtu_size = 512
data = await client.read_gatt_char(uuid)
except Exception as e:
print(e)
return data
if len(sys.argv) < 3:
print("usage: "+sys.argv[0]+" <device MAC> <characteristic UUID>")
print("device MAC: MAC address of the BLE server")
print("UUID: UUID of the BLE characteristic to read")
sys.exit(1)
address = sys.argv[1]
uuid = sys.argv[2]
data = asyncio.run(read(address,uuid))
if not data:
print("not found")
else:
print("HEX: " + ''.join(format(x, '02x') for x in data))
s = ""
for b in data:
if b >= 32 and b <= 127:
s += chr(b)
else:
s += "."
print("STRING: " + s)