diff --git a/ble-server.cpp b/ble-server.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7d77af27adc32edbee99d5ad1e781b49d315578b --- /dev/null +++ b/ble-server.cpp @@ -0,0 +1,55 @@ +#include <Arduino.h> +#include <BLEDevice.h> +#include <BLEUtils.h> +#include <BLEServer.h> + +// See the following for generating UUIDs: +// https://www.uuidgenerator.net/ + +#define SERVICE_UUID "61a7f44e-5a29-4b16-a219-3dfd49d28ebc" +#define CHARACTERISTIC_UUID1 "beb5483e-36e1-4688-b7f5-ea07361b26a8" +#define CHARACTERISTIC_UUID2 "717740b7-02f8-4e5e-a236-2ec94d303934" +#define CHARACTERISTIC_UUID3 "77e846fd-d2bd-4ea1-b2ef-639bac74bac8" + +void setup() { + Serial.begin(115200); + Serial.println("Program started"); + + BLEDevice::init("ExampleBluetoothServer"); + BLEServer *server = BLEDevice::createServer(); + BLEService *testService = server->createService(SERVICE_UUID); + BLECharacteristic *accelerometerCharX = testService->createCharacteristic( + CHARACTERISTIC_UUID1, + BLECharacteristic::PROPERTY_READ | + BLECharacteristic::PROPERTY_WRITE + ); + BLECharacteristic *accelerometerCharY = testService->createCharacteristic( + CHARACTERISTIC_UUID2, + BLECharacteristic::PROPERTY_READ | + BLECharacteristic::PROPERTY_WRITE + ); + BLECharacteristic *accelerometerCharZ = testService->createCharacteristic( + CHARACTERISTIC_UUID3, + BLECharacteristic::PROPERTY_READ | + BLECharacteristic::PROPERTY_WRITE + ); + + accelerometerCharX->setValue("Accelerometer value X"); + accelerometerCharY->setValue("Accelerometer value Y"); + accelerometerCharZ->setValue("Accelerometer value Z"); + testService->start(); + + //Set up broadcasting + BLEAdvertising *pAdvertising = BLEDevice::getAdvertising(); + pAdvertising->addServiceUUID(SERVICE_UUID); + pAdvertising->setScanResponse(true); + pAdvertising->setMinPreferred(0x08); + pAdvertising->setMinPreferred(0x16); + BLEDevice::startAdvertising(); + Serial.println("GATT server set up"); +} + +void loop() { + // put your main code here, to run repeatedly: + delay(2000); +}