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

Scan response data to be added to SDK ble_app_beacon example

How can I add scan response data to the SDK example ble_app_beacon?

Parents
  • Hi!

    The approach might vary depending on what version of the SDK you are working with.

    Maybe you could provide a little more information?

    SDK version, what device, softdevice version etc. is useful information to add in your questions.

    However, you can take a look at our advertising tutorial, and the chapter about the Scan response data.
    The tutorial is from one of the older SDK but the approach will be similiar.

    Also, the ble_app_uart example adds data to the scan reponse packet, so you can get an idea of how it's done.

    Let me know if you have any further questions.
    Best regards,
    Joakim.

     

  • I have looked into the ble_app_uart example, but I cannot find the line(s) where the scan response data is set.

    I receive

          Advertisement data:    02:01:05:0C:09:4E:6F:72:64:69:63:5F:55:41:52:54   (here at the end is Nordic_UART)

          Scan response data: 11:07:9E:CA:DC:24:0E:E5:A9:E0:93:F3:A3:B5:01:00:40:6E

    But where is the scan response data in the code?

    Thanks for your help!

Reply
  • I have looked into the ble_app_uart example, but I cannot find the line(s) where the scan response data is set.

    I receive

          Advertisement data:    02:01:05:0C:09:4E:6F:72:64:69:63:5F:55:41:52:54   (here at the end is Nordic_UART)

          Scan response data: 11:07:9E:CA:DC:24:0E:E5:A9:E0:93:F3:A3:B5:01:00:40:6E

    But where is the scan response data in the code?

    Thanks for your help!

