I'm trying to send a float number from an Arduino MKR 1010 Wifi to my phone via BLE. I'm using the ver 20230728 of BLE Extension in Windows 10, and these are my blocks:
My phone connects to Arduino but doesn't see the service and characteristic it broadcasts: I get this error:
Service 0000aa00-0000-1000-8000-00805f9b34fb, characteristic 0000aa01-0000-1000-8000-00805f9b34fb are not published by the connected device.
My blocks seem (to me ) the same of other examples here in the forum; if I drop the CanRegisterForCharacteristic block the error doesn't occur. I installed on my phone BLE Analyser and it can read my characteristic values, so it shouldn't be a problem of Arduino.
However this is my sketch:
#include <ArduinoBLE.h>
// create a service
BLEService service("0000AA00-0000-1000-8000-00805F9B34FB");
// create a characteristic
BLEFloatCharacteristic characteristic("0000AA01-0000-1000-8000-00805F9B34FB", BLERead | BLENotify | BLEBroadcast);
// define the characteristic value (in a real environment should be given by a sensor)
float value = 0.0;
void setup() {
// serial initialization
Serial.begin(9600);
while (!Serial);
Serial.println("Serial initialized");
// Bluetooth initialization
if (!BLE.begin()) {
Serial.println("starting Bluetooth® Low Energy module failed!");
while (1);
}
// set the local name peripheral advertises
BLE.setLocalName("Ard Test"); // max 8 chars?
// set the UUID for the service this peripheral advertises
BLE.setAdvertisedService(service);
// add the characteristic to the service
service.addCharacteristic(characteristic);
// add service
BLE.addService(service);
// assign event handlers for connected, disconnected to central
BLE.setEventHandler(BLEConnected, bleCentralConnectHandler);
BLE.setEventHandler(BLEDisconnected, bleCentralDisconnectHandler);
// start advertising
BLE.advertise();
Serial. println("Start advertising");
}
void loop() {
if (BLE.connected()) {
BLE.poll();
characteristic.writeValue(value);
Serial.println("Data sent");
// only for sending a different value every time
value += 0.5;
}
delay(1000);
}
void bleCentralConnectHandler(BLEDevice central) {
// central connected event handler
Serial.println("Connected to");
Serial.println(central.localName());
}
void bleCentralDisconnectHandler(BLEDevice central) {
// central disconnected event handler
Serial.println("Disconnected from");
Serial.println(central.localName());
}
Any help is appreciated, thanks!