Hey guys,
I want to run a peripheral BLE-Service on the nano 33 BLE Sence wich contains the temperature values of the integrated sensor, so that a central device can read them or gets notifications. Unfortunatly I constantly get an error as result, while compiling the code. The error message is in the .txt. Here is the code:#
#include <Arduino_HTS221.h>
#include <ArduinoBLE.h>
BLEService Bauteiltemperatur("19b10011-e8f2-537e-4f6c-d104768a1214");
BLEUnsignedCharCharacteristic Sensor1("19b10012-e8f2-537e-4f6c-d104768a1214" , BLERead | BLENotify);
float Temperatur1 = 0;
void setup() {
float Temperature1 = HTS.readTemperature();
Serial.begin(9600);
while(!Serial);
if(!HTS.begin()) {
Serial.println("Initialisierung des Temperatursensors fehlgeschlagen");
while(1);
}
if(!BLE.begin()) {
Serial.println("BLE-Startvorgang fehlgeschlagen");
while(1);
}
pinMode(LED_BUILTIN, OUTPUT);
Bauteiltemperatur.addCharacteristic(Sensor1);
BLE.setLocalName("Messaufbau");
BLE.setAdvertisedService(Bauteiltemperatur);
BLE.addService(Bauteiltemperatur);
Sensor1.writeValue(Temperatur1);
BLE.advertise();
Serial.println("Bluetooth-Gerät aktiv, warte auf Verbindungen...");
}
void loop() {
BLEDevice central = BLE.central();
if(central) {
Serial.print("Verbunden mit PC:");
Serial.println(central.address());
digitalWrite(LED_BUILTIN, HIGH);
while (central.connect());
updateSensor1 ();
Serial.print("Temperatur: ");
Serial.print(Temperature1);
Serial.print("°C");
delay(1000);
}
}
void updateSensor1 () {
float Temperatur1 = HTS.readTemperature ();
Serial.print("Sensor 1:")
Serial.println(Temperatur1);
Serial.print("°C");
Sensor1.writeValue(HTS.readTemperature());
}
Thank u for the help!
Error_message.txt (50.2 KB)