Multiple Sensors - Fighting for resources on MAC OSX and Swift

edited October 2017 in General
I have two metawear sensors that I want to connect to my mac application, to read data.

I am attempting to do it as follows:

let manager = MBLMetaWearManager.shared();

...

manager.startScanForMetaWears() {   array in
    for currentDevice in array {
       currentDevice.connectAsync().success() { _ in
           // connected
       }.failure() { error in
           // failed to connect
       }
     }
     self.manager.stopScan();
}

Using this approach, I can see that a connection is attempted to be made to both of my devices. However, as soon as one connects, the other is stuck in the async method trying to connect. ( However, it never does ) Note : Yes, I can connect to each sensor individually, and retrieve the data without an issue. It is only when I try to connect to multiple that I get the resource fight for which one will be connected to first.

Am I missing something here in being able to connect to two?

I have been reading thee threads to try and solve the problem, but it seems I cannot find any more hints:



p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4f8187; background-color: #ffffff}
span.s1 {color: #ba2da2}
span.s2 {color: #000000}
span.s3 {color: #31595d}

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #31595d; background-color: #ffffff}
span.s1 {color: #4f8187}
span.s2 {color: #000000}
span.s3 {color: #ba2da2}

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff; min-height: 13.0px}
span.s1 {color: #ba2da2}
span.s2 {color: #31595d}
span.s3 {color: #008400}
span.s4 {color: #4f8187}

Comments

  • Thanks for the well documented error report.  We have been able to reproduce and are looking into it now.

    We have run into issues before with the saturating CoreBluetooth, however, it's not well documented.   We currently throttle writes on a per-device basis based on some trial/error, but it appears parallel connection requests may push that limit.

    In the mean time, if you use Bolts Tasks to do serial instead of parallel connection request, that should enable you to continue development while we get to the bottom of this.  Example code:

    var task = BFTask(result: nil)
    for currentDevice in x {
      task = task.continueOnDispatch { _ in
        return currentDevice.connectAsync().success() { _ in
          // connected
        }.failure() { error in
          // failed to connect
        }
      }
    }
  • After a few experiments, the only reliable way to do this on macOS was with serial requests.  macOS defaults to very low BLE bandwidth and it just can't support 2 devices at the same time.
This discussion has been closed.