Disconnected sensors automatically after sometime iOS

I am creating app with two sensors. I am using sensors simultaneously for live streaming but after some time one of sensor got disconnected automatically even app is not in background. So we lost data in between and live streaming got stuck.
Please let me what is issue? Is this with iOS SDK or iPhone or sensor?

I am using iOS version 13.5.1, iphone XR.
Installed pod of SDK using this command "pod "MetaWear", :subspecs => ['UI', 'AsyncUtils', 'Mocks', 'DFU']"
Using C++ functions to get data from sensors for live streaming with swift language.

If anything else required please let me.

Below is the code that I am using for live streaming:-

upperArm is name of sensor Metawear

    upperArm.connectAndSetup().continueWith { t in

        t.result?.continueWith { t in
           // self.upperArm.clearAndReset()
            print("Upper Arm disconnected")

// self.upperArm.connectAndSetup().continueWith(.mainThread) { t in
// }
// self.upperArmDataStreaming()
// DispatchQueue.main.async {
// if let scene = self.scene{
// scene.updateUpperArmAngle()
// }
// }

        if let error = t.error {
            mbl_mw_sensor_fusion_enable_data(self.upperArm?.board, MBL_MW_SENSOR_FUSION_DATA_CORRECTED_ACC);
        } else {

            mbl_mw_sensor_fusion_set_acc_range(self.upperArm?.board, MBL_MW_SENSOR_FUSION_ACC_RANGE_16G)
            mbl_mw_sensor_fusion_set_gyro_range(self.upperArm?.board, MBL_MW_SENSOR_FUSION_GYRO_RANGE_2000DPS)

            self.correctedAccerlationUpperArm = mbl_mw_sensor_fusion_get_data_signal(self.upperArm?.board, MBL_MW_SENSOR_FUSION_DATA_CORRECTED_ACC)

            mbl_mw_datasignal_subscribe(self.correctedAccerlationUpperArm, bridge(obj: self)) { (context, data) in
                guard let _ = context else{return}

                let this: CalibrateViewController = bridge(ptr: context!)

                guard let _ = this.correctedAccerlationUpperArm else{return}
                DispatchQueue.main.async {
                    this.upperArmOnOffLabel.text = "On"
                let dateFormatter = DateFormatter()
                dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
                dateFormatter.calendar = NSCalendar.current
                dateFormatter.timeZone = TimeZone.current
                if let datax = data?.pointee{
                    let obj: MblMwCorrectedCartesianFloat = datax.valueAs()
                    this.upperArmY = obj.y + this.upperArmCalibration

                    this.upperArmX = obj.x
                    //var upperArmAngle = acos(this.upperArmY)
                    var upperArmAngle = atan2(-obj.x, -obj.y)
                    upperArmAngle = upperArmAngle.isNaN ? 0 : upperArmAngle
                    this.Yup = (upperArmAngle * 180) / .pi

                    //print((upperArmAngle * 180) / .pi)
                    //Check up angle for upper arm
                    if this.Yup > -120 && this.Yup < 0{
                        this.upperArmFlag = true
                    //if values are less than 0 then it will rotate whole hand so only when upperArmAngle is greater than 0 then update upper arm angle
                    DispatchQueue.main.async {
                        if this.isCalibrateEnabled{
                            //Stop Arm moving in oposite direction
                            //&& ((upperArmAngle * 180) / .pi < -90 )
                            if upperArmAngle < 0 {
                                if upperArmAngle < -1.50{
                                    if let scene = this.scene{
                                        scene.updateUpperArmAngle(CGFloat(upperArmAngle) * 2)


                                if let scene = this.scene{

            mbl_mw_sensor_fusion_enable_data(self.upperArm?.board, MBL_MW_SENSOR_FUSION_DATA_CORRECTED_ACC);



  • Do you have code that can automatically reconnect in case the Bluetooth drops?
    Bluetooth isn't guaranteed so you have to handle sudden disconnects.

    Also make sure that your phone doesn't turn off or send the app into the background (then you will lose Bluetooth as per iOS guidelines).

  • It gets disconnected after some time again and again even app is in foreground mode. So in between this time data is lost for that time period. After disconnection it reconnects automatically. Sometime it gets disconnected after long time. Please let me know is this sensor issue or iPhone?. Because we need constant connection so we do not loss data.

Sign In or Register to comment.