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

nrf52840 Dongle and ble_serial.py

I am trying to run ble_serial.py in the ble_app_cli SDK example using the nrf52840 dongle. To do so, I tried flashing the connectivity firmware automatically via the nrfConnect Desktop Bluetooth Low Energy application. When I run the python script, I can connect and everything runs OK for 30 seconds although there is one exception: 

Exception: 'BLE_Serial' object has no attribute 'on_gattc_evt_exchange_mtu_rsp'

After 30 seconds, it loses connection and constantly tries to reconnect with no success. I have also tried flashing connectivity_1.2.3_usb_dfu_pkg.zip from the pc-ble-driver repo checking to see if it could be a version issue but the problem exists there as well. 

Any idea what could be going wrong?

Parents Reply Children
  • I am using SDK 15.2.0 and the  Experimental: Console over Bluetooth Application example python script with my custom application. 

    My custom peripheral application implements pairing/bonding. I found out that the source of the timeout is not the ATT MTU exchange but an authentication timeout; I need to implement authentication in the ble_serial.py script. I have had limited luck with that. I have tried calling: self.adapter.authenticate(self.conn_handle, bond=True, lesc=False) after a successful connection. This works if the peripheral isn't bonded yet, i.e first time bond. What is the correct way to re-establish a connection with a bonded device using pc-ble-driver-py? Is there any example of a pc-ble-driver-py implementing bonding/pairing?

  • Hi,

    Yes I think you are onto the right track then. self.adapter.authenticate() is used for pairing, optionally also bonding.

    In order to reestablish a bond you can use self.adapter.encrypt(), with the keys that were stored during self.adapter.authenticate(). The central is free to start this procedure when it wants to, and so it should be safe to do as early as on the connection event if you want to.

    The correct way to handle a security request (on_gap_evt_sec_request) is to either authenticate() or encrypt(), depending on whether a bond already exists. Similarly, you may choose to do either authenticate() or encrypt() on the connected event, based on whether the peer is previously bonded or not.

    The self.adapter.authenticate() and self.adapter.encrypt() API calls correspond to sd_ble_gap_authenticate() and sd_ble_gap_encrypt() from the SoftDevice API documentation. See for instance the Security Request Reception Message Sequence Chart.

    Regards,
    Terje

  • Thank you for that. How can I tell when a connected peer is already bonded? And what are the parameters for self.adapater.encrypt()?

  • Hi,

    Sorry for not getting back to you before the holidays.Have you found answers to your latest questions?

    Regards,
    Terje

  • I haven't found the answers yet. Additionally, I had another question -- does the dongle store the peer bond information on its flash (like using the peer manage) or do we need to store it locally on the PC?

Related