Hello everyone,
I am using the NRF5340-DK development board, but I am having trouble restarting advertising when my smartphone connects or disconnects from the board. Once I connect and pair my smartphone, advertising stops. I am trying to restart it after the BLE disconnect callback, but despite no function returning an error, I cannot see the board advertising on my smartphone. Below is a snippet of my code:
/* Disconnect callback */ void BLEHandler::BluetoothDisconnected(struct bt_conn *conn, uint8_t reason) { ble::BLEHandler& BLE = ble::BLEHandler::Instance(); char addr[BT_ADDR_LE_STR_LEN]; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); k_sem_give(&BLE.m_DisconnectedSemaphore); }
Main loop:
if(k_sem_take(&m_DisconnectedSemaphore, K_NO_WAIT) == 0) { int rc = bleHandler.StopAdvertise(); if(rc != 0) Log("Error stop advertise: %d\n", rc); k_msleep(100); rc = bleHandler.StartAdvertise(&BLEConfig); if(rc != 0) Log("Error re-start advertise: %d\n", rc); else Log("Restarted advertise\n"); }
And my StartAdvertise function:
int BLEHandler::StartAdvertise(const BluetoothConfig_st *config) { int rc = 0; if (config->CCC_DK_DeviceName == NULL) return -EINVAL; rc = bt_set_name(config->CCC_DK_DeviceName); if (rc != 0) return rc; rc = bt_le_adv_start(&config->CCC_DK_AdvParameters, config->CCC_DK_AdvData, config->CCC_DK_AdvDataSize, NULL, 0); return rc; }
Does anyone know if this is the normal behaviour, or how can I fix this?
Best regards.