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

BLE_NUS_C how to send pkt from client to service with efficient and reliable?

In my situation, I want to use bluetooth to designed a piconet which has 1 master and up to 4 slave.
With yours suggestion,Now i make it work,in upload from slave to master(per slave upload rate is 2.2KB/s)

https://devzone.nordicsemi.com/f/nordic-q-a/59367/how-about-capobility-of-52832-in-rate-delay-distance-amount-of-slave-in-piconet

But,i confused by download.In this communication direction,maybe >4 packets/s to each slave,each packet length less than 200B. Default,in ble_nus_c_string_send, i use BLE_GATT_OP_WRITE_CMD as a param pass to sd_ble_gattc_write.There appeared serious packet loss even short distance of master and slave.

Then i try use BLE_GATT_OP_WRITE_REQ,which support reliable write.And check return of ble_nus_c_string_send_req:

uint32_t ble_nus_c_string_send_req(ble_nus_c_t * p_ble_nus_c, uint8_t * p_string, uint16_t length)
{
    VERIFY_PARAM_NOT_NULL(p_ble_nus_c);

    nrf_ble_gq_req_t write_req;

    memset(&write_req, 0, sizeof(nrf_ble_gq_req_t));

    if (length > BLE_NUS_MAX_DATA_LEN)
    {
        NRF_LOG_WARNING("Content too long.");
        return NRF_ERROR_INVALID_PARAM;
    }
    if (p_ble_nus_c->conn_handle == BLE_CONN_HANDLE_INVALID)
    {
        NRF_LOG_WARNING("Connection handle invalid.");
        return NRF_ERROR_INVALID_STATE;
    }

    write_req.type                        = NRF_BLE_GQ_REQ_GATTC_WRITE;
    write_req.error_handler.cb            = gatt_error_handler;
    write_req.error_handler.p_ctx         = p_ble_nus_c;
    write_req.params.gattc_write.handle   = p_ble_nus_c->handles.nus_rx_handle;
    write_req.params.gattc_write.len      = length;
    write_req.params.gattc_write.offset   = 0;
    write_req.params.gattc_write.p_value  = p_string;
    write_req.params.gattc_write.write_op = BLE_GATT_OP_WRITE_REQ;//BLE_GATT_OP_WRITE_CMD;//无需回复的发送方式
    write_req.params.gattc_write.flags    = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE;

    return nrf_ble_gq_item_add(p_ble_nus_c->p_gatt_queue, &write_req, p_ble_nus_c->conn_handle);
}

if not return NRF_SUCCESS, it will try send several times(such as 100,as far as possible to reliable send).In this way,packet sent to slave is more reliable ,but the effective send rate seem is too low,maybe less than 100B/s for each slave。(PS:upload 2KB/s from slave is continuous running,when some packets download from master to slave )

Is there any way to improve it?

Make an efficient and reliable channel to send packet from master to slave.

Parents
  • Hi,

    How do you detect the packet loss ?

    Are you using a custom board, or a nRF52832-DK in your test ?

    As long as the sd_ble_gattc_write() returns NRF_SUCESS, the packet will be delivered to the server.

    When transferring data with a write request from GATT client, then only one packet is sent every other connection event. This is because ATT level acknowledgement must be received for a sent packet before sending another packet. The procedure is as follows:

    • Connection event x: Send writeRequest packet
    • Connection event x+1: Receive ATT acknowledgement packet
    • Connection event x+2: Send writeRequest packet
    • Connection event x+3: Receive ATT acknowledgement packet

    and so on. So with connection interval 7.5ms, then one packet can be sent every 15ms, therefore substantially limiting throughput.

    But with Write Command packet you can send multiple packets each connection interval, and you will therefore get much higher throughput with Write Command.

  • First of all,Thanks for your reply!

    1、I detect the packet loss by sending packet with one byte for sequence.Each packet will increase 1.In the slave,judge wheather sequence is continuous or not.

    2、I understand throughput with write request is lower than write cmd.but how low?less than 500B/s for each slave?

    3、Slave upload seem more reliable, even though throughput with 2KB/s.but slaves were bought from other company,I am not sure it used write request or write cmd.wheather some params I set in master are not proper.Or it is different from master(central) and slave(peripheral),that is the ultimate performance for master send packet to slave.

Reply
  • First of all,Thanks for your reply!

    1、I detect the packet loss by sending packet with one byte for sequence.Each packet will increase 1.In the slave,judge wheather sequence is continuous or not.

    2、I understand throughput with write request is lower than write cmd.but how low?less than 500B/s for each slave?

    3、Slave upload seem more reliable, even though throughput with 2KB/s.but slaves were bought from other company,I am not sure it used write request or write cmd.wheather some params I set in master are not proper.Or it is different from master(central) and slave(peripheral),that is the ultimate performance for master send packet to slave.

Children
No Data
Related