summaryrefslogtreecommitdiff
path: root/examples/BLE_notify/BLE_notify.ino
diff options
context:
space:
mode:
authorchegewara <imperiaonline4@gmail.com>2018-11-30 10:59:14 +0100
committerchegewara <imperiaonline4@gmail.com>2018-11-30 10:59:14 +0100
commit934702b6169b92c71cbc850876fd17fb9ee3236d (patch)
tree048df4f7106cd4a574b609a13e62a36567f5a322 /examples/BLE_notify/BLE_notify.ino
parentUpload of 0.4.16 (diff)
downloadthermostat-934702b6169b92c71cbc850876fd17fb9ee3236d.tar.gz
thermostat-934702b6169b92c71cbc850876fd17fb9ee3236d.tar.bz2
thermostat-934702b6169b92c71cbc850876fd17fb9ee3236d.zip
Changes, bugfixes and updgrades. Library is ready to work with arduino-esp32 v1.0.1.
Diffstat (limited to 'examples/BLE_notify/BLE_notify.ino')
-rw-r--r--examples/BLE_notify/BLE_notify.ino15
1 files changed, 10 insertions, 5 deletions
diff --git a/examples/BLE_notify/BLE_notify.ino b/examples/BLE_notify/BLE_notify.ino
index 5e915be..42b9e72 100644
--- a/examples/BLE_notify/BLE_notify.ino
+++ b/examples/BLE_notify/BLE_notify.ino
@@ -2,6 +2,7 @@
Video: https://www.youtube.com/watch?v=oCMOYS71NIU
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleNotify.cpp
Ported to Arduino ESP32 by Evandro Copercini
+ updated by chegewara
Create a BLE server that, once we receive a connection, will send periodic notifications.
The service advertises itself as: 4fafc201-1fb5-459e-8fcc-c5c9c331914b
@@ -27,7 +28,7 @@ BLEServer* pServer = NULL;
BLECharacteristic* pCharacteristic = NULL;
bool deviceConnected = false;
bool oldDeviceConnected = false;
-uint8_t value = 0;
+uint32_t value = 0;
// See the following for generating UUIDs:
// https://www.uuidgenerator.net/
@@ -52,7 +53,7 @@ void setup() {
Serial.begin(115200);
// Create the BLE Device
- BLEDevice::init("MyESP32");
+ BLEDevice::init("ESP32");
// Create the BLE Server
pServer = BLEDevice::createServer();
@@ -78,17 +79,21 @@ void setup() {
pService->start();
// Start advertising
- pServer->getAdvertising()->start();
+ BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
+ pAdvertising->addServiceUUID(SERVICE_UUID);
+ pAdvertising->setScanResponse(false);
+ pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter
+ BLEDevice::startAdvertising();
Serial.println("Waiting a client connection to notify...");
}
void loop() {
// notify changed value
if (deviceConnected) {
- pCharacteristic->setValue(&value, 1);
+ pCharacteristic->setValue((uint8_t*)&value, 4);
pCharacteristic->notify();
value++;
- delay(10); // bluetooth stack will go into congestion, if too many packets are sent
+ delay(3); // bluetooth stack will go into congestion, if too many packets are sent, in 6 hours test i was able to go as low as 3ms
}
// disconnecting
if (!deviceConnected && oldDeviceConnected) {