-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignals.py
62 lines (36 loc) · 1.72 KB
/
signals.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import asyncio
from bleak import BleakClient
ADDRESS = "D8:B6:73:04:F1:F2" # Replace with your device's address
CHARACTERISTIC_UUID = "0000FFE1-0000-1000-8000-00805F9B34FB" # Replace with the characteristic UUID you want to interact with
textFile = open("emotionCodes.txt", "r")
async def main():
async with BleakClient(ADDRESS) as client:
while True:
# Write data to the characteristic
lines = textFile.readlines()
#last = lines[-1].strip
last = lines[len(lines)-1].strip()
# if not last:
# last = last.strip()
# else:
# last = '0'
print(f"{last}, {lines}")
if last == '1':
await client.write_gatt_char(CHARACTERISTIC_UUID, bytearray([0x01]))
print("Sent: 1")
await asyncio.sleep(5)
response = await client.read_gatt_char(CHARACTERISTIC_UUID)
elif last == '2':
await client.write_gatt_char(CHARACTERISTIC_UUID, bytearray([0x02]))
print("Sent: 2")
await asyncio.sleep(5)
response = await client.read_gatt_char(CHARACTERISTIC_UUID)
else:
await client.write_gatt_char(CHARACTERISTIC_UUID, bytearray([0x03]))
print("Sent: 3")
await asyncio.sleep(5)
response = await client.read_gatt_char(CHARACTERISTIC_UUID)
# Write data to the characteristic
# Read data from the characteristic
asyncio.run(main())
textFile.close()