When the nrf device momentarily disconnects from my app, and the app immediately reconnects, the sd_ble_gatts_hvx function returns an error 13313 (0x3401).
I understand that this means that system attributes are missing. As suggested elsewhere on the forum, I have
case BLE_GATTS_EVT_SYS_ATTR_MISSING: err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0); APP_ERROR_CHECK(err_code); break
in my ble_evt handler, but that event never fires.
Instead, when the sd_ble_gatts_hvx fails with error 13313 I run:
ret = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
This returns 0, however subsequent calls to sd_ble_gatts_hvx return 8 (invalid state).
In the original, valid, connection I observe:
- GATT write to attribue 16, length 2
- GATT write to attribute 13, length 1
- GATT write to attribute 13, length 20
- GATT read of attribute 13, length 1
After the reconnection, the connection id is that same number and I see only
- GATT read of attribute 13, length 1
I think what is happening is that the app client expects the device to remember some parameters (I suppose the CCCD), but the device has erased that information.
I am not using bonding, just connecting to the device. This is for SDK 17.1.0 Softdevice S112. The application is using FlutterBluePlus to manage the connection.
I suspect that the solution is that the GATT handshake needs to be completed, but I'm not sure if that needs to be fixed on the device or the app.