Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Analog data on Scan Rsp

Hi, Nordic.

I'm developing multiple peripheral and a central. Central is only scanning and Peripherals are only advertising.

I got Adv data and Scan rsp data successfully.

But, I have to get  some analog data like sensor. So, I have used rand() function and the result value put in scan rsp data.

However, this value does not change when read from the central.

I think that when the peripheral performs an advertisement, it sends an initial random value only once, and then continues to transmit that had setted format.

So, how can i do that analog value(random value) send to Central. should I use sd_radio_notification_cfg_set ??

If i have to use it, please let me know how to use it. If not, is there what kind of solution?

I using

  • SDK14.2
  • Central : ble_app_uart_c / peripheral : ble_app_beacon
  • PCA10056 (nRF52840)

I will wait for your answer. Thanks.

  • Hi,

    To change the data in the advertising data or scan respone, it must be re-encoded. Are you calling these functions multiple times? I suspect you are just calling them the first time you start advertising.

    let's say you can call sd_ble_gap_adv_start(...) with a short advertising timeout. When you get the BLE_GAP_EVT_TIMEOUT from the softdevice (remember to check if the source is advertising timeout BLE_GAP_TIMEOUT_SRC_ADVERTISING) you can do ble_advdata_set(..) and sd_ble_gap_adv_start(...) again with a new random value.

     

  • Thanks for your answer Havard.
    My peripheral is advertising and there is no timeout. m_adv_params.timeout = 0;
    what you said, If i want to get analog data every 1 second, the timeout must be 1 sec and re advertising and encode every second???

    How can i do that? It should be performed peripheral? or does it have to command the peripheral from the central??

  • yes if you want to get analog data every 1 second, the timeout must be 1 sec and re-advertising and encode every second.

    It must be performed on the peripheral.

    You must act upon the events coming from the softdevice (BLE_GAP_EVT_TIMEOUT)

    To do this you must add a softdevice handler observer in the ble_stack_init (beacon does not do this but you can look at other peripheral examples and notice how they add it).

    /**@brief Function for initializing the BLE stack.
     *
     * @details Initializes the SoftDevice and the BLE event interrupt.
     */
    static void ble_stack_init(void)
    {
        ret_code_t err_code;
    
        err_code = nrf_sdh_enable_request();
        APP_ERROR_CHECK(err_code);
    
        // Configure the BLE stack using the default settings.
        // Fetch the start address of the application RAM.
        uint32_t ram_start = 0;
        err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
        APP_ERROR_CHECK(err_code);
    
        // Enable BLE stack.
        err_code = nrf_sdh_ble_enable(&ram_start);
        APP_ERROR_CHECK(err_code);
    
        // Register a handler for BLE events.
        NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
    }

    Now you can add ble_evt_handler()

    static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
    {
        ret_code_t err_code;
    
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GAP_EVT_TIMEOUT:
                //start advertising.
            break;
            default:
                break;
        }
    }
        

  • Thank you very much.

    It is very helpful for me. Thanks again

  • You are very welcome, good luck with your project :)

Related