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

Data updating upto 241 bytes

Hello,

I have developed an application that transmits a string as a notification to the phone app whenever there is a corresponding command received from the phone app.

I actually want to send a string of size around 3KB. Now whenever I try to do that using a for loop to send chunks of 20 bytes of data at a time, the maximum number of bytes that I am able to see as notifications is 241 bytes. 

So how do I send the rest of data to the phone app?

Is this something to do with the connection interval?

If so how to solve this and send further data?

Any relevant links or details would be appreciated.

Thanks & Regards 

Sudeep R J

  • Hi Sudeep

    I recommend you divide your packets into 20-byte packets, as this is the most efficient way to transfer large amounts of data like this over BLE. Please take a look at this case, for some more pointers on the matter.

    Best regards,

    Simon

  • Hey Simonr,

    I have done that already.

    Now whatever 241 bytes i am able to receive as notifications are sent in 20 byte packets itself. I want to know how the next 241 bytes of data can be sent after sending this first 241bytes.

    whats happening is when I try to send a string of size say anythin more than 241 bytes, the first 241 bytes are sent successfully and that is notified on the nRF connect app. But the next bytes are not sent. That is the issue I am facing.

    Thank you

  • Hey Simonr,

    I clearly understood what Ole has written in case of Heart Rate Monitor and i tried the same thing but when i wrote a if condition to check for BLE_ERROR_NO_TX_BUFFERS i got an error saying this is undefined. I searched the entire project but BLE_ERROR_NO_TX_BUFFERS is nowhere to be found. should i manually add this event in the BLE_GATTS_EVT or in nus_evts ?

    I think with what Ole has described my program should work according to that. Kindly let me know how to solve this BLE_ERROR_NO_TX_BUFFERS issue.

    Thanks & Regards

    Sudeep R J

  • Hi Sudeep

    BLE_ERROR_NO_TX_BUFFERS is outdated and no longer a valid error message. To make sure there are TX buffers available in newer SDKs you can call sd_ble_gatts_hvx until you get NRF_ERROR_RESOURCES. When you get this error, wait for BLE_GATTS_EVT_HVN_TX_COMPLETE before you call sd_ble_gatts_hvx again.

    Best regards,

    Simon

  • Hi Simonr,

    I tried the NRF_ERROR_RESOURCES as you mentioned but now I am not able to receive any notifications from the TX_COMPLETE event. I am giving a command from phone app and it is it is detected as RX_DATA event and for that I have written a Hello World string which is notified and after that there is a program halt at  NRF_BREAKPOINT_COND breakpoint in app_error_weak.c. Earlier i was sending data and upto 241 bytes there was no problem. But now there is no transmission of data at all. Here is the data handler code that I have written.

    static void nus_data_handler(ble_nus_evt_t *p_evt)
    {
      
      if(p_evt->type == BLE_NUS_EVT_RX_DATA)
      {
        uint32_t err_code;
       
        static uint8_t data_array[BLE_NUS_MAX_DATA_LEN] = "Hello World";
        uint16_t length = sizeof(data_array) ;
        printf("Command Received : %d%d\n",p_evt->params.rx_data.p_data[0],p_evt->params.rx_data.p_data[1]);
        
       if(p_evt->params.rx_data.p_data[0]=='0' && p_evt->params.rx_data.p_data[1]=='2' )
       {
          err_code = ble_nus_data_send(&m_nus, data_array , &length, m_conn_handle);
          printf("data sent\n");
          if(err_code != NRF_SUCCESS)
          {
            APP_ERROR_CHECK(err_code);
         }
         
       }
      }
      if(p_evt->type == BLE_NUS_EVT_TX_RDY)
         {
           uint32_t err_code;
           uint8_t data_array1[20];  
         
           uint8_t data_array[242] = "12131415161718190471234567890101112131Heytherehowareyouhihkshuwrhibwbhvbvuewbaidhbuhwvvabhvsduverubvjhfvyuweqiqhidbqwejkfijsnoowhuiehisbfihbiqeajojqpowhijbhvbhbvwryguyhdjdieuyevuowsacihwaygbahbyfyugfrybfyrygiwhabiwfbyryi45966598kyuftd1589622k";
           
           while(1)
           {
             uint32_t k = i;
              for(uint8_t j=0;i<k+20;i++)
              {
                data_array1[j] = data_array[i];
                j++;
              }
              uint16_t length = sizeof(data_array1);
              err_code = ble_nus_data_send(&m_nus, data_array1 , &length, m_conn_handle);
              
             if(err_code == NRF_ERROR_RESOURCES)
              {
                break;
              }
              else if (err_code != NRF_SUCCESS) 
              {
                APP_ERROR_HANDLER(err_code);
              }
              
             
           }
           
           
           }
    }    

    If you could help me with any examples or documentation then that would be great.

    Thanks & Regards

    Sudeep R J

Related