deleted
Yes, Please share you whole project zipped. I need to see what your code is doing in other callbacks like connected(). I also need to see how you are giving the semaphore sem_connected.
deleted
There is a bug in your code, in the connected_cb() you are not giving the semaphore when the connection fails.
So when there is a connection failure your main loop is stuck. You also still have k_sem_take waiting for K_FOREVER.
I suggest you one of the two changes
1) In your connected_cb()
static void connected_cb(struct bt_conn *conn, uint8_t err)
{
if (err) {
LOG_ERR("Connection failed (err 0x%02x)", err);
bt_conn_unref(conn);
k_sem_give(&sem_connected); // ADD THIS NEW LINE ADDED SUSHEEL
return;
}
/* On success the same give(), which you are doing already. */
k_sem_give(&sem_connected);
…
}
2) Make sure your k_sem_take are not waiting for ever and PLEASE DO NOT IGNORE RETURN VALUES of function calls like k_sem_take
Assuming that you are able to reproduce this on DK, Can you please attach your minimalistic project so that I can reproduce this on my desk and find out the reason for this. This will avoid a lot of ping pong questions and let me dive straight to debugging.