aboutsummaryrefslogtreecommitdiffstats
path: root/client/python/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'client/python/client.py')
-rw-r--r--client/python/client.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/client/python/client.py b/client/python/client.py
new file mode 100644
index 0000000..4cd4672
--- /dev/null
+++ b/client/python/client.py
@@ -0,0 +1,55 @@
+"""
+2024-12-22 23:07:22,916 __main__ INFO: starting scan...
+2024-12-22 23:07:23,257 __main__ INFO: connecting to device...
+2024-12-22 23:07:23,910 __main__ INFO: connected
+2024-12-22 23:07:23,910 __main__ INFO: [Service] 00001801-0000-1000-8000-00805f9b34fb (Handle: 6): Generic Attribute Profile
+2024-12-22 23:07:23,911 __main__ INFO: [Service] 00000000-0000-1000-8000-00805f9b34fb (Handle: 7): Vendor specific
+2024-12-22 23:07:23,911 __main__ INFO: [Characteristic] 00000002-0000-1001-8001-00805f9b07d0 (Handle: 10): Unknown (notify)
+2024-12-22 23:07:24,173 __main__ INFO: [Descriptor] 00002902-0000-1000-8000-00805f9b34fb (Handle: 12): Client Characteristic Configuration, Value: bytearray(b'\x00\x00')
+2024-12-22 23:07:24,174 __main__ INFO: [Characteristic] 00000001-0000-1001-8001-00805f9b07d0 (Handle: 8): SDP (write-without-response,write), Max write w/o rsp size: 253
+2024-12-22 23:07:24,174 __main__ INFO: disconnecting...
+2024-12-22 23:07:28,414 __main__ INFO: disconnected
+"""
+
+import asyncio
+import binascii
+from bleak import BleakClient
+
+def callback(_: int, data: bytearray):
+ print("received:", data)
+ print("received:", data.hex())
+ print("len:", len(data))
+
+def convertInput(i):
+ decimal_value = int(i)
+ hex_string = hex(decimal_value).split('x')[-1]
+ if len(hex_string) % 2 != 0:
+ hex_string = '0' + hex_string
+ byte_array = binascii.unhexlify(hex_string)
+ return byte_array
+
+async def main():
+ ble_address = "8D:FE:5B:68:D6:D9"
+ characteristic = "00000001-0000-1001-8001-00805f9b07d0"
+ notify_listen = "00000002-0000-1001-8001-00805f9b07d0"
+
+ async with BleakClient(ble_address) as client:
+ #await client.write_gatt_char(characteristic, b"\x00\x01\xf4", response=False)
+ #await client.write_gatt_char(characteristic, b"\x01\x00\x00", response=False)
+ #await client.write_gatt_char(characteristic, b"\x02\x00\x00", response=False)
+ # we’ll do the read/write operations here
+ print("Connected to BLE device")
+ print(client.is_connected)
+ while True:
+ usduty = input("rgbcw")
+# c = convertInput(1)
+# duty = convertInput(rgbcw)
+# cmd = c + rgbcw
+# print("sending command ")
+# print(cmd)
+ await client.write_gatt_char(characteristic, b"\x01\xFF\xFF\xFF\x10\xFF", response=False)
+ try:
+ await client.start_notify(notify_listen, callback)
+ except Exception as e:
+ return
+asyncio.run(main())