How to send 25 packets of data each second

I am not able to send 25 array packets each second. array size is 244 bytes

I am reading the sensor data continuosly and every 40 ms i am sending the data to bluetooth using gatt_notify

Each second the receiver receiving different number of packets 

1st second 24 packets
2nd second 25 packets 
3rd second 23 packets like wise Receiver receiving the data 

every second 25 packets are not receiving 


Please help on this 

Thank you in advance

Parents Reply Children
  • Devices can agree on what MTU they can use. Im checking it using code bellow. Ive not tried setting it manually as this fits my purpose. I then use that negotiatedMTU as size of the packet sent via notify. 

    void exchange_mtu_result(struct bt_conn* conn, uint8_t err, struct bt_gatt_exchange_params* params) {
      if (err)
        printErr("MTU exchange failed (Error: %d)", err);
      else {
        negotiated_MTU = bt_gatt_get_mtu(conn) - 4; // INFO negotiated MTU is reduced by 4 as 3 bytes are ATT and 1 for null termination
      }
    }
    
    BT_CONN_CB_DEFINE(conn_callbacks) = {
      .connected           = connected,
      .disconnected        = disconnected,
      .le_param_req        = param_req,
      .le_param_updated    = param_updated,
      .le_phy_updated      = phy_updated,
      .le_data_len_updated = data_length_updated
    };

    MTU : 494 bytes
  • In documentation and L2CAP_TX_MTU, it is showing that we can update upto 251 bytes only

    At a time i can send 494 bytes of array to receiver? 

    In my application i want to send 6000 bytes of array with in one second so this is not possible thats why every 40 ms i am sending 240  bytes of array 


  • Hi 

    It's true that the L2CAP_TX_MTU is not limited to 251 bytes, but the data length is:

    config BT_CTLR_DATA_LENGTH_MAX
    	int "Maximum data length supported"
    	depends on BT_CTLR_DATA_LENGTH
    	default BT_BUF_ACL_RX_SIZE if BT_BUF_ACL_RX_SIZE < 251
    	default 27
    	range 27 BT_BUF_ACL_RX_SIZE if BT_BUF_ACL_RX_SIZE < 251
    	range 27 251
    	help
    	  Set the maximum data length of PDU supported in the Controller.

    Once you send packets longer than this they will have to be segmented by the link layer, and the throughput will suffer as a result. The ideal situation is to negotiate a 251 byte data length, and send data packets of 244 bytes (leaving 7 bytes for the L2CAP and ATT headers). 

    I am reading the sensor data continuosly and every 40 ms i am sending the data to bluetooth using gatt_notify

    Rather than sending the packets every 40ms I would recommend sending them as fast as possible, then you will be able to more efficiently fill the buffers in the Bluetooth stack, which will increase overall throughput. 

    Best regards
    Torbjørn

Related