#include "BluetoothService.h"
// See the following for generating UUIDs:
// https://www.uuidgenerator.net/
#define SERVICE_UUID "0000ffe0-0000-1000-8000-00805f9b34fb" // UART service UUID
#define CHARACTERISTIC_UUID_RX "0000ffe1-0000-1000-8000-00805f9b34fb"
#define CHARACTERISTIC_UUID_TX "0000ffe1-0000-1000-8000-00805f9b34fb"
BLEServer *pServer = NULL;
BLECharacteristic *pTxCharacteristic;
bool isBleConnected = false;
bool oldBleConnected = false;
uint8_t txValue = 0;
class MyServerCallbacks : public BLEServerCallbacks {
void onConnect(BLEServer *pServer) {
isBleConnected = true;
// connecting
if (isBleConnected && !oldBleConnected) {
// do stuff here on connecting
oldBleConnected = isBleConnected;
Serial.println("Ble Connect");
}
};
void onDisconnect(BLEServer *pServer) {
isBleConnected = false;
// disconnecting
if (!isBleConnected && oldBleConnected) {
oldBleConnected = isBleConnected;
Serial.println("Ble Disconnect");
delay(500); // give the bluetooth stack the chance to get things ready
pServer->startAdvertising(); // restart advertising
}
}
};
class MyCallbacks : public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
onBleReceived(pCharacteristic);
}
};