This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Adding Custom Characteristic pc-ble-driver-py

Hi,

I'm trying to emulate a server device with pc-ble-driver-py, I recently moved from version 0.11.4 using Python 2.7.12 to version 0.14.0 using Python 3.7.4. I'm trying to perform these tasks on a nrf52840 dongle with the connectivity FW and S132 SoftDevice:

  1. Adding a custom service
  2. Adding two custom characteristics to that service

On both versions I've been able to add the custom service but I've had some problems adding the characteristics.

On the older version I did it but on the newer one I noticed that you created new classes to help this process, and I tried to repeat the process in this scenario. I'm not able to make it work properly so I'm trying to understand if I am missing something. To work around this issue I managed to perform the tasks calling directly the soft-device function instead of the higher level methods.

Old version:

s_handle = driver.uint16_value(self.bc_service.handle)
char_md = driver.ble_gatts_char_md_t()
cccd_md = driver.ble_gatts_attr_md_t()
attr_char_value = driver.ble_gatts_attr_t()
attr_md = driver.ble_gatts_attr_md_t()
handles = driver.ble_gatts_char_handles_t()

char_md.char_props.read = 1
char_md.char_props.notify = 1

char_md.p_char_user_desc = None
char_md.p_char_pf = None
char_md.p_user_desc_md = None
char_md.p_cccd_md = cccd_md
char_md.p_sccd_md = None

rp = driver.ble_gap_conn_sec_mode_t(); rp.sm = 1; rp.lv = 1
wp = driver.ble_gap_conn_sec_mode_t(); wp.sm = 1; wp.lv = 1

attr_md.read_perm = rp
attr_md.write_perm = wp
attr_md.vloc = driver.BLE_GATTS_VLOC_STACK
attr_md.rd_auth = 0
attr_md.wr_auth = 0
attr_md.vlen = 1 #variable length characteristic

cccd_md.read_perm = rp
cccd_md.write_perm = wp
cccd_md.vloc = driver.BLE_GATTS_VLOC_STACK

attr_char_value.p_uuid = self.read_only_char.uuid.to_c()

attr_char_value.p_attr_md = attr_md
attr_char_value.init_len = 0
attr_char_value.init_offs = 0
attr_char_value.max_len = driver.BLE_GATTS_FIX_ATTR_LEN_MAX

return self.adapter.driver.ble_gatts_characteristic_add(service_handle = s_handle,
                                                        char_md = char_md,
                                                        attr_char_value = attr_char_value,
                                                        char_handle = handles) ,\
       handles.value_handle

New version:

s_handle = self.bc_service.handle.handle
attr_md = BLEGattsAttrMD()
handles = BLEGattsCharHandles()

char_props = BLEGattCharProps(read = True, notify = True, indicate = False)
char_md = BLEGattsCharMD(char_props = char_props)

char_uuid = self.read_only_char.uuid

attr_char_value = BLEGattsAttr(char_uuid, attr_md, driver.BLE_GATTS_FIX_ATTR_LEN_MAX)

return self.adapter.driver.ble_gatts_characteristic_add(service_handle = s_handle,
                                                        char_md = char_md,
                                                        attr_char_value = attr_char_value,
                                                        char_handle = handles) ,\
       handles

With the new version I actually can add the characteristics but when I try to read or write from the client it's not possible. So I suppose that the problem is something related to read and write permissions, but I've not found out where to initialize them in the properties of the new classes, so I've got back to the old solution calling directly the SoftDevice function sd_ble_gatts_characteristic_add().

I hope you could help me figuring out where I'm missing something

Thank you in advance,

Best regards

Mirko

Parents
  • Hi,

    This question has been here a while with no answer. Have you gotten any further? I am sure a quick write-up of the solution (if you have one) is appreciated by others who may see similar issues in the future.

    There is an example of using those functions in tests/test_server_client.py that you could use for reference. May it be that you have not fully embraced the use of the helper classes, e.g. BLEGattHandle?

    In what way does it not work? Error messages, at what point does it fail, etc.

    Regards,
    Terje

Reply
  • Hi,

    This question has been here a while with no answer. Have you gotten any further? I am sure a quick write-up of the solution (if you have one) is appreciated by others who may see similar issues in the future.

    There is an example of using those functions in tests/test_server_client.py that you could use for reference. May it be that you have not fully embraced the use of the helper classes, e.g. BLEGattHandle?

    In what way does it not work? Error messages, at what point does it fail, etc.

    Regards,
    Terje

Children
No Data
Related