I recently started development on NRF52833 for one of my projects. I use segger embedded studio with the "ble_app_uart" example. As I mentioned I'm using nrf52833 DK so I used soft-device s140 for BLE communication.
what I want to achieve !!
I want to advertise the data dynamically on BLE. The data is updated as per user need for an example on the button press the data packet updated. Currently, I just use some delay after adertising_init(), then try to update the new data.
The issue I'm facing!!
The static void advertising_init(), function work to perfect the data advertise properly, the device is visible on nrfconnect app, but when I update my data using the ble_advertising_advdata_update() function the device is no longer visible on nrfconnect app.
The functions which I'm using :
static void advertising_init(void)
{
uint32_t err_code;
ble_advertising_init_t init;
ble_advdata_manuf_data_t manuf_data;
memset(&init, 0, sizeof(init));
uint8_t data[] = {0xAB, 0xCD, 0xFE, 0xBF}; // this is the advertise data
manuf_data.company_identifier = 0x0059;
manuf_data.data.p_data = data;
manuf_data.data.size = sizeof(data);
init.advdata.name_type = BLE_ADVDATA_FULL_NAME;
init.advdata.include_appearance = false;
init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
init.config.ble_adv_fast_enabled = true;
init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
init.config.ble_adv_fast_timeout = APP_ADV_DURATION;
init.evt_handler = on_adv_evt;
err_code = ble_advertising_init(&m_advertising, &init);
APP_ERROR_CHECK(err_code);
ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
}
update data function:
void update_function(ODID_BasicID_data *BasicID)
{
// Ensure the ID is null-terminated
char buf[ODID_ID_SIZE + 1] = { 0 };
memcpy(buf, BasicID->UASID, ODID_ID_SIZE);
const char ODID_BasicID_data_format[] =
"UAType: %d\nIDType: %d\nUASID: %s\n";
printf(ODID_BasicID_data_format, BasicID->IDType, BasicID->UAType, buf);
//------- send data on ble ----------------------------------//
ret_code_t err_code;
ble_advdata_manuf_data_t manuf_data;
new_advdata.p_manuf_specific_data = &manuf_data;
uint8_t data[] = {0xAB, 0xCD, 0xFE, 0xBF}; // this is the advertise data
manuf_data.company_identifier = 0x0059;
manuf_data.data.p_data = buf;
manuf_data.data.size = sizeof(buf);
err_code = ble_advertising_advdata_update(&m_advertising, &new_advdata, NULL);
APP_ERROR_CHECK(err_code);
}
main function:
int main(void)
{
bool erase_bonds;
// Initialize.
uart_init();
log_init();
timers_init();
buttons_leds_init(&erase_bonds);
power_management_init();
ble_stack_init();
gap_params_init();
gatt_init();
services_init();
advertising_init();
conn_params_init();
// Start execution.
printf("\r\nUART started.\r\n");
NRF_LOG_INFO("Debug logging for UART over RTT started.");
advertising_start();
NRF_LOG_FLUSH();
nrf_delay_ms(5000); // after 5s delay the advertising packet updated with drone
update_function();
//Enter main loop.
for (;;)
{
idle_state_handle();
}
}
The code works fine no error comes in compiling and debugging.
I want to add some more of the same code I use on nrf52832 with soft-device s132, the packets update fine.. I don't understand why there is an issue on nrf52832.