Never stops discovering second device

I'm using version 2.8.3 of the iOS SDK to discover devices (I'm testing with MetaWear C devices).  I'm using the startScanForMetaWearsAllowDuplicates method to discover available devices.  

If the scan is active and I turn on one device (by inserting the battery), it is discovered, and when I turn it off, it stops being discovered.  This is what I expect.

If I then turn on a second device, both it and the first device are discovered, even though the first device is off.  This is *not* what I expect.

If I turn the second device off, neither device is discovered.  If I turn on either device after that, both devices are again discovered, even though only one is on.  It seems like the library never forgets about any devices, once they've been seen.

Is this a bug in the library?

thanks!


Comments

  • It's correct that the library doesn't forget about a device once it has seen it.  There isn't a clear 'device turned' off indicator from the perspective of a BLE central scanning for advertisement packets.

    Couple things might help you:
    1. You can use averageRSSI property on MBLMetaWear, this is set to nil after 10 seconds of no advertisement packets reaching the apple device (reasonable default in most cases).
    2. Use the clearDiscoveredDevices method on MBLMetaWearManager to empty the cache
  • I understand that BLE doesn't give an indication that a device has been lost, but it is very counintertuitive that when my phone receives advertisements from one device, the library also notifies me about all the other devices it has ever seen, even though they are no longer advertising.  I would expect only to be notified about the devices that are actually advertising; that's how CoreBluetooth works.

    Anyway, I'll see what I can do with the clearDiscoveredDevices method.

    thanks!
    -steve
  • I found that when I call clearDiscoveredDevices, I can no longer connect to the devices that have been advertised previously.

    Checking the averageRSSI property almost works, in that it is nil for the devices that are not actually advertising.  However, if you connect to a device, and then later disconnect, the averageRSSI will always be nil for that device after disconnecting. (Is this a bug?)

    Here's what I'm trying to do... I'd like to be able to detect any advertising devices and present them in a list.  If a device stops advertising, after some amount of time, I want to remove it from the list.  In other words, the list will contain any devices for which an advertisement has been received recently.

    I'm able to do this with CoreBluetooth for other devices, and it seems like I should be able to do this with MetaWear devices through the SDK.  I guess I could use CoreBluetooth itself and watch for advertisements for MetaWear devices, but it seems like overkill.  Is there another way to do this?


  • Please check out the scanning code from our sample app.  What we implemented sounds like exactly what you want, only difference is we put an "X" for signal strength instead of removing the device from the list.

    Note that averageRSSI will be nil until you start scanning again.
  • Thanks... I figured out by comparing with the sample app that I need to stop the scan and restart it after a device disconnects; otherwise the averageRSSI will always be nil for that device.
  • Actually the real problem was that I wasn't properly disconnecting the MBLMetaWear object.  Now that I'm disconnecting, it's all working as expected.
This discussion has been closed.