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

ADC values in advertising data dynamically changing

Hello,

How to put values changing over time into advertising data? What I want to acchieve is to send ADC values that are changing dynamically over advertising packet which I wish to change over time.

I would like to know how to even send random dynamic numbers over advertising data packet. I am using nRF51822, SDK8.0.0., SoftDevice100,

PS I've seen this: devzone.nordicsemi.com/.../ but can't get the code working...

  • The link you posted contains the solution. Please explain what you mean by "Not Working". It is very hard to help you with so little information.

  • Ok, let me explain:

    • I don't know what is the "example ble_app_hrs that includes the ADC converter" that Xenia mentioned, but somehow I managed to send ADC values through HRS

    • Martin posts some code and his main.c file, but what am I supposed to do with that? Paste this, but where? Which SDK does this use? My problem is the file isn't compiling

  • First of all, i advise you to use the newest SDK (10 at this time) when creating a new project. You can download the SDK here.

    This solution includes two tasks: 1 - Getting a value from the ADC, 2- Put the value into the advertisement packet. From you question, i assume that it is part 2 you need help with.

    Start by making sure that you have enough free space in the advertisement packet. You can also consider putting the adc value in the scan response packets. If you are not familiar with these concepts, please see the advertising tutorial.

    The adc data should be put inside the manufacturer specific field of the advertisement. We create a struct containing this data:

    ble_advdata_manuf_data_t manuf_specific_data;
    

    Then we put our adc value into the struct

    manuf_specific_data.data.p_data = get_adc_value();
    manuf_specific_data.data.size  = ADC_VALUE_LENGTH;
    

    Then we put our data struct into the advertisement packet

    advdata.p_manuf_specific_data = &manuf_specific_data;
    

    Finally we set the advertisement data

    err_code = ble_advdata_set(&advdata, NULL);
    APP_ERROR_CHECK(err_code);
    

    This is in addition to all the other things we put in the advertisement packet. The total function for updating the advertisment packet might look something like this. (this is a modified advertising_init() from ble_app_hrs in SDK 10.)

    static void advertisement_update(void)
    {
        uint32_t      err_code;
        ble_advdata_t advdata;
    
        // Build advertising data struct to pass into @ref ble_advertising_init.
        memset(&advdata, 0, sizeof(advdata));
    
        advdata.name_type               = BLE_ADVDATA_FULL_NAME;
        advdata.include_appearance      = true;
        advdata.flags                   = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
        advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        advdata.uuids_complete.p_uuids  = m_adv_uuids;
    
        //New part
        ble_advdata_manuf_data_t manuf_specific_data;
        memset(&manuf_specific_data, 0, sizeof(manuf_specific_data));
        manuf_specific_data.data.p_data = get_adc_value();
        manuf_specific_data.data.size  = ADC_VALUE_LENGTH;
        advdata.p_manuf_specific_data = &manuf_specific_data;
    
        err_code = ble_advdata_set(&advdata, NULL);
        APP_ERROR_CHECK(err_code);
    }
    

    PS: The ble_app_hrs is a heart rate sensor example from our SDK. When you unzip the SDK, it is found here: \examples\ble_peripheral\ble_app_hrs

  • Hello,

    thanks for your response, Anders. I followed your advice and downloaded SDK10. 'Clean' HRS works well, but I approached few problems when trying to compile project with the code you've given! :( I listed below lines of code and corresponding errors/warnings from Keil:

    manuf_specific_data.data.p_data = get_adc_value();
    

    warning: #223-D: function "get_adc_value" declared implicitly

    error: #513: a value of type "int" cannot be assigned to an entity of type "uint8_t *"

    manuf_specific_data.data.size  = ADC_VALUE_LENGTH;
    

    error: #20: identifier "ADC_VALUE_LENGTH" is undefined

    err_code = ble_advdata_set(&m_advdata, NULL);
    

    error: #20: identifier "m_advdata" is undefined

    I hope you can help me with this and I really appreciate your efforts to date.

  • I forgot to mention that this is not code you can just paste in. You must implement get_adc_value and define ADC_VALUE_LENGTH yourself. For the last one, just change m_advdata to advdata. Have you successfully read the ADC values that should be put in here, or is this something you need help with too? This was not clear from your first question

Related