Skip to content

Instantly share code, notes, and snippets.

@RuiSantosdotme
Created January 19, 2019 18:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RuiSantosdotme/d98d1867c5f53e57144877526665a199 to your computer and use it in GitHub Desktop.
Save RuiSantosdotme/d98d1867c5f53e57144877526665a199 to your computer and use it in GitHub Desktop.
/*
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>
// See the following for generating UUIDs:
// https://www.uuidgenerator.net/
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC1_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
#define CHARACTERISTIC2_UUID "688091db-1736-4179-b7ce-e42a724a6a68"
#define CHARACTERISTIC3_UUID "0515e27d-dd91-4f96-9452-5f43649c1819"
void setup() {
Serial.begin(115200);
Serial.println("Starting BLE work!");
BLEDevice::init("MyESP32");
BLEServer *pServer = BLEDevice::createServer();
BLEService *pService = pServer->createService(SERVICE_UUID);
BLECharacteristic *pCharacteristic1 = pService->createCharacteristic(
CHARACTERISTIC1_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE
);
pCharacteristic1->setValue("Hi 1");
BLECharacteristic *pCharacteristic2 = pService->createCharacteristic(
CHARACTERISTIC2_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE
);
pCharacteristic2->setValue("Hi 2");
BLECharacteristic *pCharacteristic3 = pService->createCharacteristic(
CHARACTERISTIC3_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE
);
pCharacteristic3->setValue("Hi 3");
pService->start();
BLEAdvertising *pAdvertising = pServer->getAdvertising();
pAdvertising->start();
Serial.println("3 Characteristics defined! Now you can read it in your phone!");
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment