Hello,
I am playing around with pc-ble-driver-py to make a connection towards a BLE peripheral. The peripheral is using a custom service very similar to the Nordic UART Service. I have managed to get it working but I am unable to exchange the MTU size and is stuck with the 23 bytes default MTU.
I have been looking into other code examples and this is what I'm trying to do:
CFG_TAG = 1 nrf_sd_ble_api_ver = config.sd_api_ver_get() assert nrf_sd_ble_api_ver == 5 # Setup BLEDriver and BLEAdapter driver = BLEDriver( serial_port='/dev/tty.usbmodem0006826680971', auto_flash=False, baud_rate=1000000, log_severity_level="info" ) adapter = BLEAdapter(driver) # Later in code cfg = BLEConfigGapRoleCount(central_role_count=1, periph_role_count=0, central_sec_count=0) cfg.conn_cfg_tag = CFG_TAG self.adapter.driver.ble_cfg_set(BLEConfig.role_count, cfg) cfg = BLEConfigConnGatt(att_mtu=Central.LOCAL_ATT_MTU) # Central.LOCAL_ATT_MTU = 247 cfg.conn_cfg_tag = CFG_TAG self.adapter.driver.ble_cfg_set(BLEConfig.conn_gatt, cfg) cfg = BLEConfigConnGap(event_length=320) cfg.conn_cfg_tag = CFG_TAG self.adapter.driver.ble_cfg_set(BLEConfig.conn_gap, cfg) self.adapter.driver.ble_enable() self.adapter.driver.ble_vs_uuid_add(Central.BASE_UUID) # Start scan, find device and connect self.adapter.connect(peer_addr, tag=CFG_TAG) logging.info('MTU Size: {}'.format(self.adapter.db_conns[self.conn_handle].att_mtu)) # Prints 23 if Central.LOCAL_ATT_MTU > ATT_MTU_DEFAULT: logging.info('Requesting MTU exchange') self.att_mtu = self.adapter.att_mtu_exchange(self.conn_handle, Central.LOCAL_ATT_MTU) max_data_length = 251 data_length = self.att_mtu + 4 if data_length > max_data_length: data_length = max_data_length self.adapter.data_length_update(self.conn_handle, data_length)
Here i get error message:
2020-11-11 10:03:09,265 root INFO Requesting MTU exchange Traceback (most recent call last): File "/test/venv/lib/python3.7/site-packages/pc_ble_driver_py/ble_adapter.py", line 220, in att_mtu_exchange self.driver.ble_gattc_exchange_mtu_req(conn_handle, mtu) File "/test/venv/lib/python3.7/site-packages/pc_ble_driver_py/ble_driver.py", line 107, in wrapper error_code=err_code, pc_ble_driver_py.exceptions.NordicSemiException: Failed to ble_gattc_exchange_mtu_req. Error code: NRF_ERROR_INVALID_PARAM The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/test/test.py", line 227, in <module> central.start() File "/test/test.py", line 133, in start self.att_mtu = self.adapter.att_mtu_exchange(self.conn_handle, Central.LOCAL_ATT_MTU) File "/test/venv/lib/python3.7/site-packages/pc_ble_driver_py/ble_adapter.py", line 225, in att_mtu_exchange "different config tags used in ble_cfg_set and connect.") from ex pc_ble_driver_py.exceptions.NordicSemiException: MTU exchange request failed. Common causes are: missing att_mtu setting in ble_cfg_set, different config tags used in ble_cfg_set and connect.
Any suggestion how to proceed with this?