You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importasynciofrombleakimportBleakClient# Replace these with your actual device address and characteristic UUIDDEVICE_ADDRESS="8D:3C:82:19:5F:7C"# Your BLE device's addressCHARACTERISTIC_UUID="0000ffe1-0000-1000-8000-00805f9b34fb"# UUID of the target BLE characteristicasyncdefmain():
asyncwithBleakClient(DEVICE_ADDRESS) asclient:
ifclient.is_connected:
print("Connected to device")
# Send data (example: send [0x01, 0x02])data_to_send=bytearray([0x01, 0x02])
awaitclient.write_gatt_char(CHARACTERISTIC_UUID, data_to_send)
print(f"Sent data: {data_to_send}")
else:
print("Failed to connect")
# Run the main looploop=asyncio.get_event_loop()
loop.run_until_complete(main())
Logs
Connected to device
Traceback (most recent call last):
File "/home/dixiong/data_sender.py", line 21, in <module>
loop.run_until_complete(main())
File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/home/dixiong/data_sender.py", line 14, in main
await client.write_gatt_char(CHARACTERISTIC_UUID, data_to_send)
File "/home/.local/lib/python3.10/site-packages/bleak/__init__.py", line 786, in write_gatt_char
await self._backend.write_gatt_char(characteristic, data, response)
File "/home/sahil/.local/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 862, in write_gatt_char
assert_reply(reply)
File "/home/.local/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 20, in assert_reply
raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.bluez.Error.Failed] Not connected
The text was updated successfully, but these errors were encountered:
Description
I am trying to send some data to my BLE module .
What I Did
Logs
The text was updated successfully, but these errors were encountered: