Generic Access Service
The GenericAccessService implements the required standard BLE Generic Access service, providing device information from a BLE peripheral to a BLE central.
It should be noted that as a developer, you are not required to use this service, as one is created for you automatically by the BLE stack.
I’m not really sure why I created this file, but I have so here we are.
API Reference
Header File
Classes
-
class GenericAccessService : public espp::BaseComponent
Generic Access Service This class is responsible for creating and managing the Generic Access Service.
The service is created with the following characteristics:
Name (read)
Appearance (read)
The Generic Access Service is a required Bluetooth service that provides information about the device. This information can be used by a client to identify the device and determine its capabilities. The Generic Access Service is defined by the Bluetooth SIG and is intended to be used with any device.
NOTE: as a developer, you should not need to actually use this service directly as the NimBLE stack will automatically include it in the device information. This class is provided for completeness and for developers who want to customize the service. I’m not really sure why I created this file, but I have so here we are.
Public Functions
-
inline explicit GenericAccessService(espp::Logger::Verbosity log_level = espp::Logger::Verbosity::WARN)
Constructor
- Parameters
log_level – The log level for the component
-
inline void init(NimBLEServer *server)
Initialize the Service
- Parameters
server – The BLE server to add the service to
-
inline void deinit()
Deinitialize the Service
Note
This should only be called after NimBLEDevice::deinit(true) has been called, since that will free the memory used by the service
-
inline void start()
Start the service
Note
This must be called after the service has been initialized
-
inline NimBLEService *get_service()
Get the service object
- Returns
The service object
-
inline NimBLEUUID uuid()
Get the UUID of the service
- Returns
The service UUID
-
inline void set_name(const std::string &name)
Set the device name
- Parameters
name – The device name
-
inline void set_appearance(uint16_t appearance)
Set the device appearance
- Parameters
appearance – The appearance value
-
inline std::string get_name()
Get the device name
- Returns
The device name
-
inline uint16_t get_appearance()
Get the device appearance
- Returns
The appearance value
-
inline const std::string &get_name() const
Get the name of the component
Note
This is the tag of the logger
- Returns
A const reference to the name of the component
-
inline void set_log_tag(const std::string_view &tag)
Set the tag for the logger
- Parameters
tag – The tag to use for the logger
-
inline espp::Logger::Verbosity get_log_level() const
Get the log level for the logger
See also
See also
- Returns
The verbosity level of the logger
-
inline void set_log_level(espp::Logger::Verbosity level)
Set the log level for the logger
See also
See also
- Parameters
level – The verbosity level to use for the logger
-
inline void set_log_verbosity(espp::Logger::Verbosity level)
Set the log verbosity for the logger
See also
See also
See also
Note
This is a convenience method that calls set_log_level
- Parameters
level – The verbosity level to use for the logger
-
inline espp::Logger::Verbosity get_log_verbosity() const
Get the log verbosity for the logger
See also
See also
See also
Note
This is a convenience method that calls get_log_level
- Returns
The verbosity level of the logger
-
inline void set_log_rate_limit(std::chrono::duration<float> rate_limit)
Set the rate limit for the logger
See also
Note
Only calls to the logger that have _rate_limit suffix will be rate limited
- Parameters
rate_limit – The rate limit to use for the logger
Public Static Functions
-
static inline uint16_t parse_appearance(const std::vector<uint8_t> &bytes)
Parse the appearance value from raw bytes
- Parameters
bytes – The characteristic value
- Returns
The appearance value
-
static inline uint16_t parse_appearance(const uint8_t *bytes, size_t size)
Parse the appearance value from raw bytes
- Parameters
bytes – The characteristic value
size – The size of the characteristic value
- Returns
The appearance value