This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to send more than 8 packets of 20bytes to ble app using notification

Hello, I am using sdk12 and uart code. I want to send my sensor data readings to ble app. For that I have modified the ble_app_uart code and I am able to send 8 packets of 20 bytes using ble_nus_string_send function. But my challenge is I am not getting more than 8 packets in the app. I think that the queue size is set to 8. Which buffer should I allocate more storage?

I am attaching my main.c New Text Document (3).txt

I have checked the error code of ble_nus_string function. It returns me success until it sends 8 packets and than it returns error after 8th packet.

Error - queueerror.PNG

Thanks, Shailav

  • Hi,

    With S132 v.3.0.0 (SDK12) you will get a BLE_ERROR_NO_TX_PACKETS error code when the buffer is full (7 packets with high BW). You have to wait for any pending packets to be sent and retry later. You can handle this in several ways. If you don’t care about wasting CPU time and current, you can just make some sort of if(returned error == BLE_ERROR_NO_TX_PACKETS) check, and simply keep trying again until the function return NRF_SUCCESS. A better approach is to use the BLE_EVT_TX_COMPLETE event, and keep track of the buffers that you can use. There are many posts about this on Devzone, here are is a list of some you can check out:

    devzone.nordicsemi.com/.../

    devzone.nordicsemi.com/.../

    devzone.nordicsemi.com/.../

    devzone.nordicsemi.com/.../


    Note that this is changed in S132 v.4.0.2 (SDK13), here the application packet concept has been replaced with a dedicated transmission queue for Handle Value Notifications. The number of Handle Value Notifications that can be queued is now configured by ble_gatts_conn_cfg_t::hvn_tx_queue_size by the application. When the queue is full, the function call will now return NRF_ERROR_RESOURCES. BLE_ERROR_NO_TX_PACKETS / BLE_ERROR_NO_TX_BUFFERS is no longer used. A BLE_GATTS_EVT_HVN_TX_COMPLETE event will be issued as soon as the transmission of the notification is complete.

  • Hi Sigurd, Where is the macro BLE_ERROR_NO_TX_BUFFERS defined? My code gives me error as undefined variable. Whats the value of this error code? I am getting error as attached above.Find the image attached above in question. Thanks, Shailav

  • From the photo you uploaded, you are getting error code value of 12292. If you convert this value to hex, the value becomes 0x3004. And 0x3004 is BLE_ERROR_NO_TX_PACKETS.

    This error code is defined in a file called ble_err.h, as

    #define BLE_ERROR_NO_TX_PACKETS          (NRF_ERROR_STK_BASE_NUM+0x004) /**< Not enough application packets available on this connection. */
    

    where NRF_ERROR_STK_BASE_NUM is defined as (0x3000) in nrf_error.h

  • Hi , I am not able to receive all data from flash. Below is my code snippet. Please suggest me changes. while(1) { for(i=0;i<20;i++) {

    		data[i] = data_flash[j]; //data= buffer to send to ble, data_flah=data stored in flash
    		NRF_LOG_INFO("%d %d %d bledata \r\n",data[i], i, j);
    			
    			nrf_delay_ms(1000);
    			j++;
    		}
    		
    
    		
        err_code = ble_nus_string_send(&m_nus, data,BLE_NUS_DATA_CHAR_LEN);
    		NRF_LOG_INFO("%d errcode \r\n",err_code);
        if (err_code != NRF_SUCCESS &&
            err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
            err_code != NRF_ERROR_INVALID_STATE &&
    err_code != (NRF_ERROR_STK_BASE_NUM+NRF_ERROR_NO_MEM)&&
      err_code != (BLE_ERROR_NO_TX_PACKETS)  //added as per your suggestions
    			)
        {
            APP_ERROR_CHECK(err_code);
        }
    
    			
    			if (i==20)
    			{
    				for(i=0;i<20;i++)
    				 {
    						data[i] = 0; //clearing data and breaking into 20 bytes
    			   }
    				
    				 i=0;
    				
    			}
    			
      }
    

    BLE EVENTS:

    case BLE_EVT_TX_COMPLETE:

    							  if(!ble_buffer_available) tx_complete = true;
            break;
    

    Thanks

  • Hi Sigurd, I have found out a problem. My mechanism was such that when I write in characteristic notification is enabled and my function call will send the data via ble. Here is code snippet

     case BLE_GATTS_EVT_WRITE:
    						if(m_nus.is_notification_enabled == true)
    						{
    					//		err_code = sd_nvic_SetPendingIRQ(DATA_SEND_IRQn);
    					//		APP_ERROR_CHECK(err_code);
    							nus_data_handler(&m_nus, data, 40);
    						}
    						           
                break;
    

    But this stops after sending 8 packets and returns me error as discussed above.

    When I call my function in for loop in main function it sends complete packets without missing any thing. So what could be possible errors while I send when user writes something to write characteristics? Thanks, Shailav

Related