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...

Parents
  • 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

  • I got some troubles but in the end I managed to send my dynamic ADC data in manufacturer specific data ;) Thanks for your help, Anders.

    Cheers! :)

Reply Children
No Data
Related