When i upload this code on my ESP32 S3 for using ble it works with nrf connect app but it doesnt work with serial bluetooth terminal app ?
#include <Arduino.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
BLEServer *pServer = NULL;
BLECharacteristic *pCharacteristic = NULL;
bool deviceConnected = false;
class MyServerCallbacks : public BLEServerCallbacks {
public:
void onConnect(BLEServer* pServer) {
deviceConnected = true;
}
void onDisconnect(BLEServer* pServer) {
deviceConnected = false;
}
};
class MyCallbacks : public BLECharacteristicCallbacks {
public:
void onWrite(BLECharacteristic *pCharacteristic) {
std::string value = pCharacteristic->getValue();
if (!value.empty()) {
Serial.print("Received command over BLE: ");
Serial.println(value.c_str());
} else {
Serial.println("Empty value received over BLE");
}
}
};
void setup() {
Serial.begin(115200);
Serial.println("Starting BLE Server...");
BLEDevice::init("ESP32-S3 BLE Server");
pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
BLEService *pService = pServer->createService(BLEUUID((uint16_t)0x180A)); // Generic Attribute Profile (GATT)
pCharacteristic = pService->createCharacteristic(
BLEUUID((uint16_t)0x2A23), // Characteristic UUID for System ID
BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE
);
pCharacteristic->setValue("ESP32-S3"); // Set a static system ID
pCharacteristic->setCallbacks(new MyCallbacks());
// Optional: Add descriptor for notifications
// BLE2902 *pDescriptor = new BLE2902();
// pCharacteristic->addDescriptor(pDescriptor);
pService->start();
BLEAdvertising *pAdvertising = pServer->getAdvertising();
pAdvertising->start();
Serial.println("BLE Server started");
}
void loop() {
// Handle other tasks if needed
delay(1000);
}