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

Proper way to handle a bonded reconnect

According to the spec, this is how a bonded reconnect should work:

On first pass, the central client does discovery and enables descriptors to characteristics of interest. At sometime during this sequence, pairing occurs. The central saves the pairing data, services, etc,, and enabled state information. The peripheral server does the same.

On a reconnect, service discovery, pairing, and enabling descriptors is no longer needed as it is done and saved. One can get right down to data transfer after encryption is established.

Okay, in my pulse ox peripheral, I am having trouble with the restoring of the enabled states of the descriptors. This involves perhaps the most confusing of the sd_* procedures, the notorious

sd_ble_gatts_sys_attr_set

sd_ble_gatts_sys_attr_get 

and saving that info to a file between connections. One of the parameters in the calls is BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS or BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS or (and I am not sure here) entering nothing (0) or maybe the ORing?. I am not sure what I should be saving (and therefore restoring). My understanding is that the 'system services' are things like the service changed characteristic enabled state. 'user' services are things like the continuous measurement characteristic, spot measurement characteristic, and RACP characteristic but I am not sure.

I call the methods using BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS yet on a reconnect I get the error BLE_ERROR_GATTS_SYS_ATTR_MISSING and though I handle the BLE_GATTS_EVT_SYS_ATTR_MISSING event, it never gets signaled.

What do I need to do to fix this?

  • Should I call these methods with just a 0 value and that gives me both?
  • Since when I get the error I am trying to send a continuous measurement by notification should I just assume that the error BLE_ERROR_GATTS_SYS_ATTR_MISSING is misleading, it  really should be BLE_ERROR_GATTS_USR_ATTR_MISSING?

What is the procedure I should follow when disconnecting the first time connect?

  • call the sd_ble_gatts_sys_attr_get  method a couple of times to get the information with BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS or BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS or 0 or (BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS | BLE_GATTS_SYS_ATTR_FLAG_USR_SRVCS)?
  • save the data to a file

On a reconnect, when should I restore the info by calling the sd_ble_gatts_sys_attr_set during the connection event? It better not be later because an RACP transaction can come real fast!

Do I also need to write to the client characteristic configuration descriptors myself on reconnect to restore their 'enabled' state?

Parents Reply Children
Related