onConnectedStateChanged not being called

hi, 

i am trying to create a datafield which connects to a indoor rowing controller. 

i am able to scan devices, and try to pair to the controller. however onConnectedStateChanged is never called. 

so far i am using a modified version of Thingy52CoinCollector. my watch is a 645M, and i am building using the sdk 4.1.1

this is what the connectiq log looks like

registerProfiles
scanning
onScanStateChange
onProfileRegister
found device: null
found device: FS-ABFEBE
found FL by Company ID
trying to pair device, rssi -45
onScanStateChange

i have also installed BleScan app, https://apps.garmin.com/en-US/apps/9bcc8b66-8385-4afb-b93e-f69e01422284

and i observed the same behaviour: the controller will be found, but if i try to pair to it, the process will timeout after 14 seconds. 

i read here in the forum that sometimes onConnectedStateChanged() is not always called, and a workaround for it would be to just check if the device is connected. unfortunately if i try 

var device = BluetoothLowEnergy.pairDevice(scanResult); then, the following returns false: 
device.isConnected() ; 
given that BleScan is presenting the same behaviour, i am beginning to think that this might be some kind of issue with the bluetooth stack of the controller (the controller is provided with a topiom rower, and it is compatible by using fitshow protocol in apps like the very same fitshow or kinomap. 
nrf connect does manage to pair the device, the callback after the pairing it is called very fast as shown in the log file
can you guys figure out what my be the problem here, or some workaround to make this work? 
  • On thing to keep in mind is that the CIQ implementation is very basic.  For example there's no security.  With the 7.0.x bonding looks like it will be available, but I've not tried it.

    I would also switch to a 6.4 SDK.  4.1.1 is really old.

    CIQ does not work with all external devices/sensors.  

    Have you watched the breakout session about BLE?  https://forums.garmin.com/developer/connect-iq/b/news-announcements/posts/adding-bluetooth-connectivity-to-your-connect-iq-projects

    Oh, Make sure you aren't already paired to your device in the watch firmware and the sensor isn't paired to something like you phone

  • Thank you Jim,

    I will give a try to the sdk update. But if blescan  app cannot pair either, I guess it will not help. I'll take a look at the video too.

    What do you mean, " Make sure you aren't already paired to your device in the watch firmware "? How can I check this?

  • The reason I wrote and published blescan was so that an external device can be checked for compatibility without wring any code.  Sounds to me like your device may need more than CIQ provides (maybe bonding or some security?)

    On some devices, things like yours can be added under "sensors and accessories", meaning it's paired in the firmware.

    blescan is actually really simple and does nothing fancy.  It scans, saves off the scan results, and if you try to connect, it just tries to pair using the associated scan result.  It knows nothing about UUID, but with something like a BLE HRM, what you see for that devices is the full UUID and not a shorter 16 bit one.  For some devices, blescan won't even show them at all

  • What happens in the sim - you need the nordic dongle or DK, but last I looked, the dongle was only about $12US.

    With the 7 SDK, it looks to me things like bonding will only be available on System 7 devices, so the 645m won't get it.

  • thanks jim, i might give the sim a go.

  • i just wanted to let you know that my issue got fixed after downgrading the sdk to version 6.4.1

    i have rebuilt with 6.4.1 and now onConnectedStateChanged is called!

    i tried this after seeing the bug report in another ticket

    https://forums.garmin.com/developer/connect-iq/f/discussion/364802/ble-sdk-v6-4-2-does-not-find-a-device-which-is-found-with-v6-4-1---need-help/1749183#1749183

    6.4.2 hat some issues in both the simulator and the edge device, while 6.4.1 was working properly. 

  • It's worth to report it in the bug report forum. They might be able to fix it before the next SDK versuon

  • The person who wrote the post above has reported this. He is not certain that it affects real devices, though. That I manage to connect might be related to something else I might have done...

  • I've been able to make a bit more progress in analyzing the issue:

    • If I restart the watch and launch the BleScan app, it detects the external device and can connect and reset the connection as many times as needed.
    • if I then launch the stock rowing app along with my data field, the log shows that the AvailableConnectionCount is 3. When I do pairDevice, I see onConnectionStateChanged. However, getService returns null, and when I unpairDevice, I no longer see onConnectionStateChanged, which should occur when disconnecting the external device. Then I exit the application.
    • Upon restarting the stock rowing app along with my data field again, AvailableConnectionCount is only 2 this time. i can still scan the external device, but I can no longer connect with pairDevice. onConnectionStateChanged does not execute.it seems it is locked from the previous step. 
    • Restarting BleScan reveals that the external device is not detected at all. not shown in screen. It's as if it remains connected to the rowing application.
    • If I turn the external device off and on (without restarting the watch), bleScan detects the device, but it fails to connect to it (times out). I have a feeling that once again, the rowing application somehow has the device blocked.

    I'm not entirely sure why unpairDevice isn't working. I'm calling it from onConnectionStateChanged when getService returns null and I want to release the external device.

    I'm also unsure why getService returns null. The UUID seems correct; it's the typical FFF0 that many devices have, and I've configured it in the profile.

    I'm making progress little by little.

    By the way, I'm using SDK 6.4.1. I haven't tried 6.4.2, but I suspect the behavior will be the same

  • how it's going ? The new SDK just released 7.2.0. I have struggling with some of your same issues. unpairDevice not calling disconnect event, i set the device, and scanresults to null after calling the unpairDevice() function. 

    I have nrf52840 Soc- with custom code, and can't see the advertising uuids after getting the scanResult, but i can list after the connection event with device.getServices() iterator. I think this may be a limitation coming from CIQ side with the 20 byte frame size. If you use and see JIM's ble scan app - you will see it can list some devices and for others cant.

    Calling the unpairDevice disconnects the BLE sensors for me.