[英]Transfer Data to multiple peripheral simultaneously ios BLE
Able to connect to multiple iOS devices via Bluetooth, working as 1 master and 4 slave devices. 能够通过蓝牙连接到多个iOS设备,作为1个主设备和4个从设备。
Data transfers from central to peripheral through the following code 通过以下代码将数据从中央传输到外围设备
[peripheral.peripheral writeValue:currentData forCharacteristic:peripheral.characteristic type:CBCharacteristicWriteWithoutResponse];
But this made hugs data loss, but was faster. 但是,这可以防止数据丢失,但是速度更快。
then tried with the following code for not losing data 然后尝试使用以下代码不丢失数据
[peripheral.peripheral writeValue:currentData forCharacteristic:peripheral.characteristic type:CBCharacteristicWriteWithResponse];
Trying to transfer data to multiple peripheral at a same time (concurrently) 尝试同时(同时)将数据传输到多个外围设备
for (Peripheral * peripheral in self.connectedPeripherals) {
[peripheral.peripheral writeValue:currentData forCharacteristic:peripheral.characteristic type:CBCharacteristicWriteWithResponse];
}
Data transfers one by one it seems like a delay once 1st peripheral is received the data then 2nd peripheral gets the data and go on. 一旦第一个外设接收到数据,然后第二个外设获取数据并继续进行,数据就好像延迟了一个接一个的传送。
Want to transfer data simultaneously and reflect at same time to all the peripherals. 要同时传输数据并同时反映到所有外围设备。
When you transfer data with response, you have to wait for the acknowledgement of its receipt each time you send a packet. 当您传送带有响应的数据时,每次发送数据包时都必须等待其收据的确认。 When you transfer data without response, the acknowledgement is not being sent back, so the throughput is higher. 当您传输数据而没有响应时,不会发送回确认,因此吞吐量更高。 However, as you correctly point out, when transferring data without response there can be data loss. 但是,正如您正确指出的那样,当传输数据而没有响应时,可能会丢失数据。 This data loss happens because of the overflow of internal iOS buffer that holds the data between your call to - writeValue:forCharacteristic:type:
and its actual departure. 发生此数据丢失的原因是内部iOS缓冲区的溢出,该缓冲区保存在您对- writeValue:forCharacteristic:type:
调用与实际调用之间的数据。 If you want to prevent data loss, you can do either of the following things. 如果要防止数据丢失,可以执行以下任一操作。
- writeValue:forCharacteristic:type:
, you'll definitely face data loss. 因此,如果您有例如1 kb的数据要发送到4个外围设备,并且通过迭代调用- writeValue:forCharacteristic:type:
,则肯定会面临数据丢失的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.