I'm having some issues with my Peripheral failing to restart advertising after its disconnected from the Client.
In my main loop, I am looking at a bunch of flags to decide what to do next, and part of that is to check one that tracks the BLE status:
typedef enum
{
BLE_CONNECTED,
BLE_DISCONNECTED,
BLE_ADVERTISING,
BLE_NOT_STARTED,
BLE_STOPPED
} bt_current_state;
In my callback that gets called when I disconnect from the Client, I set this flag to BLE_ADVERSTING:
void disconnected(struct bt_conn *conn, uint8_t reason)
{
char addr[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
LOG_INF("INFO: Disconnected from %s (reason 0x%02x)", addr, reason);
bt_status = BLE_ADVERTISING;
}
Then in my main loop, I look for this flag being set to BLE_ADVERSTING and I update my scan response data, then attempt to update the adversting data with this new scan response data:
if (bt_status == BLE_ADVERTISING)
{
update_sr_data(sst_data, sr_data);
update_adv_data();
}
But for some reason, I am getting an error when I make a call to update_adv_data. This function does the following:
void update_adv_data(void)
{
int8_t err;
err = bt_le_adv_update_data(ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));
if (err & (bt_status == BLE_ADVERTISING))
{
LOG_ERR("ERROR: Adv data update failed (err %d)",err);
}
}
I am getting an error of -11 from that call to bt_le_adv_update_data which seems to indicate that the Peripheral isn't actually advertising if I understand this section of that API correctly:
if (!atomic_test_bit(adv->flags, BT_ADV_ENABLED)) {
return -EAGAIN;
}
So, I'm trying to work out where things are falling over, as I would expect that once the Peripheral disconnects, it should automatically restart advertising. I know its at least getting the disconnect callback because I see the printk() statement from that callback on my Terminal software:
INFO: Disconnected from F4:21:CA:73:F6:AE (public) (reason 0x16)
If I understand that code correctly, it means that the Local Host (my Client) has initiated the disconnect, which is what I am expecting to happen. What I can't seem to work out is why my Peripheral then fails to re-start advertising.
Can anyone assist me in what I need to be looking at to try and resolve this issue?
Regards
Mike