Problem reading value from a Nano 33 BLE Sense

Hello,
Being a beginner with Arduino, I try my few sketches, and I am currently facing a problem when trying to read a dummy value sent through bluetooth. Here is the sketch adapted from a LED example:

#include <ArduinoBLE.h>

BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service

BLEByteCharacteristic fooCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite );


const int ledPin = LED_BUILTIN; // pin to use for the LED

void setup() {
  Serial.begin(9600);
  while (!Serial);

  // set LED pin to output mode
  pinMode(ledPin, OUTPUT);

  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");

    while (1);
  }

  // set advertised local name and service UUID:
  BLE.setLocalName("LED");
  BLE.setAdvertisedService(ledService);

  // add the characteristic to the service
  ledService.addCharacteristic(fooCharacteristic);

  // add service
  BLE.addService(ledService);
  
  // start advertising
  BLE.advertise();

  Serial.println("BLE LED Peripheral");
}

void loop() {
  // listen for BLE peripherals to connect:
  BLEDevice central = BLE.central();
  float testfloat = 3.14152;
  
  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());
    
    // while the central is still connected to peripheral:
    while (central.connected()) {
      fooCharacteristic.writeValue((byte)testfloat);
    }

    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }
}

With this on the device, I can connect with gatttool on linux.

hms@joe:~/projects/arduino$ gatttool -I
[                 ][LE]> connect fc:57:4a:cb:ea:2e
Attempting to connect to fc:57:4a:cb:ea:2e
Connection successful
[fc:57:4a:cb:ea:2e][LE]> char-read-uuid 19B10001-E8F2-537E-4F6C-D104768A1214
Error: Read characteristics by UUID failed: Attribute PDU was invalid
[fc:57:4a:cb:ea:2e][LE]>

And so there is this error:

Error: Read characteristics by UUID failed: Attribute PDU was invalid

I can connect with LightBlue from Android, read a value, but it appears that the hex on binary value that is read does not correspond to the value that is written by the device.
What am I doing wrong here? Can it be a problem with my laptop (and me being dumb at reading the value on LightBlue)?
Thanks for yout help!

Welcome to the forum

hms4242:
I can connect with LightBlue from Android, read a value, but it appears that the hex on binary value that is read does not correspond to the value that is written by the device.

I read 0x03. Using LightBlue and BLE Scanner on iOS. What value do you get/expect?

hms4242:
What am I doing wrong here? Can it be a problem with my laptop ...

Do you have any other software trying to access BLE at the same time e.g. Node-RED?
Do you have another BLE device that you can try to access with gatttool? Just to check that it is working as you expect it.

In case you did not find it. There are two a Nano 33 BLE specific sub-boards.

Nano Boards (NEW types)

Hi and thank you for your reply. I did not notice there was a Nano specific sub board, sorry for posting that here.

I tried various values and LightBlue seems to read the result correctly apart from the fact that it does not recognize the type of transfered data. I have no idea if it should guess it correctly though. But translating written values from one type to another tells me that the value is the one that is written from the Nano board.

So i tried to read values from other machines (raspberries) using gatttool the same way as described above, and this lead to the exact same error. I will try to mimic another ble device from one of these raspberries and see if the result is the same from my laptop.

Again, thank you for your answer.

hms4242:
I did not notice there was a Nano specific sub board, sorry for posting that here.

No need to be sorry. You can post here as well. But you will find more information in the other sub board because it is device specific.

hms4242:
I tried various values and LightBlue seems to read the result correctly apart from the fact that it does not recognize the type of transfered data. I have no idea if it should guess it correctly though.

Every BLE app is slightly different. Most UUIDs are not recognized and decoded in most apps, so they show raw data. But some apps decode a few known UUIDs when you also have the data structure correct.

Thank you for your reply, I will try to post on the Nano specific sub-board.