P2 BLE scan for an Argon

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.

Is the problem that it's not seeing any response from the Argon, or that it's not showing the right service or name? Is the Found debug message displayed, or is no message displayed at all?

1 Like

Hey @rickkas7! Thank you so much for your answer.

The problem is that my P2 does not find the Argon when it is scanning, as it does not find any device by that name nor by that service. The "Found" message is never displayed, always displaying "Ignoring ..."

1 Like

For anyone facing this problem:

I was able to finally fix it by returning the P2 and the Argon to my previous firmware versions:

  • 5.3.2 for the P2.
  • 4.2.0 for the Argon.

Also, although is indicated against in the documentation, the Argon needed to be in listening mode for the P2 to find it; as a side note, I can always see the Argon either in or out of listening mode with my cellphone.

In the peripheral Argon

localName = "LOREM";
BLE.setDeviceName(localName);

How did you declare the variable localName?
const char* const localName = "LOREM";

Where is BLE.on();

In the central P2
Would it not be easier to use BLEScanFilter() for both device name and ServiceUUID?

1 Like

Have in mind that any device in listening mode is NOT running your firmware.
Best

2 Likes

I came back to this thread since I recently tried to update some code to work on Photon2 that reads commerical bluetooth thermometer/hygrometers. These devices broadcast their data in the customData of their advertisements (you can also connect and get history etc.).

I could not read these advertisements on a Photon2 using deviceOS 5.7.0. I could only see a very occasional advertisement packet and the custom data was always length 0. It's strange.

I can make this work a Photon2 with 5.3.2 so I think something is broken in the advertisement handling part of deviceOS in later versions.

So with deviceOS 5.3.2 I can see advertisements from 14 devices around my desk but with 5.7.0 I can only one and it is empty.

Hi, might be related to this:

Fix coming in 5.8.0.

1 Like

Just here to confirm that 5.8.0 reads these advertisement perfectly again, and I can see the 14-15 devices that in range for BLE from this device.

Nice!

3 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.