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.

  • Hello Laura
    There is state when sometime sensor goes into unknown state and it stop downloading data from sensor. We are not able to find the state when it is doing that. Can you please let me know how we can know that it is in unknown state.

  • @Rakesh64587,
    Have you been able to fix this?

  • No, please let me know how we can fix this?

  • Can you send replicable steps and code in .txt file?

  • Hello Laura
    Please find .txt file attached for the steps for live streaming and issue mentioned in .txt file. Please check and let me know is there anything else we need to do.

  • Hello Laura
    There is another issue coming while downloading data from sensors. I have attached .txt file for the steps to download data from multiple sensors. Sometime download callback functions are not called and we get stuck in between. Please check attached .txt file and let me know what is the issue for this.

  • Hello @Laura
    It's been too long, there is no response. Please let us know it's very urgent.

  • Hi @Rakesh64587

    Those are complicated bits of code, it would not be possible to debug without fully loading up your application. I would suggest simplifying the use case to see which operations cause the issue to appear.

    I can say from looking at the code that I would not recommend calling mbl_mw_debug_reset(this.foreArmDevice.board) immediately after reading out the log. This is a forced reset, which will interrupt log memory garbage collection, and possibly the final log readout handshaking.

Sign In or Register to comment.