void bleSetup() {
// Create the BLE Device
String s = String("Freenove-Dog");
BLEDevice::init(std::string(s.c_str()));
BLEDevice::setMTU(512);
// Create the BLE Server
pServer = BLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
// Create the BLE Service
BLEService *pService = pServer->createService(SERVICE_UUID);
// Create a BLE Characteristic
pTxCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_TX,
BLECharacteristic::PROPERTY_NOTIFY);
pTxCharacteristic->addDescriptor(new BLE2902());
BLECharacteristic *pRxCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_RX,
BLECharacteristic::PROPERTY_WRITE);
pRxCharacteristic->setCallbacks(new MyCallbacks());
// Start the service
pService->start();
// Start advertising
pServer->getAdvertising()->start();
Serial.println("Bluetooth initialization complete, Waiting a client connection to notify...");
}
void bleStop() {
BLEDevice::deinit();
}
void bleSend(std::string msg) {
if (isBleConnected) {
pTxCharacteristic->setValue(msg);
pTxCharacteristic->notify();
}
}