Can't get BLE characteristic - what am I doing wrong?

I am trying to work on a SensorTag...beyond the simple key service example. I can't seem to get a characteristic associated with a service the way I would like (or any way, actually). The code below (as an example) compiles and runs fine. It finds the SensorTag when I turn advertising on. It connects to the SensorTag. It discovers attributes. It discovers the humidiyy service. The HumConCharacteristic always fails! That is the problem.

So, using either one of these:

 BLECharacteristic HumConCharacteristic = peripheral.characteristic("F000AA22-0451-4000-B000-000000000000");

BLECharacteristic HumConCharacteristic = peripheral.service("F000AA20-0451-4000-B000-000000000000").characteristic("F000AA22-0451-4000-B000-000000000000");

Always fails at:

if (!HumConCharacteristic) {
        Serial.println("Peripheral does NOT have Humidity Control characteristic!");  //<-- ALWAYS fails here
      }
      else {
        Serial.println("Peripheral has Humidity Control characteristic!");
      }

Here is the entire program:

#include <ArduinoBLE.h>
void setup() {
  Serial.begin(9600);
  while (!Serial); // wait to open the serial monitor
  // initialize the BLE hardware
  if (!BLE.begin()) {
    Serial.println("BLE Start Failed!");
    while (1); // go no further on failure
  }
  BLE.scan();
  Serial.println("*** Scanning ***");
}

void loop() {
  BLEDevice peripheral = BLE.available();

  if (peripheral) {
    // print out address, local name, and advertised service of the peripheral
    Serial.print("Found Device: ");
    if (peripheral.address() == "") {
      Serial.print(" <no advertised address> ");
    }
    else {
      Serial.print("Advertised Device Address: ");
      Serial.print(peripheral.address());
    }
    if (peripheral.localName() == "") {
      Serial.print(" <no advertised local name> ");
    }
    else {
      Serial.print(" Local Name: ");
      Serial.print(peripheral.localName());
    }

    if (peripheral.advertisedServiceUuid() == "") {
      Serial.print(" <no advertised service UUID> ");
    }
    else {
      Serial.print(" Advertised Service UUID ");
      Serial.print(peripheral.advertisedServiceUuid());
    }
    Serial.println();
    if (peripheral.localName() == "CC2650 SensorTag") {
      // stop scanning and try to connect
      BLE.stopScan();
      if ( peripheral.connect()) {
        Serial.println("Connected to SensorTag");
      }
      else {
        Serial.println("Could not connect to SensorTag");
      }

      // discover peripheral attributes
      Serial.println("Discovering attributes ...");
      if (peripheral.discoverAttributes()) {
        Serial.println("Attributes discovered");
      } else {
        Serial.println("Attribute discovery failed!");
        peripheral.disconnect();
      }

      if (peripheral.discoverService("F000AA20-0451-4000-B000-000000000000")) {
        Serial.println("Discovered humidity service");
      }
      else {
        Serial.println("Could not discover humidity service");
        peripheral.disconnect();
      }
      //BLECharacteristic HumConCharacteristic = peripheral.characteristic("F000AA22-0451-4000-B000-000000000000");  // DOES NOT WORK
      BLECharacteristic HumConCharacteristic = peripheral.service("F000AA20-0451-4000-B000-000000000000").characteristic("F000AA22-0451-4000-B000-000000000000");

      if (!HumConCharacteristic) {
        Serial.println("Peripheral does NOT have Humidity Control characteristic!");  //<-- ALWAYS fails here
      }
      else {
        Serial.println("Peripheral has Humidity Control characteristic!");
      }
      peripheral.disconnect();
      Serial.println("stop");
here: goto here;
    }
  }
}

Two other points. Using CurieBLE I am able to do something like this with success:

  if (peripheral.discoverAttributesByService("F000AA20-0451-4000-B000-000000000000")) {
    Serial.println("discovered");
    HUMConCharacteristic = peripheral.characteristic("F000AA22-0451-4000-B000-000000000000");
  }
  else  {
    Serial.println("Error: Humidity service discovery failed.");
    peripheral.disconnect();
    return;
  }

But, alas, ArduinoBLE does not have peripheral.discoverAttributesByService - what is the best way to do that?

Second, using the PeripheralExplorer example, it finds everything in the SensorTag. I have looked at that code and I have a sense for how all the services and characteristics are discovered...do I have to do all that and evaluate compare their UUIDs to get the characteristics I want??

What am I missing? Can anybody help please?

Hi @DrGee,

Can you please share the output of the peripheral explorer sketch?

But, alas, ArduinoBLE does not have peripheral.discoverAttributesByService - what is the best way to do that?

This has been renamed too peripheral.discoverService(uuid); the SensorTagButton example sketch should demonstrate it's usage.

Hi @sandeepmistry and thanks for responding.

Attached is the output for PeripheralExplorer (of course I changed the local name to if (peripheral.localName() == "CC2650 SensorTag") ). It gets everything on the SensorTag exactly as far as I can tell.

I am going to work on it some more today. I feel like I am missing something stupid, but if something else occurs to you, please let me know. -Thanks

Sensortag MK1010 Values.txt (5.19 KB)

It seems things are case sensitive, would you be able to try lower case UUID's: "f000aa22-0451-4000-b000-000000000000", it's working for me here.

Could you please open an issue on Github for this: Issues · arduino-libraries/ArduinoBLE · GitHub

Thanks.

sandeepmistry:
It seems things are case sensitive, would you be able to try lower case UUID's: "f000aa22-0451-4000-b000-000000000000", it's working for me here.

Could you please open an issue on Github for this: Issues · arduino-libraries/ArduinoBLE · GitHub

Thanks.

Yes, that is it!

peripheral.characteristic("f000aa22-0451-4000-b000-000000000000");   // WORKS
peripheral.characteristic("F000AA22-0451-4000-B000-000000000000");  // DOES NOT WORK

Thank you very much. I'm not sure when that would have occurred to me.

edited to add: Issue opened - thanks again.