UWB-Tracking
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
BleServer Class Reference

Represents a Bluetooth Server for ESP32. More...

#include <ble-server.h>

Classes

struct  Characteristic
 Represents a Bluetooth characteristic with a name, UUID, and descriptor UUID. More...
 
struct  Service
 Represents a Bluetooth service with a UUID and an array of characteristics. More...
 

Public Member Functions

 BleServer ()
 Constructor for BleServer class. More...
 
void init_server ()
 Initializes the Bluetooth Server. More...
 
std::string read_value (const std::string uuid)
 Reads the value from a characteristic with the given UUID. More...
 
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 without specifying the Service. More...
 
size_t getConnectedCount ()
 Get the number of connected devices. More...
 

Private Member Functions

void add_Characteristic (BLEService *service, BleServer::Characteristic characteristic)
 Adds a new characteristic with the given UUID to a service. More...
 
void init_services ()
 Initializes all services for the BLE server. More...
 

Private Attributes

BLEServer * pServer
 
BLEAdvertising * pAdvertising
 
std::list< BLEService * > mServices
 
const std::array< Service, 2 > my_services
 

Detailed Description

Represents a Bluetooth Server for ESP32.

Constructor & Destructor Documentation

◆ BleServer()

BleServer ( )
inline

Constructor for BleServer class.

Member Function Documentation

◆ add_Characteristic()

void add_Characteristic ( BLEService *  service,
BleServer::Characteristic  characteristic 
)
private

Adds a new characteristic with the given UUID to a service.

Parameters
serviceThe service to which the characteristic should be added.
characteristicA Caracteristic struct, containing uuids and name of the caracteriistic.

◆ getConnectedCount()

size_t getConnectedCount ( )
inline

Get the number of connected devices.

Returns
The number of connected devices.

◆ init_server()

void init_server ( )

Initializes the Bluetooth Server.

This function initializes the Bluetooth Server, creates the services, and starts advertising. The UUIDs of the services are defined through the constants BLE_SERVICE_*. The device name is set through the constant BLE_NAME. The advertising intervals are set through the constants BLE_MIN_INTERVAL and BLE_MAX_INTERVAL.

◆ init_services()

void init_services ( )
private

Initializes all services for the BLE server.

Creates a BLEService for each service UUID specified in the header file and creates a BLECharacteristic for each characteristic UUID specified in the header. Finally, each created service is started.

Note
The services and their characteristics are defined in this header file.

◆ read_value()

std::string read_value ( const std::string  uuid)

Reads the value from a characteristic with the given UUID.

Parameters
uuidThe UUID of the characteristic to read from.
Returns
std::string of the read value.

◆ send_value()

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 without specifying the Service.

Parameters
uuidThe UUID of the Characteristic to which the value should be sent.
dataThe value to be sent.

Member Data Documentation

◆ mServices

std::list<BLEService *> mServices
private

List of BLE services.

◆ my_services

const std::array<Service, 2> my_services
private
Initial value:
{
Service{
characteristics : {
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},
Characteristic{name : "send \"1\" for saving config", characteristic_uuid : BLE_CHARAKTERISTIK_SAVE_CONFIG_UUID, descriptor_uuid : BLE_DESCRIPTOR_SAVE_CONFIG_UUID},
}
},
Service{
characteristics : {
Characteristic{name : "Anchor Positions [Output only]", characteristic_uuid : BLE_CHARAKTERISTIK_ANCHOR_POSITIONS_UUID, descriptor_uuid : BLE_DESCRIPTOR_ANCHOR_POSITIONS_UUID},
Characteristic{name : "my position [i.e. x, y, z]", characteristic_uuid : BLE_CHARAKTERISTIK_OWN_POSITION_UUID, descriptor_uuid : BLE_DESCRIPTOR_OWN_POSITION_UUID},
}
}
}
#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 characteristic with a name, UUID, and descriptor UUID.
Definition: ble-server.h:88

◆ pAdvertising

BLEAdvertising* pAdvertising
private

Pointer to the BLE advertising object.

◆ pServer

BLEServer* pServer
private

Pointer to the BLE server object.


The documentation for this class was generated from the following files: