Advertisement
Guest User

lol

a guest
Oct 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. #include <BLEDevice.h>
  2. #include <BLEUtils.h>
  3. #include <BLEServer.h>
  4.  
  5. // See the following for generating UUIDs:
  6. // https://www.uuidgenerator.net/
  7.  
  8. #define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
  9. #define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
  10.  
  11. void setup() {
  12.   Serial.begin(115200);
  13.   Serial.println("Starting BLE work!");
  14.  
  15.   BLEDevice::init("Long name works now");
  16.   BLEServer *pServer = BLEDevice::createServer();
  17.   BLEService *pService = pServer->createService(SERVICE_UUID);
  18.   BLECharacteristic *pCharacteristic = pService->createCharacteristic(
  19.                                          CHARACTERISTIC_UUID,
  20.                                          BLECharacteristic::PROPERTY_READ |
  21.                                          BLECharacteristic::PROPERTY_WRITE
  22.                                        );
  23.  
  24.   pCharacteristic->setValue("Hello World says Neil");
  25.   pService->start();
  26.   // BLEAdvertising *pAdvertising = pServer->getAdvertising();  // this still is working for backward compatibility
  27.   BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  28.   pAdvertising->addServiceUUID(SERVICE_UUID);
  29.   pAdvertising->setScanResponse(true);
  30.   pAdvertising->setMinPreferred(0x06);  // functions that help with iPhone connections issue
  31.   pAdvertising->setMinPreferred(0x12);
  32.   BLEDevice::startAdvertising();
  33.   Serial.println("Characteristic defined! Now you can read it in your phone!");
  34. }
  35.  
  36. void loop() {
  37.   // put your main code here, to run repeatedly:
  38.   delay(2000);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement