BLE & problems while learning

I've just started playing with the BLE code, and come across a couple of things which have caused me problems so far. I thought I'd mention them here in case I'm doing something wrong, or they shouldn't happen or maybe it will help someone else:

  •  I thought I'd start off with the easiest uuid (or so I thought haha!) - so I set out to use the generic access, and get the device name ...
    • So service uuid = 00001800-0000-1000-8000-00805f9b34fb
    • Characteristic uuid = 00002a00-0000-1000-8000-00805f9b34fb
  • Running this in the simulator works fine to register the profile, but as soon as I try on my watch it crashes. No stack trace or anything. Just "Error: System Error" and "Details: Profile Registration Unhandled Error". Eventually I get around to trying a different (random-ish) uuid and of course that works fine ... So I'm guessing it is just the generic access one that doesn't work - maybe because the system code is using it itself in some way? (as device name is returned in scan results?)
  • A second problem that didn't help, is that in the simulator when I call BluetoothLowEnergy.registerProfile() then onProfileRegister() in the delegate is not called, making it hard to check the code. Again it turns out that running on my watch it works differently, and onProfileRegister() is actually called correctly.
  • You are limited to 3 ble profiles, if three are available See getAvailableConnectionCount.

  • I didn't try multiple connections at all in my code - just trying to keep it simple Slight smile The getPairedDevices() function returns an iterator so I assume there can be more than one paired device, but I didn't even try finding out the value of getAvailableConnectionCount() on my watch to see what the maximum was (I'm not sure if that is a maximum? If it can vary by device? If it can vary over time depending on what else your device is doing, e.g other BLE apps? Is it a limit per app or over all apps? Or if it is just the current number of paired devices?)

    And a paired device sometimes seems able to last beyond the end of your app (data field in my case) if you don't unpair it when exiting. When testing then sometimes it seemed like I could exit and restart the activity and the paired device was still there.

    Which makes me wonder … if another app on the Garmin device is also using BLE then will my own app see devices paired by the other app when I call getPairedDevices() ? If it can then I definitely have a bug to fix!!

    I did notice when connecting to my Shimano e-bike via the EW-EN100 that if my Edge 1030 was already connected to it (via ANT+) then when I connected my watch via BLE then the Edge disconnected (until I disconnected my watch again). So I assume the EW-EN100 can only handle one connection at a time on it's end.

  • I've used up to three profiles at the same time, but all are for the same device.  Some sensors use two-3 profiles.

    ANT and BLE seem to be completely separate for at least some things where you can pair to a watch with ant and a phone with BLE for example.

  • I was using 3 profiles for the same device - but I only connected to one device at a time.

    Could my watch (a Fenix 5X+) actually connect to two devices at the same time (using all 3 profiles for each) ? I've only got one e-bike here so it's something I haven't been able to test.

    I guess I'm not sure what the value returned by getAvailableConnectionCount() actually represents ...

  • I've not tried but it looks to be 3 profiles per app, not per device.  It would have to be different apps.  When you try to register the 4th, an error gets thrown.

  • So for an example, if I only registered 1 profile at app startup. Then how many devices can I connect to & pair with at the same time? Is that what getAvailableConnectionCount() specifies?

  • I would guess "more than one" if it was the same type of device and had the same profile..

    What numbers do you see with getAvailableConnectionCount? It may be for the overall device (BT is used for a number of things outside CIQ).  Maybe I'll give it a try later.

    update: ran a quick test and in both the sim and on a devices, it starts at 3 and drops to 2 when a device is paired.

  • I see getAvailableConnectionCount =3 when the app starts. After i connect to BLE device it becomes 2. Using Fenix 5 plus in simulator.

  • Yes, looks like you can pair 3 devices, and I know the limit is 3 profiles, so 3 devices that share the same profiles, or 3 devices with one profile each is how it looks.

  • Aha nice, that is making sense now Slight smile

    So I imagine the maximum starting value for getAvailableConnectionCount could vary between different Garmin devices (although I'd guess it is 3 for all of them currently). Opens some interesting possibilities though.

    If you can have 2 CIQ datafields active at once (and maybe some other background tasks), then now I wonder if they are each allowed 3 connections, or if the 3 connections are shared. Although if they were shared it would be tricky if you went to connect and suddenly found another app had stolen the last slot!