Hello! First of all, I've been using Particle devices for over 6+ years and they're great. Also, I've never written here before, so, please forgive me if this has already been asked or if I'm missing some forum rules.
My latest project is to have a P2 as a central BLE device giving orders to an Argon in a peripheral role. Both devices are on 5.7.0.
I have problems with the P2 scanning for the Argon, as it never finds it, neither by it's name nor by a serviceUuid. I know the Argon is advertising successfully because I see it with an app on my phone, and I can connect to it and read it's characteristics.
This is the code in my P2 to scan:
Vector<BleScanResult> scanResults = BLE.scan();
if (scanResults.size()) {
Serial.printlnf("BLE devices found: %d ", scanResults.size());
BleUuid serviceUuid("6D456DD8-C0D1-4A86-92F3-DBB87D17A6B8");
for (int ii = 0; ii < scanResults.size(); ii++) {
BleUuid foundServiceUuid;
size_t svcCount = scanResults[ii].advertisingData().serviceUUID(&foundServiceUuid, 1);
String advertisedName = scanResults[ii].advertisingData().deviceName();
String responseName = scanResults[ii].scanResponse().deviceName();
bool foundService = svcCount > 0 && foundServiceUuid == serviceUuid;
bool foundName = advertisedName.indexOf("LOREM") > -1 || responseName.indexOf("LOREM") > -1 || advertisedName.indexOf("Argon") > -1 || responseName.indexOf("Argon") > -1;
if (!foundService && !foundName) {
Serial.printlnf(
"Ignoring: %02X:%02X:%02X:%02X:%02X:%02X | signal: %d",
scanResults[ii].address()[0], scanResults[ii].address()[1], scanResults[ii].address()[2],
scanResults[ii].address()[3], scanResults[ii].address()[4], scanResults[ii].address()[5],
scanResults[ii].rssi()
);
} else {
Serial.printlnf("Found: %02X:%02X:%02X:%02X:%02X:%02X | signal: %d",
scanResults[ii].address()[0], scanResults[ii].address()[1], scanResults[ii].address()[2],
scanResults[ii].address()[3], scanResults[ii].address()[4], scanResults[ii].address()[5],
scanResults[ii].rssi()
);
}
}
}
And this is, roughly, the code that I'm using to advertise in my Argon:
BleAdvertisingData adv;
const char* serviceUuid = "6D456DD8-C0D1-4A86-92F3-DBB87D17A6B8";
const char* characteristicUuid = "6D456DD4-C0D1-4A86-92F3-DBB87D17A6B8";
BleUuid service(serviceUuid);
BleCharacteristic characteristic(
"loremIpsum",
BleCharacteristicProperty::READ,
characteristicUuid,
serviceUuid
);
localName = "LOREM";
BLE.setDeviceName(localName);
BLE.addCharacteristic(characteristic);
adv.appendServiceUUID(service);
BLE.advertise(&adv);
Do you see any problems? Am I missing something?
Thank you in advance for your help, it would be greatly appreciated.