UWB-Tracking
Loading...
Searching...
No Matches
ble-server.h
Go to the documentation of this file.
1#pragma once
2
8#include "Arduino.h"
9#include <NimBLEDevice.h>
10#include <array>
11
12#define BLE_NAME "ESP32"
13
14// BLE Service for Configuration
15#define BLE_SERVICE_INPUT_UUID "76847a0a-2748-4fda-bcd7-74425f0e4a10"
16#define BLE_CHARAKTERISTIK_DEVICE_POSITION_UUID "76847a0a-2748-4fda-bcd7-74425f0e4a11"
17#define BLE_DESCRIPTOR_DEVICE_POSITION_UUID "76847a0a-2748-4fda-bcd7-74425f0e4a12"
18#define BLE_CHARAKTERISTIK_SAVE_CONFIG_UUID "76847a0a-2748-4fda-bcd7-74425f0e4a13"
19#define BLE_DESCRIPTOR_SAVE_CONFIG_UUID "76847a0a-2748-4fda-bcd7-74425f0e4a14"
20
21// BLE Service for Device-Information
22#define BLE_SERVICE_OUTPUT_UUID "76847a0a-2748-4fda-bcd7-74425f0e4a20"
23#define BLE_CHARAKTERISTIK_ANCHOR_POSITIONS_UUID "76847a0a-2748-4fda-bcd7-74425f0e4a21"
24#define BLE_DESCRIPTOR_ANCHOR_POSITIONS_UUID "76847a0a-2748-4fda-bcd7-74425f0e4a22"
25#define BLE_CHARAKTERISTIK_OWN_POSITION_UUID "76847a0a-2748-4fda-bcd7-74425f0e4a23"
26#define BLE_DESCRIPTOR_OWN_POSITION_UUID "76847a0a-2748-4fda-bcd7-74425f0e4a24"
27
28/*BLE Advertising-Intervalle*/
29#define BLE_MIN_INTERVAL 0x06
30#define BLE_MAX_INTERVAL 0x12
31
37{
38public:
43
52 void init_server();
53
60 std::string read_value(const std::string uuid);
61
69 void send_value(std::string uuid, const std::string data);
70
76 size_t getConnectedCount() { return this->pServer->getConnectedCount(); };
77
78private:
79 BLEServer *pServer;
80 BLEAdvertising *pAdvertising;
81 std::list<BLEService *> mServices;
88 {
89 std::string name;
90 std::string characteristic_uuid;
91 std::string descriptor_uuid;
92 };
93
98 struct Service
99 {
100 std::string uuid;
101 const std::array<Characteristic, 2> characteristics;
102 };
103
104 /*This Array structure shows the Service-&Characteristic-Architecture of the BLE Connection*/
105 const std::array<Service, 2> my_services{
106 Service{
108 characteristics : {
109 Characteristic{name : "anchor position [i.e. {\"x\":1,\"y\":2,\"z\":3}]", characteristic_uuid : BLE_CHARAKTERISTIK_DEVICE_POSITION_UUID, descriptor_uuid : BLE_DESCRIPTOR_DEVICE_POSITION_UUID},
110 Characteristic{name : "send \"1\" for saving config", characteristic_uuid : BLE_CHARAKTERISTIK_SAVE_CONFIG_UUID, descriptor_uuid : BLE_DESCRIPTOR_SAVE_CONFIG_UUID},
111 }
112 },
113
114 Service{
116 characteristics : {
117 Characteristic{name : "Anchor Positions [Output only]", characteristic_uuid : BLE_CHARAKTERISTIK_ANCHOR_POSITIONS_UUID, descriptor_uuid : BLE_DESCRIPTOR_ANCHOR_POSITIONS_UUID},
118 Characteristic{name : "my position [i.e. x, y, z]", characteristic_uuid : BLE_CHARAKTERISTIK_OWN_POSITION_UUID, descriptor_uuid : BLE_DESCRIPTOR_OWN_POSITION_UUID},
119 }
120 }
121 };
122
129 void add_Characteristic(BLEService *service, BleServer::Characteristic characteristic);
130
140 void init_services();
141};
#define BLE_CHARAKTERISTIK_OWN_POSITION_UUID
Definition: ble-server.h:25
#define BLE_DESCRIPTOR_ANCHOR_POSITIONS_UUID
Definition: ble-server.h:24
#define BLE_DESCRIPTOR_DEVICE_POSITION_UUID
Definition: ble-server.h:17
#define BLE_CHARAKTERISTIK_ANCHOR_POSITIONS_UUID
Definition: ble-server.h:23
#define BLE_DESCRIPTOR_SAVE_CONFIG_UUID
Definition: ble-server.h:19
#define BLE_DESCRIPTOR_OWN_POSITION_UUID
Definition: ble-server.h:26
#define BLE_SERVICE_INPUT_UUID
Definition: ble-server.h:15
#define BLE_CHARAKTERISTIK_SAVE_CONFIG_UUID
Definition: ble-server.h:18
#define BLE_CHARAKTERISTIK_DEVICE_POSITION_UUID
Definition: ble-server.h:16
#define BLE_SERVICE_OUTPUT_UUID
Definition: ble-server.h:22
Represents a Bluetooth Server for ESP32.
Definition: ble-server.h:37
void init_services()
Initializes all services for the BLE server.
Definition: ble-server.cpp:32
const std::array< Service, 2 > my_services
Definition: ble-server.h:105
BleServer()
Constructor for BleServer class.
Definition: ble-server.h:42
void add_Characteristic(BLEService *service, BleServer::Characteristic characteristic)
Adds a new characteristic with the given UUID to a service.
Definition: ble-server.cpp:50
void send_value(std::string uuid, const std::string data)
Sends a new value to a Characteristic with the given UUID. The Characteristic can be referenced witho...
Definition: ble-server.cpp:80
size_t getConnectedCount()
Get the number of connected devices.
Definition: ble-server.h:76
BLEServer * pServer
Definition: ble-server.h:79
std::list< BLEService * > mServices
Definition: ble-server.h:81
void init_server()
Initializes the Bluetooth Server.
Definition: ble-server.cpp:3
BLEAdvertising * pAdvertising
Definition: ble-server.h:80
std::string read_value(const std::string uuid)
Reads the value from a characteristic with the given UUID.
Definition: ble-server.cpp:63
Represents a Bluetooth characteristic with a name, UUID, and descriptor UUID.
Definition: ble-server.h:88
std::string descriptor_uuid
Definition: ble-server.h:91
std::string name
Definition: ble-server.h:89
std::string characteristic_uuid
Definition: ble-server.h:90
Represents a Bluetooth service with a UUID and an array of characteristics.
Definition: ble-server.h:99
std::string uuid
Definition: ble-server.h:100
const std::array< Characteristic, 2 > characteristics
Definition: ble-server.h:101