BLE onScanResult how to compare the uuids against a fix service value

Hi developers,

I would need some help, as I am fighting since 2 days on a simple problem.

I used the Nordic BLE example:

https://github.com/fabiobaltieri/ciq-nrf-blinky

as a template for my BLE project.

Now I run into the problem, that the device name is not reported by BLE scan result. This is a known issue in the SDK:

 https://forums.garmin.com/developer/connect-iq/i/bug-reports/connect-iq-ble-advertising-layer-parsing-bug-prevent-many-devices-to-function-properly-paired-or-not-paired-toybox-bluetoothlowenergy-scanresult-getrawdata-getservicedata-getserviceuuids-are-broken

As a workaround I want to compare the UUID instead of the device name in my project, as the UUID is found in the BLE scan correctly.

=> But how to compare the UUID provided via getServiceUuids() against a fix value?

Sounds simple, tried many times with printf debugging (log), no solution found.

Some code snippets:

	function initialize() {
		SERVICE = Ble.stringToUuid("19067010-db9e-4075-a5b5-e6df36619906");
		READ_CHAR = Ble.stringToUuid("19067011-db9e-4075-a5b5-e6df36619906");
		READ_DESC = Ble.cccdUuid();
		WRITE_CHAR = Ble.stringToUuid("19067012-db9e-4075-a5b5-e6df36619906");
		SCAN_TIMEOUT = 5;
		RESCAN_DELAY = 10;

		BleDevice.initialize();
	}
	
	function onScanResults(scanResults) {
		debug("scan results");
		var appearance, name, rssi, rawdata;
		var mfg, uuids, service;
		for (var result = scanResults.next(); result != null; result = scanResults.next()) {
			if (result instanceof Ble.ScanResult) {
				appearance = result.getAppearance();
				name = result.getDeviceName();
				rssi = result.getRssi();
				mfg = result.getManufacturerSpecificDataIterator();
				uuids = result.getServiceUuids();
				rawdata = result.getRawData();

				debug("device: appearance: " + appearance + " name: " + name + " rssi: " + rssi);
				debug("result raw: " + rawdata);

				debug("Vor matchDevice");
				if (matchDevice(name, mfg, uuids)) {
				//if (appearance==4660) {
					connect(result);
					return;
				}
			}
		}
	}
	
	protected function matchDevice(name, mfg, uuids) {
		//dumpUuids(uuids);
		//dumpUuids(UUID_COMPARE);
		//dumpMfg(mfg);

		// if (name != null && (
		// 	name.equals(DEVICE_NAME) ||
		// 	name.equals(DEVICE_NAME_Z))) {
		// 	return true;
		// }
		var uuidString = uuids.String;

		debug("SERVICE: " + SERVICE);
		debug("uuidString: " + uuidString);

		if (uuids.equals(SERVICE)) {
			debug("matchDevice: Found");
			return true;
		}
		debug("matchDevice: NOT Found");
		return false;
	}
	

Main question is on line 53 the does not work....

Thanks for support.

Best Regards Sven

  • it's already uuid, the problem is that you compare an array with an uuid, that will never be equal

    Do you have a proposal how to do it better?

    I introduced now some debug logs:

    	private function dumpUuids(iter) {
    		for (x = iter.next(); x != null; x = iter.next()) {
    			debug("uuid: " + x);
    		}
    	}

    This show up the correct UUID in the log:

    [ble] uuid: 19067010-DB9E-4075-A5B5-E6DF36619906

    compared to

    The log for SERVICE (debug("SERVICE: " + SERVICE);) shows same:

    [ble] SERVICE: 19067010-DB9E-4075-A5B5-E6DF36619906

    So maybe I need a loop to compare each element?

    General: Sorry for my nested comments. Will do it now better using the quote function in the chat....

  • yes. Or try contains as Jim recommended

  • I wrote BLEScan in the sim before I even tried it on a device, and it works today with win11 and the 7.1.0 sim, 1.0.11 extention with no problems.

    I'd say there is something wrong with your setup.  Try just putting the println in "contains" I keep mentioning as you should see every device that CIQ BLE can see with a 1 line change to the sample.

  • I'm telling you it doesn't work. My problem is not about understanding basic programming or debugging. It's either hardware or firmware related. I'm not 100% confident that firmware was written out or that what was written out is what was suppoed to be written (meaning maybe I should've used another hex file)

    BTW with the dongle I only have Write in the programmer. No Erase & write. Is that how it's supposed to be?

    Also, after flushing the ROM, should I keep it in the USB port, or should I remove it, then reattach?

    If I remove and reattach then it's not blinking any more.

  • if you're having problems flashing the dongle, have you checked on the nordic site and the nRFConnect desktop app?  Seems this works for other people on macs unless every using this for the last 4 years was on windows.

    There is no "erase" for the dongle.  It's always been that way.  I flashed the dongle a couple  times this week, it takes about 20 seconds, and unplugging/replugging the dongle make it available in the sim

    You can always just test with sideloads to your watch.  It may take longer but it works

  • With the nRFConnect Desktop have you triedrunning this app?


    It flashes it's own code and the app let's you see what the dongle can see when scanning.  That way you can make sure your dongle works.

    You need to re-flash the hex file for CIQ when you're done.

    Here's an example for what I see with that app:

  • Sorry, I was lost, but now I found the "contains" function in the other project. Seems this is exactly what I need. Seems this also just a loop. So I will give this a try tomorrow.

    Maybe to add: My device is a ESP32 SOC with Arduino, not a Nordic. I do all printf debugging via logs on the real device which is time consuming in iterations. I never came to the idea, that it is possible to use the simulator. So just for right understanding: If I follow:

    https://forums.garmin.com/developer/connect-iq/w/wiki/19/getting-started-with-connect-iq-ble-development

    with the NRF Dongle I will be able to have a real BLE device connection available in the Connect IQ simulator?

  • Yes..With the dongle you can test in the sim.  At the breakout when this was announced, Nordic handled out a dongle, a Dk and a Thingy52, so I've been using the sim for years.

  • Yes that works.

    I managed to make it work now on my old mac, but not the new. I still think that it's some problem with the simulator (maybe more than one). It works now with SDK 6.4.2, and 7.1.1 but it didn't.

    This is what I did: I started the simulator, then made sure the correct port was set. (It was), but still nothing.

    Then I changed the port to a filename that doesn't exist (got the error popup)

    Then I changed it back to the correct port, and then it started to work.

    Looks like for some reason it doesn't work when I start the simulator with the port already set correctly.

    Also while I was trying I got the simulator crash more than 10 times with both sdk versions (and it still crashes on the new mac (which I use nowadays, I only tried it with the old to see if that makes any difference), every time I run either of the two Nordic apps).

    Now I just need to find how to make it work with the new mac.

  • Hi jim_m_58 and flocsy

    thanks for your inputs. I had now success on two points. I found an old NRF Dongle and flashed it with the BLE IQ connect firmware. So now I am able to use the simulator with real BLE devices. This is really great and makes life easier. Second the  "contains" function from the sample project works on my side too!

    So this issue can be closed!

    Finaly maybe for other developers the short description for the workaround:

    If the Name of your BLE device will not show up on scanResults you should search for your device via UUIDs.

    As a template how to implement this you should take a look to the "contains" function in the following project:

    https://forums.garmin.com/developer/connect-iq/b/news-announcements/posts/would-you-like-some-raspberry-pi-with-your-connect-iq

    Thanks a lot for support.

    Best Regards Sven