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

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

    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

Reply Children
  • 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

  • Hi Ziv, 

    If you want to test with the ATT_MTU, I would suggest to start with the documentation. 

    But I would strongly suggest to start with the ble_app_uart. You need to study the code and get to understand how things work in the code before moving to more advanced application. 
    ble_app_blinky would also a good start. 

  • hi Hung

    If you want to test with the ATT_MTU, I would suggest to start with the documentation. 

    i have seen this link .. could not understand everything yet

    i understand it is a bit more easy to start with the Uart_ble example but i will eventually need to use the large throughput that is the ATT_MTU example and since i was not given so much time i must try to understand the ATT_MTU instead of writing the uart_ble and then change to the ATT_MTU

    i am trying to understand how to configure only peripheral for start. in the ATT_MTU example when pressing the button to get the "dummy"(responder) which to my understanding is the peripheral, there is a start advertising and start scan, if the central (tester) button is pressed there is a user choosing .. but the initiation of all the GAP GATT and so are done before all this decisions, i guess it is somehow fits to both roles,  but what configs and inits should be for peripheral configuration only and which for the central ? how can i organize that ?

    hope to read from you soon

    best regards

    Ziv

  • Hi Ziv, 

    I didn't suggest that you have to modify the ble_app_uart to make it high throughput. What I wanted to suggest is to start with simple example and get to understand how things work. 
    The ble_app_att_mtu is a bit more complex because the server is located on the central device. So the tester is both the central and the one who send data via notification. 

    The ATT table (both client and server) is setup automatically on both device, and when you press the button you only select the application activity, not the GATT attribute table. 

    If you need peripheral + server, this example could be a better option: https://github.com/NordicPlayground/nrf52-ble-image-transfer-demo

    It also comes with an Android/iOS app to test, but you need to have an Adruino camera module, or you need to modify the application to send dummy data instead. 

Related