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