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:
- Adding a custom service
- 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