Greetings,
I want to change Device name on Advertising. Is that possible?
I am using nrfSDk52832, I want when some state of Switch is change, to change advertising name dynamically .
Here is my code:
static void make_dev_name(void)
{
ble_gap_addr_t device_address;
uint8_t companyName[] = {"S"};
uint8_t modelName[] = {"1"};
uint8_t *macAddressName;
uint8_t macTmp[12]; // macTmp[8];
uint8_t switchState[2] = {0,0};
uint8_t *switchHex;
if(nrf_gpio_pin_read(HANDLE_SIG)) switchState[0] = 1;
if(nrf_gpio_pin_read(LOCK_SIG)) switchState[0] += 2;
if(nrf_gpio_pin_read(RESET_SW)) switchState[0] += 4;
if(nrf_gpio_pin_read(LATCH_SIG)) switchState[0] += 8;
if(nrf_gpio_pin_read(MOT_SIG)) switchState[1] = 1;
if(nrf_gpio_pin_read(BLE1)) switchState[1] += 2;
if(nrf_gpio_pin_read(BLE2)) switchState[1] += 4;
uint8_t pomX = switchState[0];
if(pomX > 9)
{
pomX += 55;
}
if(pomX < 10)
{
pomX += 0x30;
}
switchState[0] = pomX;
pomX = switchState[1];
if(pomX > 9)
{
pomX += 55;
}
if(pomX < 10)
{
pomX += 0x30;
}
switchState[1] = pomX;
sd_ble_gap_addr_get(&device_address);
macAddressName = Convert_Hex_To_Ascii(&device_address.addr[0], 6);
memcpy(&DEVICE_NAME[0], companyName, 1); //3);
memcpy(&DEVICE_NAME[1], modelName, 1); //3);
memcpy(&DEVICE_NAME[2], macAddressName, 12); //8);
memcpy(&DEVICE_NAME[14], switchState, 2); //8);
}
Also here is my int main
*/
int main(void)
{
bool erase_bonds;
ret_code_t err_code;
ble_gap_addr_t device_address;
// Comment this for new modules
sd_power_dcdc_mode_set(1);
// Initialize.
uart_init();
log_init();
// Initialize the async SVCI interface to bootloader before any interrupts are enabled.
//err_code = ble_dfu_buttonless_async_svci_init();
APP_ERROR_CHECK(err_code);
timers_init();
buttons_leds_init(&erase_bonds);
power_management_init();
ble_stack_init();
make_dev_name();
gap_params_init();
gatt_init();
services_init();
advertising_init();
conn_params_init();
peer_manager_init();
//if(nrf_gpio_pin_read(WAKEUP_IN_PIN))
//{
// while(1); // wait here
//}
sd_ble_gap_addr_get(&device_address);
nrf_delay_ms(5);
while(!nrf_gpio_pin_read(WAKEUP_IN_PIN))
{
//nrf_gpio_pin_clear(UART_TX_NOTIFY);
//nrf_delay_ms(250);
//nrf_gpio_pin_set(UART_TX_NOTIFY);
// Sends 6 bytes
for(int i=0; i<6; i++)
{
do
{
err_code = app_uart_put(device_address.addr[i]);
if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
{
NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
APP_ERROR_CHECK(err_code);
}
} while (err_code == NRF_ERROR_BUSY);
}
//nrf_delay_ms(500);
nrf_delay_ms(50);
}
// Start execution.
//printf("\r\nApplication started.\r\n");
NRF_LOG_INFO("Debug logging for UART over RTT started.");
while(app_uart_tx_done());
app_uart_close();
advertising_start();
wdt_init();
// Enter main loop.
for (;;)
{
// Feed the watchdog
feed_dog();
// Power management
idle_state_handle();
}
}
Do I need adv_update?
For example this code only work, if i pressed Switch before i programmed, and it stay like that, when i reprogrammed it with another pressed switch it changed but only first time.
I want it this change on running mode(advertising).
Thank you !