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.