Why Connect IQ Device Simulator (nRF52 DK) always return null for device.getService(uuid) ?

My environment:

Windows 10

Eclipse Version: 2020-12 (4.18.0)

Connect IQ Device Simulator 3.2.5 (Connect IQ application is developed for Forerunner 945; Target API Level 3.2.x)

nRF52 DK (flashed with memory layout from this link https://developer.garmin.com/downloads/connect-iq/connectivity_2.0.1_115k2_with_s132_5.0.zip)

Snippet of code:

---start

    // After pairing a device this will be called after the connection is made.
    // ---
    // device — (BluetoothLowEnergy.Device) — The device state that was changed.
    // state  — (Lang.Number)               — A BluetoothLowEnergy.CONNECTION_STATE_* inicating the state of the connection.
    // ---
    function onConnectedStateChanged(device, state) {
        var myService;
        var ch;
        var desc;
        
        myDevice = device;
    
        System.println("ble:onConnectedStateChanged " + myDevice + " " + connectionStateToString(state));
        
        if (state == Ble.CONNECTION_STATE_CONNECTED) {
            if (myDevice == null) {
                System.println("device is not connected");
                return;
            }
           
            System.println("0");
            var services = myDevice.getServices();
            for (var service = services.next(); service != null; service = services.next()) {
                System.println(service.getUuid().toString());
            }
            
            myService = myDevice.getService(Ble.stringToUuid("0000180f-0000-1000-8000-00805f9b34fb")); // 0000180f-0000-1000-8000-00805f9b34fb is UUID for battery service
            System.println("1");
            if (myService == null) {
                System.println("myService is null");
            } else { // this else block of code is now irrelevant
                ch = myService.getCharacteristic(tempAndHumidityCharacteristicUuid);
                System.println("2");
                desc = ch.getDescriptor(Ble.cccdUuid());
                System.println("3");
                desc.requestWrite([value & 0x01, 0x00]b);
                System.println("4");
            }
        } else {
            System.println("other state");
            connected = false;
        }
    }

---end

Note: real device I am not tried, important now for me is Simulator with flashed nRF52 DK

Thanks for your any help.

  • I flash my device with ATC/ATC_MiThermometer it looks much better... in sim pairing is ok but not in real watch fr945.

    I used your BleScan app on my fr945 watch and connection/pairing there is not ok -> not connected - still "orange" and after 15s "white" displayed data again.

    My question:

    Are some general specifications for external Ble devices so that it can be successfully connected (example on Ble packets/bytes/bits)?

  • I've used CIQ Ble with  a number of sensors and Garmins.  HRMs, Raspberry Pi's, ESP32s, etc. In my blog about the pi, there is sample code for both ends which may help.  What you see in CIQ is a bit limited, at least partly for security reasons.  You won't see the MAC address for the sensor, as an example, and some things are limited in size. You amy or may not see the devices anme or primary UUID  With BleScan, you can see the raw data in the advertisement by pressing "start".  I don't think I've ever seen more than about 30 bytes as raw data, and often less..

    It's only been a week or two that I've been using an ESP32.  I started with some sample code, that used 3 different sensors itself.  Temperature, pressure, and light.  I wanted to skip those and use a 1wire temperature sensor to make things a bit simpler.  I also wanted to make it compatible with my CIQ apps that use a pi, so I used the same UUIDs and data format for both reads and notifies,.  Worked with nRFConnect and I could see things just fine (the intent of the sample code was to make the data available on a phone).  But it didn't work with the sim or a real device.  Turns out I had to debug what was happening on the ESP32.  It now works with the sim and real devices, but getting data seems to be a bit slower in the sim and sometimes fails.  I can connect to it fine using BleScan in both the sim and real device.

    Sounds to me like you need to take a hard look at what your sensor is doing.  Does it see the connection/pairing attempt?  How does it respond?