Nicla Sense ME BLE characteristic data not being received in BLE central device

Hello,

I have a Nicla Sense ME that I'm using to generate data and send out via Bluetooth, BLE. I'm using the sketch here: https://docs.arduino.cc/tutorials/nicla-sense-me/web-ble-dashboard

I have a second Nicla Sense ME that I want to receive the BLE data by. The second one detects the first Nicla Sense ME, but I'm failing to get the specific data sent. For example, I'm trying to acquire the accelerometer data that is sent by the first. It tells me there is no such data when I use the UUID. I'm struggling finding anywhere where it is described how I receive the data. I can't find documentation on this specific thing. There must be documentation somewhere.

I don't know how to figure this out with out documentation.

If fails in the controls() function where I have this line in the code below::

BLECharacteristic accelerometerCharacteristic = peripheral.characteristic(BLE_SENSE_UUID("5001"));

So, it finds the peripheral service, but not this particular characteristic.

The code in the central BLE is here:

#include <ArduinoBLE.h>

#define BLE_SENSE_UUID(val) ("19b10000-" val "-537e-4f6c-d104768a1214")

//BLE_SENSE_UUID("5001") // for the accelerometer, three floats

//BLEService niclaService(BLE_SENSE_UUID("0000"))
//BLECharacteristic accelerometerCharacteristic(BLE_SENSE_UUID("5001"), BLERead | BLEWrite, 3 * sizeof(float));  // Array of 3x 2 Bytes, XY

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while (!Serial);

  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting Bluetooth® Low Energy module failed!");

    while (1);
  }

  Serial.println("Bluetooth® Low Energy Central - Peripheral Explorer");

  // start scanning for peripherals
  // BLE.scan();
  BLE.scanForUuid(BLE_SENSE_UUID("0000"));
}

void loop() { 
 // check if a peripheral has been discovered
  BLEDevice peripheral = BLE.available();

  if(peripheral){

      //How do I match addresses?
    // stop scanning
    BLE.stopScan();

    controls(peripheral);
    // peripheral disconnected, start scanning again
    BLE.scanForUuid(BLE_SENSE_UUID("0000"));
  }


}

void controls(BLEDevice peripheral)
{
  // connect to the peripheral
  Serial.println("Connecting ...");

  if (peripheral.connect()) {
    Serial.println("Connected");
  } else {
    Serial.println("Failed to connect!");
    return;
  }
 // THE CODE FAILS TO RETURN THIS CHARACTERISTIC:
  BLECharacteristic accelerometerCharacteristic = peripheral.characteristic(BLE_SENSE_UUID("5001"));

  
  if (!accelerometerCharacteristic) {
    Serial.println("Peripheral does not have accelerometer characteristic!");
    peripheral.disconnect();
    return;
  }

  while(peripheral.connected())
  {
    float x, y, z;
    float accelerometerValues[3];

    x = accelerometerValues[0];
    y = accelerometerValues[1];
    z = accelerometerValues[2];
    accelerometerCharacteristic.readValue(accelerometerValues, sizeof(accelerometerValues));
    Serial.println("accelerometer: x: " + String(x,3) + String(" y:") + String(y,3) + String(" z:") + String(z,3));
  }

  Serial.println("Peripheral disconnected");
}

Thanks for any help!
...John

An update...

I am able to identify the accelerometer characteristic via the UUID. It's received, however the data is zero. I can successfully get the temperature characteristic, which is sent as a float value. The accelerometer is three float values.

Is there any good documentation for this stuff, because so far everything has been trial and error.

Try this modification with using the address operator

accelerometerCharacteristic.readValue(&accelerometerValues, sizeof(accelerometerValues));

1 Like

Thanks for the reply, cattledog!

It didn't work. But I'm using the address of an array of floats, so I think that should work.

What I'm finding is that when I use
characteristic.valueLength() for the accelerometer, it is always returning zero, instead of 12, which it should be for three floats. I know that's what it is on the sending end.

On the sending side I see this

if (accelerometerCharacteristic.subscribed()){
        float x, y, z;
        x = accelerometer.x();
        y = accelerometer.y();
        z = accelerometer.z();

        float accelerometerValues[] = {x, y, z};
        accelerometerCharacteristic.writeValue(accelerometerValues, sizeof(accelerometerValues));
      }

Have you subscribed to the characteristic?

characteristic.subscribe();

In some code I used, it was in a discover attributes section, which I don't see in your code.

1 Like

Thanks. I think you are right. I did try subscribing earlier and still wasn't getting the data, even though I noticed that it was streaming from the peripheral.

I was finally able to get the data by removing the subscribe condition on the peripheral. I don't know why that worked, but maybe I have to play with it. At least it now captures the data.

I'll likely set it up without characteristic subscription, since I don't need it that finally tuned. :slight_smile:

Give a try to this new testing app BlueDashBy Sparkleo, It may help