File Information
Library: IoT/BtLE
Package: BtLE
Header: IoT/BtLE/GATTClient.h
Description
This class provides a low-level interface to a Bt LE peripheral device using the Bt Generic Attribute Profile (GATT).
Member Summary
Member Functions: address, characteristics, connect, descriptors, disconnect, getMTU, getSecurityLevel, getTimeout, includedServices, read, services, setMTU, setSecurityLevel, setTimeout, state, write
Nested Classes
struct Characteristic
Characteristic description.
struct Descriptor
struct Indication
struct Notification
struct Service
Service description.
Types Aliases
Handle
using Handle = Poco::UInt16;
Ptr
using Ptr = Poco::SharedPtr < GATTClient >;
Enumerations
ConnectMode
Connect mode - synchronous or asynchronous.
Property
Characteristic property flags.
GATT_PROP_BROADCAST = 0x01
GATT_PROP_READ = 0x02
GATT_PROP_WRITE_NO_RESP = 0x04
GATT_PROP_WRITE = 0x08
GATT_PROP_NOTIFY = 0x10
GATT_PROP_INDICATE = 0x20
GATT_PROP_WRITE_SIGNED = 0x40
GATT_PROP_EXTENDED = 0x80
SecurityLevel
Security level of the connection to the peripheral device.
State
State of the connection to the peripheral device.
Destructor
~GATTClient
virtual ~GATTClient();
Member Functions
address
virtual std::string address() const = 0;
Returns the address of the connected device, or an empty string if no device is connected.
characteristics
virtual std::vector < Characteristic > characteristics(
const Poco::UUID & serviceUUID
) = 0;
Returns a list of all characteristics of the service with the given UUID.
connect
virtual void connect(
const std::string & address,
ConnectMode mode = GATT_CONNECT_WAIT
) = 0;
Connects the GATTClient to the Bt LE peripheral with the given address. The address consists of six hexadecimal byte values, separated by a colon, e.g.: "68:C9:0B:06:23:09".
If mode is GATT_CONNECT_WAIT, waits for the connection to be established (or for an error to be reported).
If wait is GATT_CONNECT_NOWAIT, returns immediately. The connection state is reported via the connected event.
descriptors
virtual std::vector < Descriptor > descriptors(
const Poco::UUID & serviceUUID
) = 0;
Returns a list of all handle descriptors for the service with the given UUID.
disconnect
virtual void disconnect() = 0;
Disconnects from the peripheral.
getMTU
virtual Poco::UInt8 getMTU() const = 0;
Returns the connection's MTU size, which may be 0 for the default size.
getSecurityLevel
virtual SecurityLevel getSecurityLevel() const = 0;
Returns the connection's current security level.
getTimeout
virtual long getTimeout() const = 0;
Returns the timeout for communication with the peripheral device.
includedServices
virtual std::vector < Service > includedServices(
const Poco::UUID & serviceUUID
) = 0;
Returns a list of all services included by the service identified by the given handles.
read
virtual std::string read(
Handle handle
) = 0;
Reads the value of the characteristic's value with the given value handle.
services
virtual std::vector < Service > services() = 0;
Returns a list of all services supported by the peripheral.
setMTU
virtual void setMTU(
Poco::UInt8 mtu
) = 0;
Sets the connection's MTU size.
setSecurityLevel
virtual void setSecurityLevel(
SecurityLevel level
) = 0;
Sets the connection's security level.
setTimeout
virtual void setTimeout(
long milliseconds
) = 0;
Sets the timeout for communication with the peripheral device.
state
virtual State state() const = 0;
Returns the current state of the client.
write
virtual void write(
Handle handle,
const std::string & value,
bool withResponse = true
) = 0;
Writes the value of the characteristic with the given handle. If withResponse is true, expects a response from the peripheral device.
write
virtual void write(
Handle handle,
const char * value,
std::size_t size,
bool withResponse = true
) = 0;
Writes the value of the characteristic with the given handle. If withResponse is true, expects a response from the peripheral device.
Variables
connected
Poco::BasicEvent < void > connected;
Fired when a connection with the peripheral has been established.
disconnected
Poco::BasicEvent < void > disconnected;
Fired when the connection with the peripheral has been disconnected.
error
Poco::BasicEvent < const std::string > error;
Fired when the connection attempt with the peripheral has failed. The event argument contains more information about the error.
indicationReceived
Poco::BasicEvent < const Indication > indicationReceived;
Fired when an Indication has been received from the peripheral.
notificationReceived
Poco::BasicEvent < const Notification > notificationReceived;
Fired when a Notification has been received from the peripheral.