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

NRF52832 - advertising data

About this example

https://github.com/NordicPlayground/nrf51-ble-tutorial-advertising

It´s advertising the data

 uint8_t                     data_response[] = "Many_bytes_of_data" with the MAC and RSSI 

without connection.

How can advertising dynamic data without connection ?

For example, MAC, RSSI + some dynamic data ?

Is there some SES example ? 

Thanks

Parents
  • Hi.

    You can do this by using two data buffers, so that you avoid re-using an active buffer, because that is not allowed by sd_ble_gap_adv_set_configure().

    If you use SDK 15.2, you can take a look at ble_advertising_advdata_update(), which can be used to update the advertising data. The update will be effective even if the advertising has already been started.

    ret_code_t ble_advertising_advdata_update(ble_advertising_t  * const p_advertising,
                                              ble_gap_adv_data_t * const p_new_advdata_buf,
                                              bool                       permanent)
    {
        if (permanent)
        {
            memcpy(&p_advertising->adv_data, p_new_advdata_buf, sizeof(p_advertising->adv_data));
            p_advertising->p_adv_data = &p_advertising->adv_data;
        }
        else
        {
            p_advertising->p_adv_data = p_new_advdata_buf;
        }
    
        return sd_ble_gap_adv_set_configure(&p_advertising->adv_handle,
                                            p_advertising->p_adv_data,
                                            NULL);
    }

    If permanent is set to true, the advertising data will be permanently updated inside the module. Otherwise, the previous advertising data will be restored when there is a transition to the next advertising mode.

    - Andreas

  • thanks for fast reply

    in my code advertising_init()  i can successfully advertising manufacturer data_response[]

    but in

    static void Set_AdvData()
    {
    ret_code_t ret_code;
    static ble_gap_adv_data_t new_data;

    ret_code = ble_advertising_advdata_update(&m_advertising, &new_data, true);
    }

    wich are the parameters to me update the data_response[] ?

    static void advertising_init(void)
    {
        uint32_t      err_code;
        ble_advdata_t advdata;
        uint8_t       flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;
    
        ble_advdata_manuf_data_t manuf_specific_data;
    
        manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
    
        // Prepare the scan response manufacturer specific data packet
        ble_advdata_manuf_data_t  manuf_data_response;
        uint8_t                     data_response[] = {0x06,0x48,0x41};
        manuf_specific_data.company_identifier  = 0x0059;
        manuf_specific_data.data.p_data         = data_response;
        manuf_specific_data.data.size           = sizeof(data_response);
        
        // Build and set advertising data.
        memset(&advdata, 0, sizeof(advdata));
    
        advdata.name_type             = BLE_ADVDATA_NO_NAME;
        advdata.flags                 = flags;
        advdata.p_manuf_specific_data = &manuf_specific_data;
    
        // 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_NONCONNECTABLE_NONSCANNABLE_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.
    
        err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_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);
    }

Reply
  • thanks for fast reply

    in my code advertising_init()  i can successfully advertising manufacturer data_response[]

    but in

    static void Set_AdvData()
    {
    ret_code_t ret_code;
    static ble_gap_adv_data_t new_data;

    ret_code = ble_advertising_advdata_update(&m_advertising, &new_data, true);
    }

    wich are the parameters to me update the data_response[] ?

    static void advertising_init(void)
    {
        uint32_t      err_code;
        ble_advdata_t advdata;
        uint8_t       flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;
    
        ble_advdata_manuf_data_t manuf_specific_data;
    
        manuf_specific_data.company_identifier = APP_COMPANY_IDENTIFIER;
    
        // Prepare the scan response manufacturer specific data packet
        ble_advdata_manuf_data_t  manuf_data_response;
        uint8_t                     data_response[] = {0x06,0x48,0x41};
        manuf_specific_data.company_identifier  = 0x0059;
        manuf_specific_data.data.p_data         = data_response;
        manuf_specific_data.data.size           = sizeof(data_response);
        
        // Build and set advertising data.
        memset(&advdata, 0, sizeof(advdata));
    
        advdata.name_type             = BLE_ADVDATA_NO_NAME;
        advdata.flags                 = flags;
        advdata.p_manuf_specific_data = &manuf_specific_data;
    
        // 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_NONCONNECTABLE_NONSCANNABLE_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.
    
        err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_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);
    }

Children
No Data
Related