1

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)
    }
Rohit Bohara
  • 323
  • 4
  • 14
  • What's your connection interval on the device? In particular is it a multiple of 15ms? (If it's not, you may periodically drift out of the phone's listening window.) Check the guidelines section 41.6 for what Apple requires. https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf – Rob Napier Sep 01 '22 at 14:33
  • We read about connection parameters and how they affect the BLE connection. We learned that these parameters are set by master(iPad). A Peripheral (Rpi) could also make a request to set the parameters but the master has the final say on it and it can decided not to accept. In apple BLE api documentation, we didn't find any information to set these parameters in app (IPad). On the peripheral (RPi), we changed the parameters value by writing directly to /sys/kernel/debug/bluetooth/hci0/ files. But we have no way to know if these are accepted by master. – Rohit Bohara Sep 02 '22 at 15:18
  • We checked the BLE packets in wireshark, but didn't find a set parameter packet from master. When we tried with my Ubuntu machine, then we say parameter set request from RPi to Ubuntu – Rohit Bohara Sep 02 '22 at 15:20
  • Right, you need to send the request from the RPi. "The accessory is responsible for the connection parameters used for the Low Energy connection. The accessory should request connection parameters appropriate for its use case by sending an L2CAP Connection Parameter Update Request at the appropriate time." It sounds like you're doing that. Are the parameters as required by the linked documentation? (You do not set these in the app; you request them via the peripheral, and iOS decides the final result. The app is not involved.) – Rob Napier Sep 02 '22 at 15:36

0 Answers0