Advertising doesn't change name after code update

Greetings,

I've been developing a DFU firmware that should update the device through Android. The thing is, the device works, but I changed the advertising name, and it still shows the old name when I try to update the device. I use the following function to update the name:

static void make_dev_name(void)
{
    ble_gap_addr_t device_address;
    uint8_t companyName[] = {"M"};
    uint8_t modelName[] = {"1"};
    uint8_t *macAddressName;
    uint8_t macTmp[12];

    sd_ble_gap_addr_get(&device_address);
    macAddressName = Convert_Hex_To_Ascii(&device_address.addr[0], 4);
    memcpy(&DEVICE_NAME[0], companyName, 1);
    memcpy(&DEVICE_NAME[1], modelName, 1);
    memcpy(&DEVICE_NAME[2], macAddressName, 12);

}

Any idea why this issue occurs?

I used reference from here;
https://novelbits.io/ota-device-firmware-update-part-3/

Parents
  • Hello,

    When is make_dev_name() called, is it only on startup, or are you sending a command over BLE to update the name? 

    Best regards,

    Vidar

  • Only on start-up.

    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();
    
        //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);
            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();
    
        }
    }

  • Thanks for sharing the code. But I'm not seeing any obvious errors in this implementation. Does the device advertise with the expected name if you load the application FW with your debugger? Also, are you sure the previous device name has not been cached by your phone? 

  • The device does not advertise with the expected name, it advertises with its' previous name e.g. M0...

    We also tried with a different phone that has never been connected to the device, but it still shows the previous name.

  • Strange. I replaced the code in the ble_app_uart example in SDK 17.1.0 with your main.c file (also removed the buttonless DFU features) to attempt to reproduce the problem, but I see the full name:

    Can you place a breakpoint at the idle_state_handle() and inspect the DEVICE_NAME array to see if it is initialized correctly?

  • Unfortunately, I can't debug it because the initial setup wasn't made in Segger. Instead, I'm trying to see what UART is giving me. I will post what when I have some results.

  • It's possible to use other tools such as GDB or Segger Ozone to debug the app if the project was built without an IDE.

Reply Children
Related