I want to see Text data from esp32 via BLE.
''' ESP32 code
class MyCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
String receivedData = pCharacteristic->getValue().c_str();
Serial.print("Received data: ");
Serial.println(receivedData);
sendSerialToBLE("Received data: ");
sendSerialToBLEln(receivedData);
}
}
void sendSerialToBLE(String data) {
if (deviceConnected) { // BLE 연결 상태 확인
pCharacteristic->setValue(data.c_str()); // BLE 특성에 데이터 설정
pCharacteristic->notify(); // BLE 데이터 송신
}
}
void sendSerialToBLEln(String data) {
if (deviceConnected) {
data += "\n"; // 줄바꿈 추가
pCharacteristic->setValue(data.c_str());
pCharacteristic->notify();
}
}
void setup(){
BLEDevice::init("ESP32_S3_BLE");
BLEServer *pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
BLEService *pService = pServer->createService(SERVICE_UUID);
pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE |
BLECharacteristic::PROPERTY_NOTIFY
);
pCharacteristic->setCallbacks(new MyCallbacks());
pCharacteristic->addDescriptor(new BLE2902());
pCharacteristic->setValue("Hello from ESP32-S3!");
pService->start();
pServer->getAdvertising()->start();
Serial.println("BLE advertising started...");
}
I used blocks 'when BLE.StringReceived' and 'set Textbox.Text to stringValues'
In the Textbox, there is no data changed