This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Dynamic updating of serial number in device ID

Ole, I am trying to update the serial number value in an already initialized standard Device ID profile. [i]dis_init.serial_num_str.length = (uint16_t)strlen(newserial); dis_init.serial_num_str.p_str = (uint8_t *)newserial; err_code = ble_dis_update(&dis_init);[/i]

and this [i]uint32_t ble_dis_update(const ble_dis_init_t * p_dis_init){ uint32_t err_code;

if (p_dis_init->serial_num_str.length > 0) {
    err_code = char_add(BLE_UUID_SERIAL_NUMBER_STRING_CHAR,
                        p_dis_init->serial_num_str.p_str, 
                        p_dis_init->serial_num_str.length,
                        &p_dis_init->dis_attr_md,
                        &serial_num_handles);
    if (err_code != NRF_SUCCESS) {
        return err_code;
    }
}
return NRF_SUCCESS;

}[/i] And while nothing throws an error, it also doesn't update the value. Any ideas?

Another option I have here is to use a soft reset to start the system over again, and I may have a use for that anyway, so I have search through a the documentation but I cant seem to find a way to force a reset. Is inline with a jump to the reset vector the only way, or is there something a little more elegant?

  • I'm having a little trouble understanding this code snippet. To update an existing characteristic, you should make sure to use sd_ble_gatts_value_set(), which require you to have the handle of the characteristic you want to set. Without having tested, I'd therefore suggest a method something like this

    
    uint32_t ble_dis_serial_num_update(char * serial_num_string, uint8_t length)
    {
        return sd_ble_gatts_value_set(serial_num_handles.value_handle, 0, length, serial_num_string);
    }
    
    

    Also, you should be aware that you can't add a characteristic to a service if other services have been added in the mean time. Any attribute added will always be added to the last service added, no matter what you set the service_handle to in the sd_ble_gatts_characteristic_add() function. This is a limitation with the current GATT Table implementation in the S110.

    Edit: To also answer the second part, you can use NVIC_SystemReset() or sd_nvic_SystemReset(), depending on whether the softdevice is enabled or not.

  • Ok, so that is the problem then.... as to the second half of my question, is there a good way to reset the 51822 from software?

  • Sorry, overlooked that part. I've edited my answer above to cover that as well. If you found that my reply answered your question, I'd also be happy if you could click the "Accept as answer" button below it, to clear up this question. :)

Related