Here I use gpiote and Ble_template_example.
int main(void) { ret_code_t err_code; bool erase_bonds; // Initialize. log_init(); timers_init(); power_management_init(); ble_stack_init(); gap_params_init(); gatt_init(); advertising_init(); services_init(); conn_params_init(); peer_manager_init(); // Start execution. NRF_LOG_INFO("Ble Advertising start"); application_timers_start(); advertising_start(erase_bonds); } while(true) { //do something }
The advertisement code is working fine but now I use button interrupt to send different payload or the button press change the advertising name to something new .
here is the interrupt code I use but it's not working .. not working advertising not working code compile good but when the code enter in ISR The previous ble shut down and the new
ble instance does not come on nrf connect app
void ble_button_panic(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { sd_ble_gap_adv_stop(m_advertising.adv_handle); NRF_LOG_INFO("Ble Advertising start again"); ret_code_t err_code; ble_advdata_t mydata; ble_advdata_manuf_data_t manuf_specific_data; uint8_t data[] = "New!"; //data to include in the manufacturer field manuf_specific_data.data.p_data = data; manuf_specific_data.data.size = sizeof(data); manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER; // company identifier is required memset(&mydata, 0, sizeof(mydata)); mydata.flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED; mydata.p_manuf_specific_data = &manuf_specific_data; /*swap adv data buffer - from API doc: "In order to update advertising data while advertising,new advertising buffers must be provided"*/ m_adv_data.adv_data.p_data = (m_adv_data.adv_data.p_data == m_encoded_data[0]) ? m_encoded_data[1] : m_encoded_data[0]; err_code = ble_advdata_encode(&mydata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len); APP_ERROR_CHECK(err_code); err_code = sd_ble_gap_adv_set_configure(&(m_advertising.adv_handle), &m_adv_data, NULL); APP_ERROR_CHECK(err_code); }
How do I want this code to work?
1- Advertise ble every time (working)
2-On button press change payload or Advertise name (not working)