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

nrf52840 BLE peripheral connection for data transfer managing

Hello Nordic

 

I am using nrf52840, SDK 16.0,

I wish to implement Ble peripheral that advertise a connection request (if no response from central after x seconds then I go to sleep and try few minutes later). After connection has established I need to manage data transfer to the central gateway (also nrf52840)

  1. Is there an example that I can learn from as for how to manage a connection (only connection, not pairing etc.) ?
  2. Also since most examples are written in an event driven way which is great but really hard to flow the code since breakpoints tend to crash the app, is there some explanation somewhere or guide/tutorials for peripheral connection for data of various sizes ?
  3. Starting to play with the peripheral ble_app_blinky I saw that if I try to change the advertise timeout I stop seeing the advertise in the nrf connect cellphone application, why is that ?

 

#define APP_ADV_DURATION                30//BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED   /**< The advertising time-out (in units of seconds). When set to 0, we will never time out. */

hope to read from you soon

best regards

Ziv

  • Hi Ziv, 

    1. I would suggest to have a look at the ble_app_uart example. In the example we show cased how you can handle a BLE connection without using peer_manager library. However I would strongly suggest you to use peer_manager in your application. You can choose not to support pairing with peer_manager if you want. 

    2. Base your application on ble_app_uart would be the best option for you. 

    3. When you change APP_ADV_DURATION to 30 it will advertise in only 300ms. The   adv_params.duration  unit is 10ms not 1s as in the comment (please have a look at the ble_gap_adv_params_t struct in ble_gap.h) . I have reported this bug earlier but we haven't got it fixed yet. 

  • hi Hung

    When you change APP_ADV_DURATION to 30 it will advertise in only 300ms.

    i also tried with 3000 instead of 30 cause i thought there might be an issue there, it also did not work 

    In the example we show cased how you can handle a BLE connection without using peer_manager library.

    when reading the explanation for that example it is written "peer" all the time so i don't really understand,

    also there is something more basic that i don't get from the example: 

    to my understanding, if i am the peripheral, then first i broadcast myself, then the central can respond to my broadcast and we initiate a connection.

    in which function i get indication that a connection was established, is the broadcast timeout includes the time it takes to establish the connection, or there is a different timeout for that ?

    who enables the Notifications which to my understanding enables data transfer, is it the central or the peripheral ? 

    if the central is the one who enables the notification, how do i know that the notification is enabled, and what happens if i try to send data via "ble_nus_data_send(...)" (if this is indeed the right function to use?) when the notifications is not enabled ?

    hope to read from you soon

    best regards

    Ziv

  • hi Hung

    sorry for verifying and un verifying, just clicked the wrong place.. anyway

    beside the previouse reply i wonder, after looking intosome examples including the ble_uart_app, i am looking for a way to send data from my application, without using nus, there is no need for uart implementation in my peripheralm also looked at other examples it seems each service has it's own send function type, i am looking for general byte array kindof, data transfre.. is there some function like that or an example that demonstrate data transmit over ble from a peripheral ?

    2. in the app_ble_uart example, i tryied to change the filtering to a device name .. like so :

    /// ziv start
    static char const m_target_periph_name[] = "Audio_sensor";
    //// ziv end
    /**@brief Function for initializing the scanning and setting the filters.
     */
    static void scan_init(void)
    {
        ret_code_t          err_code;
        nrf_ble_scan_init_t init_scan;
    
        memset(&init_scan, 0, sizeof(init_scan));
    
        init_scan.connect_if_match = true;
        init_scan.conn_cfg_tag     = APP_BLE_CONN_CFG_TAG;
    
        err_code = nrf_ble_scan_init(&m_scan, &init_scan, scan_evt_handler);
        APP_ERROR_CHECK(err_code);
    /// ziv start
    //    err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_UUID_FILTER, &m_nus_uuid);
    //    APP_ERROR_CHECK(err_code);
    //
    //    err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_UUID_FILTER, false);
    //    APP_ERROR_CHECK(err_code);
    /// ziv start
        err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name); // TBD - what to do with the m_nus_uuid, what should replace it 
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_ble_scan_filters_enable(&m_scan, NRF_BLE_SCAN_NAME_FILTER, false);
        APP_ERROR_CHECK(err_code);
    //// ziv end
    }
    

    and it fails, for some reason i can't get a read of the err type on the " err_code = nrf_ble_scan_filter_set(&m_scan, SCAN_NAME_FILTER, m_target_periph_name); "

    any ideas ?

    hope to read from you soon

    best regards

    Ziv

  • Hi Ziv, 

    ble_app_uart and ble_app_uart_c should be a good place to start for you. 

    Please also get familiar to how to debug the application. You would need to compile the application without optimization in order to have debug information. 

    "peer" in "peer_manager" means the peripheral or central that connect to the device. 
    When a connection is established you will receive event: BLE_GAP_EVT_CONNECTED, please have a look at the ble_evt_handler() function. 

    We have some tutorials about BLE that you may want to have a look: devzone.nordicsemi.com/.../bluetooth-low-energy

  • hi Hung 

    sorry but it seems like you did not see all my questions .. 

    i have seen those tutorials, didn't go over them thoroughly, but in any way i did not see any of them relate to a simple way to transmit data, not by nus function or hrs, etc. specific function but just data transfer

    tried to go over the ATT_MTU example cause i will need to transfer a large amount of data with high throughput but could not really find or understood how it knows if it is peripheral or central and in general how to work with it.. any help or explanation on that will be most welcome 

    hope to read from you soon

    best regards

    Ziv

Related