pc_ble_driver_py.exceptions.NordicSemiException: Characteristic value handler not found

Using the pc_ble_driver_py.ble_driver I'm able to subscribe to notifications, but unable to get the values upon connection. The error is:

 "/home/marc/dev/src/<redacted>/v2/./gui.py", line 258, in connect_and_discover
status, data = self.adapter.read_req(new_conn, build_uuid('button'))
File "/home/marc/.local/lib/python3.9/site-packages/pc_ble_driver_py/ble_adapter.py", line 528, in read_req
raise NordicSemiException("Characteristic value handler not found")
pc_ble_driver_py.exceptions.NordicSemiException: Characteristic value handler not foundFile

I do not know how to install a value handler and could not find documentation about it. The code looks like:

new_conn = self.conn_q.get(timeout=scan_duration)
self.adapter.service_discovery(new_conn)
self.adapter.enable_notification(new_conn, build_uuid('button'))
def read_value(adapter, conn_handle, handle, offset):
    logging.debug(f"Readvalue({conn_handle} {handle} {offset}")
status, data = self.adapter.read_req(new_conn, build_uuid('button'))
logging.info('button_status: {} status: {}'.format(data, status))

and fails in read_req().

Any help would be helpful ; thanks.

Marc.

Parents
  • In fact, the error message tricked me. It should probably be `value handle` and not `value handler`.

    After realizing that value_handle could be specified and debugging the search for handles, I realized that I had to specify that my UUID is vendor specific.

    The fix:

    from pc_ble_driver_py.ble_driver import driver
    
    […]
    
    UUIDS = {
        'base': "0000XXXX-1212-EFDE-1523-785FEABCD123",
        'led': 0x1525,
        'button': 0x1524,
    }
    
    def uuid(key):
        """Parse a string and returns a BLEUUID"""
        string = UUIDS[key]
        return list(bytearray.fromhex(string.replace('-', '').replace('X', '0')))
    
    
    def build_uuid(key):
        """Build a nordic BLEUUID from a key (led, button)"""
        return BLEUUID(UUIDS[key], BLEUUIDBase(uuid('base'), uuid_type=driver.BLE_UUID_TYPE_VENDOR_BEGIN))

    What's strange is that googling for BLE_UUID_TYPE_VENDOR_BEGIN + python does not give a lot of answer.

    Marc.

Reply
  • In fact, the error message tricked me. It should probably be `value handle` and not `value handler`.

    After realizing that value_handle could be specified and debugging the search for handles, I realized that I had to specify that my UUID is vendor specific.

    The fix:

    from pc_ble_driver_py.ble_driver import driver
    
    […]
    
    UUIDS = {
        'base': "0000XXXX-1212-EFDE-1523-785FEABCD123",
        'led': 0x1525,
        'button': 0x1524,
    }
    
    def uuid(key):
        """Parse a string and returns a BLEUUID"""
        string = UUIDS[key]
        return list(bytearray.fromhex(string.replace('-', '').replace('X', '0')))
    
    
    def build_uuid(key):
        """Build a nordic BLEUUID from a key (led, button)"""
        return BLEUUID(UUIDS[key], BLEUUIDBase(uuid('base'), uuid_type=driver.BLE_UUID_TYPE_VENDOR_BEGIN))

    What's strange is that googling for BLE_UUID_TYPE_VENDOR_BEGIN + python does not give a lot of answer.

    Marc.

Children
Related