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

my bluetooth gets disconnected while sending continous stream of data

hi, i am using uart example from nrf51822 example. when i am sending continuous stream of data then my connection breaks. it disconnects from peripheral device. how should i overcome from this situation. i think i am missing some data exchange concept for sending devices based on connection interval and all different parameters.

can anyone please guide me what should i do to make connection live while sending continuous data over ble uart.

thanks!!

  • yes you are right, i am taking data as multiple of 3 byte which is a midi data. and timer i used to append data upto 20 byte because i can send maximum of 20 byte. while printing the output it gives output with correct timer value. but after connecting to device the current time gives 0 due to which no data is being appened upto 20 byte.

  • Thanks for waiting. I'm using codes from SDK 7.2 so modify the code for SDK 10.

    Also, your source files might be seperated from BLE handling parts.

    So you have to manage global variables to take care of this.

    You might have to change your sendData function too.

    The concept is quite simple. I referenced this trick from the devzone a year ago. I will post the link later if I find it.

    After you used ble_nus_string_send and successfully sends a string, on_ble_evt and

    other dispatching functions are called for the BLE_EVT_TX_COMPLETE.

    Using this feature, you can make an iterating loop to "continuously" send multiple data.

    I will give you an example below so modify it for your own.

    // global variable
    bool       m_do_nus_iteration = false;
    uint16_t m_iter = 5; // number of iteration
    // ... now suppose you called ble_nus_string_send somewhere
    void foo(void) {
                 uint32_t err_code = ble_nus_string_send(&m_nus, "Start now", 9);
                 APP_ERROR_CHECK(err_code);
                 m_do_nus_iteration = true;
    }
    

    After the string "Start now" has successfully arrived at the central device,

    your peripheral now has the BLE_EVT_TX_COMPLETE event.

    Check this sequence chart if you want more info about BLE_EVT_TX_COMPLETE.

    extern bool m_do_nus_iteration;
    // in case, your UART handling functions are at seperate source file
    
    void on_ble_evt(ble_evt_t * p_ble_evt) {
            switch (p_ble_evt->header.evt_id){
                           
                     case BLE_EVT_TX_COMPLETE: //at ble.h
                                // to distinguish whether this event happend due to ble_nus_string_send
                                if(m_do_nus_iteration) 
                                     my_nus_iter();
                                     break;
                     // for instance, I don't want this to start when I send Heart Rate Service packets
    // ...
    }
    

    Lastly, this will send ABCD 4 times. After it succeeds sending, it will send again and again.

    Hope you get the idea here.

    However, I may have made some mistakes at the my_nus_iter function, so take some inspections.

    extern uint16_t m_iter;
    extern bool       m_do_nus_iteration;
    void my_nus_iter(void) {
    
    uint32_t err_code;
    
    if(m_iter != 0) {
          err_code = ble_nus_string_send(&m_nus, "ABCD", 4);
          if (err_code == BLE_ERROR_NO_TX_BUFFERS ||
                  err_code == NRF_ERROR_INVALID_STATE ||
                  err_code == BLE_ERROR_GATTS_SYS_ATTR_MISSING) {
                  return;
    } // I experienced BLE_ERROR_NO_TX_BUFFERS at here
        
    else if (err_code != NRF_SUCCESS) {
           APP_ERROR_CHECK(err_code);
     }
    
    if(m_iter-- == 0) m_do_nus_iteration = false; // finished sending X times. So stop.
    }
    

    Hope you have understand how it works.

    A similar question like this one can be a help to you.

    Also, I wish you to reveal what caused the reset.

    // Edited, Added at 23, March, 2016

    Sorry that I cannot give you the full code you want.

    However, I believe you can makes some changes and satisfy your needs.

    I referenced this link so this will be more helpful to you.

    -Best Regards, Mango922

  • hi mango, thanks for your help. your example send data continuously. the issue i am facing is i want to send live sensor data continuously. data keeps changing each time. this example is capable of sending same data itrating. but in my case i am sending different data continuously without iteration.

    kindly guide me in that aspect.

    thanks!!

  • Hmm, I think you just have to change the packet at ble_nus_string_send at my_nus_iter function.

    Use a global variable or change the function input to get the packet you've like to send

    and I think it will be all done.

Related