Changes to help with connection issues
This commit is contained in:
parent
f1dabd3a7d
commit
a4ab81cf4d
1 changed files with 15 additions and 1 deletions
|
@ -5,6 +5,12 @@
|
||||||
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
|
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
|
||||||
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
|
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
|
||||||
|
|
||||||
|
class BLEAdvertisingRestartCallback: public BLEServerCallbacks {
|
||||||
|
void onConnect(BLEServer* server) {
|
||||||
|
BLEDevice::getAdvertising()->start();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class BluetoothService {
|
class BluetoothService {
|
||||||
const char *_serviceName;
|
const char *_serviceName;
|
||||||
BLECharacteristicCallbacks *_callbacks;
|
BLECharacteristicCallbacks *_callbacks;
|
||||||
|
@ -22,12 +28,20 @@ public:
|
||||||
BLEDevice::init(_serviceName);
|
BLEDevice::init(_serviceName);
|
||||||
_server = BLEDevice::createServer();
|
_server = BLEDevice::createServer();
|
||||||
_service = _server->createService(SERVICE_UUID);
|
_service = _server->createService(SERVICE_UUID);
|
||||||
|
_server->setCallbacks(new BLEAdvertisingRestartCallback());
|
||||||
|
|
||||||
_characteristic = _service->createCharacteristic(CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE);
|
_characteristic = _service->createCharacteristic(CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE);
|
||||||
_characteristic->setCallbacks(_callbacks);
|
_characteristic->setCallbacks(_callbacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void start() {
|
void start() {
|
||||||
_service->start();
|
_service->start();
|
||||||
_server->getAdvertising()->start();
|
|
||||||
|
BLEAdvertising *advertising = BLEDevice::getAdvertising();
|
||||||
|
advertising->addServiceUUID(SERVICE_UUID);
|
||||||
|
advertising->setScanResponse(true);
|
||||||
|
advertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
|
||||||
|
advertising->setMinPreferred(0x12);
|
||||||
|
BLEDevice::startAdvertising();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue