diff options
author | kolban <kolban1@kolban.com> | 2017-09-10 13:42:22 -0500 |
---|---|---|
committer | kolban <kolban1@kolban.com> | 2017-09-10 13:42:22 -0500 |
commit | 0c324857a574b26307788c09e08af1c0123671a8 (patch) | |
tree | 34fc565e948115b74b7f20cde05e2ac2b1055b78 /examples/BLE_server | |
parent | 0.2.0 (diff) | |
download | thermostat-0c324857a574b26307788c09e08af1c0123671a8.tar.gz thermostat-0c324857a574b26307788c09e08af1c0123671a8.tar.bz2 thermostat-0c324857a574b26307788c09e08af1c0123671a8.zip |
0.3.0
Diffstat (limited to 'examples/BLE_server')
-rw-r--r-- | examples/BLE_server/BLE_server.ino | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/BLE_server/BLE_server.ino b/examples/BLE_server/BLE_server.ino new file mode 100644 index 0000000..45ebf99 --- /dev/null +++ b/examples/BLE_server/BLE_server.ino @@ -0,0 +1,41 @@ +/* + Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleServer.cpp + Ported to Arduino ESP32 by Evandro Copercini +*/ + +#include <BLEDevice.h> +#include <BLEUtils.h> +#include <BLEServer.h> + +BLEDevice ble; + +// See the following for generating UUIDs: +// https://www.uuidgenerator.net/ + +#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b" +#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8" + +void setup() { + Serial.begin(115200); + Serial.println("Starting BLE work!"); + + ble.init("MyESP32"); + BLEServer *pServer = new BLEServer(); + BLEService *pService = pServer->createService(SERVICE_UUID); + BLECharacteristic *pCharacteristic = pService->createCharacteristic( + CHARACTERISTIC_UUID, + BLECharacteristic::PROPERTY_READ | + BLECharacteristic::PROPERTY_WRITE + ); + + pCharacteristic->setValue("Hello World says Neil"); + pService->start(); + BLEAdvertising *pAdvertising = pServer->getAdvertising(); + pAdvertising->start(); + Serial.println("Characteristic defined! Now you can read it in your phone!"); +} + +void loop() { + // put your main code here, to run repeatedly: + delay(2000); +}
\ No newline at end of file |