This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Getting hex values for entering numeric values

Hi all, I'm working on nrf52832 in segger embedded studio. Using ble scanner app, I'm entering some random values. So when i enter a value, I'm adding them to watch and checking out the value. I entered an integer value of 10, i'm expecting the same value to come in watch, but I'm getting the value as hex. For example if i enter 10, I'm getting it as 0x10.

  • This is effectively the same as what you did earlier, since it was already memset to 0. The point is that this way you do not provide any default data, but you specifies that the initial length is larger than 0. That mean you will get random/uninitialized data of whatever happens to be in memory.

    If you want to initialize all custom characteristics to (say) 0, then you could add the following snippet to your custom_value_char_add() function in ble_cus.c right before you call sd_ble_gatts_characteristic_add() (around line 154):

        // Zero-initialize the data for all. It is OK to point to the
        // same buffer for all as long as it is scaled for the largest,
        // as it is copied to the stack (BLE_GATTS_VLOC_STACK),
        #define                     MAX_LEN 45
        static uint8_t              zero_init[MAX_LEN] = {0};
        attr_char_value.p_value =   zero_init;

  • Thanks for the reply Einar.

    With your change, I am able to set the default value as zero in the custom characteristics.

    Attaching the screenshot also.

  • Hi Einar, 

    I am getting one more issue. Whenever I am doing a power cycle to the Nordic device, and I connect back using nrfConnect, all the custom characteristics are coming up as 0. 
    They are not retaining the previous values. Can you please help.

  • Of course it will lose data when power cycled!

    If you want data to be retained over  a power cycle then you will need to implement some form of non-volatile storage - and reload from that on startup.

  • Hi Awneil,

    Thanks for the reply. Is there any example application in the Nordic SDK where the data is retained using flash memory storage and provided to the custom characteristics on a power cycle.

Related