Closed paxsipornax closed 3 years ago
You have to restart advertising in onDisconnect()
.
İçinde reklam vermeye yeniden başlamalısınız
onDisconnect()
.
void onDisconnect(BLEServer* pServer) { deviceConnected = false;
pServer->getAdvertising()->start();
}
};
it worked, it worked thanks 👍
include
include
include
include
BLECharacteristic *pCharacteristic; bool deviceConnected = false;
define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
define CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
class MyServerCallbacks: public BLEServerCallbacks { void onConnect(BLEServer* pServer) { deviceConnected = true; };
void onDisconnect(BLEServer* pServer) { deviceConnected = false; } };
class MyCallbacks: public BLECharacteristicCallbacks { void onWrite(BLECharacteristic *pCharacteristic) { std::string rxValue = pCharacteristic->getValue();
if (rxValue.length() > 0) { Serial.println("*****"); Serial.print("Received Value: ");
} }
};
void setup() { Serial.begin(115200);
BLEDevice::init("ESP32 UART Test");
BLEServer *pServer = BLEDevice::createServer(); pServer->setCallbacks(new MyServerCallbacks());
BLEService *pService = pServer->createService(SERVICE_UUID);
pCharacteristic = pService->createCharacteristic( CHARACTERISTIC_UUID_TX, BLECharacteristic::PROPERTY_NOTIFY );
pCharacteristic->addDescriptor(new BLE2902());
BLECharacteristic *pCharacteristic = pService->createCharacteristic( CHARACTERISTIC_UUID_RX, BLECharacteristic::PROPERTY_WRITE );
pCharacteristic->setCallbacks(new MyCallbacks());
pService->start();
pServer->getAdvertising()->start();
}
void loop() { if (deviceConnected) {
} delay(1000); }