jeg kan ikke då min APP til at virke, jeg kan connecte til BLE men tror ikke jeg har styr på at sende data
min kode er:
#include <ArduinoBLE.h>
BLEService ledService("b10010f2-8f22-537e-4f6c-d104768a1214"); // Bluetooth® Low Energy LED Service
BLEByteCharacteristic switchCharacteristic("b10010f2-8f22-537e-4f6c-d104768a1214", BLERead | BLEWrite);
BLEByteCharacteristic ledCharacteristic("b10010f2-8f22-537e-4f6c-d104768a1214", BLERead | BLEWrite);
const int led1 = 5;
int Rvalue; // received value from Bluetooth Application
void setup() {
Serial.begin(115200); //Baudrate
pinMode(led1, OUTPUT);
// begin initialization
if (!BLE.begin()) {
Serial.println("starting Bluetooth® Low Energy module failed!");
while (1);
}
// set advertised local name and service UUID:
//BLE.setLocalName("HOME Automation"); // this will appear in the App search result.
BLE.setLocalName("ButtonLED");
BLE.setAdvertisedService(ledService);
// add the characteristic to the service
ledService.addCharacteristic(switchCharacteristic);
// add service
BLE.addService(ledService);
// set the initial value for the characeristic:
switchCharacteristic.writeValue(0);
// start advertising
BLE.advertise();
Serial.println("BLE LED Peripheral");
}
void loop() {
// listen for Bluetooth® Low Energy peripherals to connect:
BLEDevice central = BLE.central();
// if a central is connected to peripheral:
if (central) {
Serial.print("Connected to central: ");
Serial.println(central.address());
while (central.connected()) {
if (switchCharacteristic.written()) {
Rvalue = switchCharacteristic.value(); // received value is stored in variable Rvalue.
if (Rvalue== 0) {
Serial.println(switchCharacteristic.value() );
Serial.println("Led1 OFF");
digitalWrite(led1, LOW);
}
if (Rvalue== 1){
Serial.println(switchCharacteristic.value() );
Serial.println(F("LED1 ON"));
digitalWrite(led1, HIGH);
}
}
}
// when the central disconnects, print it out:
Serial.print(F("Disconnected from central: "));
Serial.println(central.address());
}
}