Hey im currently developing an App which is connecting to a BLE device and reading values from it quite frequently. I want the Value to be updated every 200ms, this is working perfectly fine on an Android Device but for some reason we have a strange delay on iOS.
In the didUpdateValueFor
Function we can clearly see in the log files that we are receiving all sended packets, but for some reason it will receive 5-6 at once, then make a short break and then continue again. This will lead to a strange result which feels like a 0.5s delay on updating our Labels. Anyone has an Idea where the Problem could be?
didUpdateValueFor Code:
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
print("update \(NSDate().timeIntervalSince1970)")
if(characteristic.value != nil) {
let characteristicValue = characteristic.value!
let ASCIIstring = NSString(data: characteristicValue, encoding: String.Encoding.utf8.rawValue)
if(ASCIIstring != ""){
DispatchQueue.main.async {
self.setPositionData(values: ASCIIstring! as String)
}
}
}
}
CentralManager Code:
centralManager.scanForPeripherals(withServices: [BLEHelper.raspberryBLECBUUID], options: nil)
didDiscover Code:
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
print("did discover")
print(peripheral)
centralManager.stopScan()
bleHelper.raspberryPeriphal = peripheral
centralManager.connect(bleHelper.raspberryPeriphal, options: nil)
}