natersoz / nrf

A Bluetoothe Low Energy (BLE) class library - initial target: Nordic nRF5x
Apache License 2.0
3 stars 0 forks source link

BLE_GATTS_EVT_SYS_ATTR_MISSING event in ble_peripheral_class when client is iPhone #7

Open natersoz opened 5 years ago

natersoz commented 5 years ago

See https://devzone.nordicsemi.com/f/nordic-q-a/1948/strange-error-code-13313-0x3401-returned-by-sd_ble_gatts_hvx/8365#8365

As the error suggests, it means that the softdevice doesn't yet have a set of system attributes. :-)

I'd recommend you to read this document to better understand the concept of bonding with regard to our softdevice, since it also applies to the system attributes.

As you can see, bonding data is split between encryption keys and the system attributes. System attributes includes for example values for CCCDs, and the softdevice therefore needs to get those before sending any notification. Hence, when you try to send a notification, if the peer device have not yet written to the CCCDs, the softdevice will ask the application whether it has any previous bonding data to be used, by giving a BLE_GATTS_EVT_SYS_ATTR_MISSING. If the device does use bonding, the bond manager will normally handle this event, and pass back whatever data has previously been written.

However, the system attributes are requested with the same event no matter if the device use bonding or not (the softdevice doesn't really know that). If a device does not use bonding, but in this case, you can just reply like this:

natersoz commented 5 years ago

More from the linked answer:

If you already have this case, I'd expect this error to be returned only for a very short time, and then disappear as soon as the application has replied to the event.

If you know that you'll never have any system attributes stored (i.e. you don't use bonding), it should be fine to move the setting of system attributes to the connected event, if you for some reason need to avoid seeing this error at all.