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

  • With my blescan app, you'll see for ,many things, you don't see the device name when scanning.  I don't see it in CIQ for the Raspberry Pi apps I use with Garmin for example (the sample you linked to).

    One where I do see the name is the HRM-PRO, but there I wouldn't want to use the name, but the Common UUID for BLE HRM's as I can use other HRM's than the HRM-PRO.

  • Something else that can be handy based on what your app does, is you can skip scanning and always connect to the same sensor after the first time, by saving the good scan result in Application.Storage.  When you next want to connect to that device, don't scan, but instead use the saved scan result and just use that to pair.

    for my real garage door control, I do just that, as I have a second pi I use to test which could be advertising, and when I'm in the car, I always want to connect to the real one and not the test pi.

    I've not looked at the bonding stuff for System 7 devices