IoT::BtLE

class GATTClient

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

Handle 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.

GATT_CONNECT_WAIT

GATT_CONNECT_NOWAIT

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.

GATT_SECURITY_LOW

GATT_SECURITY_MEDIUM

GATT_SECURITY_HIGH

State

State of the connection to the peripheral device.

GATT_STATE_DISCONNECTED

GATT_STATE_CONNECTING

GATT_STATE_CONNECTED

GATT_STATE_DISCONNECTING

Destructor

~GATTClient virtual

virtual ~GATTClient();

Member Functions

address virtual

virtual std::string address() const = 0;

Returns the address of the connected device, or an empty string if no device is connected.

characteristics virtual

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

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

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

virtual void disconnect() = 0;

Disconnects from the peripheral.

getMTU virtual

virtual Poco::UInt8 getMTU() const = 0;

Returns the connection's MTU size, which may be 0 for the default size.

getSecurityLevel virtual

virtual SecurityLevel getSecurityLevel() const = 0;

Returns the connection's current security level.

getTimeout virtual

virtual long getTimeout() const = 0;

Returns the timeout for communication with the peripheral device.

includedServices virtual

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

virtual std::string read(
    Handle handle
) = 0;

Reads the value of the characteristic's value with the given value handle.

services virtual

virtual std::vector < Service > services() = 0;

Returns a list of all services supported by the peripheral.

setMTU virtual

virtual void setMTU(
    Poco::UInt8 mtu
) = 0;

Sets the connection's MTU size.

setSecurityLevel virtual

virtual void setSecurityLevel(
    SecurityLevel level
) = 0;

Sets the connection's security level.

setTimeout virtual

virtual void setTimeout(
    long milliseconds
) = 0;

Sets the timeout for communication with the peripheral device.

state virtual

virtual State state() const = 0;

Returns the current state of the client.

write virtual

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

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.

Securely control IoT edge devices from anywhere   Connect a Device