I am trying to build an app that will identify all nearby BLE devices of a certain type (for example, all sensors built by one manufacturer). I'm currently running it on iPhone 13 Pro. If I include the UUID of the sensor, it finds and displays immediately, but without the UUID, most of the time it never finds the device, but it does find my tv, smartwatch, etc over and over again (despite setting { allowDuplicates: false }. In practice I can't include the UUID of the device, as every user would be trying to connect to a different sensor with a different UUID.
I have a separate script that is written specifically to find the sensor, which is successful every time, so I know the issue is not with the device.
I tried setting { allowDuplicates: true }, but that had no effect. Duplicates show whether this is set to true or false, so I'm not even sure why this is an option.
This is my function, which does successfully scan, but it doesn't find the sensor I'm looking for most of the time. I suspect that sometimes the sensor happens to be the first device found, so it gets scanned before all the other BLE devices around drown it out, but this happens less than 10% of the time.
manager.startDeviceScan(null, { allowDuplicates: false }, async (error, scannedDevice) => {
if (error) {
console.log('Error:', error);
manager.stopDeviceScan();
}
if (scannedDevice) {
if (scannedDevice.name) {
console.log('DEVICE:', scannedDevice.name);
}
}
});
};