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

Peripheral HIDS keyboard example - bt_gatt_is_subscribed returns False after rebooting the nRF52840

When I build and run an example Bluetooth: Peripheral HIDS keyboard (it's the same for master branch and v1.3.2) using nRF52840 DK I faced one strange behaviour. To simplify the problem description I added "CONFIG_NFC_OOB_PAIRING=n" to prj.conf to remove NFC pairing, and I also added "CONFIG_ASSERT=y". Anyway, the problem was the same with or without these modifications. Thus, the firmware had started, I connected to the board and bond. After it, I pushed Button 1 and had an output in a phone (Android) text editor, as it's expected. After it, I rebooted the board (it doesn't matter how, using a RESET Button or pulling the USB cable on a laptop), and after rebooting the board, the phone connected to the board again automatically. I could see it in my phone settings that it's connected and judging by LED2 on the board, which was on. And when I pushed Button 1 that time, then I just had an error in UART logs and nothing in the text editor in the phone, as it was before the board rebooting:

Key report send error: -13

It seems that the problem is in this piece of code:

if (!bt_gatt_is_subscribed(conn, rep_attr, BT_GATT_CCC_NOTIFY)) {
	return -EACCES;
}

And the description of this errno code is:

#define EACCES 13       /* Permission denied */

If to compare flows of executions the function bt_gatt_is_subscribed in both cases, then we can see the difference in checking if the connection is subscribed. In the case of normal execution, "cfg->peer" contains an appropriate remote peer address, but in the case of described above error, it has all zeros. Whereas "bt_conn_get_dst(conn)->a.val" has the right value in the both cases.

However, when I turned off and turned on Bluetooth on the phone, then it also connected to the board and everything worked properly again. Can you explain to me why I have such kind of sending error (Key report send error: -13) after rebooting the board? What's the problem with bt_gatt_is_subscribed function that it returns False after rebooting the board, but it returns True after reconnection Bluetooth on the phone?

Parents Reply Children
No Data
Related