Help with AIOBLE
Posted: Fri Jul 23, 2021 6:00 pm
I'm trying to develop a BLE client to get data from an OBDII reader. I have an ESP32 client derived from ble_simple_central.py working to an ESP32 peripheral derived from ble_simple_peripheral.py (but which I cannot get to work with the intended OBDII reader). I am now trying to use @jimmo's aioble library but, so far, with only limited success. I have got to the point where my aioble client can send commands to the ble emulator but, although the emulator is receiving those commands and returning some data, the client is not receiving that data almost certainly because I've got something wrong somewhere. I've looked at the examples and the readme at https://github.com/micropython/micropyt ... oth/aioble but am still struggling.
My code isWhat am I doing wrong?
EDIT - Do I need to subscribe to the notify characteristic for notifications? - And, if so, how and where?
My code is
Code: Select all
_ENV_OBD_UUID = bluetooth.UUID(0xffe0)
_ENV_OBD_RWN_UUID = bluetooth.UUID(0xffe1)
_ENV_OBD_RW_UUID = bluetooth.UUID(0xffee)
...
...
async with connection:
print"Connected")
try:
obd_service = await connection.service(_ENV_OBD_UUID)
obd_rwn = await obd_service.characteristic(_ENV_OBD_RWN_UUID)
obd_rw = await obd_service.characteristic(_ENV_OBD_RW_UUID)
except asyncio.TimeoutError:
print("Timeout discovering services/characteristics")
return
cmds = ["ATZ\n","ATD\n","ATE1\n","ATL1\n","ATH1\n","ATS0\n","ATSTFF\n","ATFE\n","ATSP6\n"]
for cmd in cmds:
try:
await obd_rwn.write(cmd, response=False, timeout_ms=2000) # <------------- Tried response = both True & False
print(cmd[:-1])
rtn = await obd_rwn.read(timeout_ms=2000) # <------------- returns Write command
# rtn = await obd_rwn.notified(timeout_ms=2000) # <------------- Times out
print(cmd)
utime.sleep(1)
except asyncio.TimeoutError:
print("Write timeout")
return
EDIT - Do I need to subscribe to the notify characteristic for notifications? - And, if so, how and where?