Children
  • Hi.

    If you take a look at line 613-614 of the main.c file.

    The ble_app_uart adds the 128-bit UUID to the scan response packet.

    If you didn't already, I would suggest that you take a look at the tutorial I referred to in my previous answer.

    Best regards,
    Joakim.

  • But in that way, I can only change the bytes "01:00" at the end of the scan response data.

    For example:

    static ble_uuid_t m_adv_uuids[] =   /**< Universally unique service identifier. */
    {
    //original:    {BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}
        {0x5678, NUS_SERVICE_UUID_TYPE} //Now 78:56 in the scan response data
    };

    Where can I change the first 14 bytes? Is that a 128 bit UUID? Where is it set?

    (I looked at your tutorial, but the API's of the older SDKs are different from version 15. And the older SDKs have no support for Segger Embedded Studio)

    Thanks for your help!

  • Not sure what you are trying to acheive here?

    Do you want to change the 128-bit UUID that is already added to the BLE stack's table?

    You can take a look at the ble_advdata_t struct to see which data can be added to the scan response data.

    As an example:

    If we want to transmit the TX-power level in the scan response packet (And not the Vendor Specific UUID) of the ble_app_uart example:

    static void advertising_init(void)
    {
        uint32_t               err_code;
        ble_advertising_init_t init;
        int8_t tx_power = -4;
    
        memset(&init, 0, sizeof(init));
    
        init.advdata.name_type          = BLE_ADVDATA_FULL_NAME;
        init.advdata.include_appearance = false;
        init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
    
        //init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
        //init.srdata.uuids_complete.p_uuids  = m_adv_uuids;
        init.srdata.p_tx_power_level =  &tx_power; 
    
        init.config.ble_adv_fast_enabled  = true;
        init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
        init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;
        init.evt_handler = on_adv_evt;
    
        err_code = ble_advertising_init(&m_advertising, &init);
        APP_ERROR_CHECK(err_code);
    
        ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
    }

    Let me know if I misunderstood something or you  have further questions.

    Best regards,
    Joakim.

     

     

  • Wim said:
    Where can I change the first 14 bytes? Is that a 128 bit UUID? Where is it set?

    One of my colleagues has made custom service tutorial available on github.

    This tutorial is updated to SDK v15.0.0 and you could take a look at that to a better understanding on how the UUID is added to the BLE stack.

    Cheers.

  • Hi Joakim,

    I was looking how to program:

    - iBeacon (to be recognized by iOS)

    - with scan response data (for additional measurement or other data)

    - and connectable (to act as normal BLE peripheral)

    I succeeded (after combining your info and single stepping through some code)

    Here is my example:

    static void advertising_init(void)
    {
        uint32_t    err_code;
        uint8_t index;
        uint8_t ch_array[10];
        uint16_t major_value;
        uint16_t minor_value;
        ble_advdata_t advdata;
        ble_advdata_t srdata;
        ble_advdata_manuf_data_t manuf_specific_data;
        ble_advdata_service_data_t service_data_array;
    
        //Compose iBeacon data. Put the measurement data as major_value and minor_value
        manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER; //Apple iBeacon. Others are not recognized by iOS
        index = MAJ_VAL_OFFSET_IN_BEACON_INFO;
        m_beacon_info[index++] = 0xab;//MSB_16(major_value);
        m_beacon_info[index++] = 0xcd;//LSB_16(major_value);
        m_beacon_info[index++] = 0xef;//MSB_16(minor_value);
        m_beacon_info[index++] = MyTime; //LSB_16(minor_value);
        manuf_specific_data.data.p_data = (uint8_t *) m_beacon_info;
        manuf_specific_data.data.size   = APP_BEACON_INFO_LENGTH;
    
        // Build and set advertising data: flags, manufacturer_specific_data
        memset(&advdata, 0, sizeof(advdata));
        advdata.name_type             = BLE_ADVDATA_NO_NAME; //name will be included in scan response data
        advdata.flags                 = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
        advdata.p_manuf_specific_data = &manuf_specific_data;
    
        // Build and set scan response data: name, service_data
        memset(&srdata, 0, sizeof(srdata));
        srdata.name_type             = BLE_ADVDATA_SHORT_NAME;
        srdata.short_name_len = 3; // Advertise only first 3 letters of name
        ch_array[0] = 0; //eight interesting bytes
        ch_array[1] = 1;
        ch_array[2] = 2;
        ch_array[3] = 3;
        ch_array[4] = 4;
        ch_array[5] = 5;
        ch_array[6] = 6;
        ch_array[7] = 7;
        service_data_array.service_uuid = 0x5678; //16 bit UUID still TBD
        service_data_array.data.size = 8; 
        service_data_array.data.p_data = ch_array; 
        srdata.service_data_count = 1;
        srdata.p_service_data_array = &service_data_array;
    
        // Initialize advertising parameters (used when starting advertising).
        memset(&m_adv_params, 0, sizeof(m_adv_params));
        m_adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
        m_adv_params.p_peer_addr     = NULL;    // Undirected advertisement.
        m_adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
        m_adv_params.interval        = NON_CONNECTABLE_ADV_INTERVAL;
        m_adv_params.duration        = 0;       // Never time out.
        m_adv_params.primary_phy     = BLE_GAP_PHY_1MBPS;
        m_adv_params.duration        = APP_ADV_DURATION;
        m_adv_params.interval        = APP_ADV_INTERVAL;
    
        //First encode the advertisement data
        err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
        APP_ERROR_CHECK(err_code);
        //Now encode the scan response data
        err_code = ble_advdata_encode(&srdata, m_adv_data.scan_rsp_data.p_data, &m_adv_data.scan_rsp_data.len);
        APP_ERROR_CHECK(err_code);
    
        err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
        APP_ERROR_CHECK(err_code);
        
        nrf_gpio_pin_toggle(NRF_GPIO_PIN_MAP(0, 30));
    }
    

    Now my advertisement data is:

    02:01:06:1A:FF:59:00:02:15:01:12:23:34:45:56:67:78:89:9A:AB:BC:CD:DE:EF:F0:AB:CD:EF:00:C3

    And the scna response data is:

    0B:16:78:56:00:01:02:03:04:05:06:07:04:08:45:50:50

    I hope it can help other programmers.

    Best regards,

    Wim

Related