SPSP
Simple publish-subscribe protocol. Connects low power IoT clients to MQTT.
All Classes Files Functions Variables Typedefs Enumerations
Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
SPSP::FarLayers::MQTT::Adapter Class Reference

MQTT adapter for ESP platform. More...

#include <mqtt_adapter.hpp>

Inheritance diagram for SPSP::FarLayers::MQTT::Adapter:
Inheritance graph
[legend]
Collaboration diagram for SPSP::FarLayers::MQTT::Adapter:
Collaboration graph
[legend]

Public Member Functions

 Adapter (const Config &conf)
 Constructs a new MQTT layer object. More...
 
 ~Adapter ()
 Destroys MQTT layer object. More...
 
bool publish (const std::string &topic, const std::string &payload)
 Publishes message coming from node. More...
 
bool subscribe (const std::string &topic)
 Subscribes to given topic. More...
 
bool unsubscribe (const std::string &topic)
 Unsubscribes from given topic. More...
 
void setSubDataCb (AdapterSubDataCb cb)
 Sets callback for incoming subscription data. More...
 
AdapterSubDataCb getSubDataCb () const
 Gets callback for incoming subscription data. More...
 
void setConnectedCb (AdapterConnectedCb cb)
 Sets connected callback. More...
 
AdapterConnectedCb getConnectedCb () const
 Gets connected callback. More...
 
 Adapter (const Config &conf)
 Constructs a new MQTT layer object. More...
 
 ~Adapter ()
 Destroys MQTT layer object. More...
 
bool publish (const std::string &topic, const std::string &payload)
 Publishes message coming from node. More...
 
bool subscribe (const std::string &topic)
 Subscribes to given topic. More...
 
bool unsubscribe (const std::string &topic)
 Unsubscribes from given topic. More...
 
void setSubDataCb (AdapterSubDataCb cb)
 Sets callback for incoming subscription data. More...
 
AdapterSubDataCb getSubDataCb () const
 Gets callback for incoming subscription data. More...
 
void setConnectedCb (AdapterConnectedCb cb)
 Sets connected callback. More...
 
AdapterConnectedCb getConnectedCb () const
 Gets connected callback. More...
 
virtual bool publish (const std::string &topic, const std::string &payload)
 Publishes message coming from node. More...
 
virtual bool subscribe (const std::string &topic)
 Subscribes to given topic. More...
 
virtual bool unsubscribe (const std::string &topic)
 Unsubscribes from given topic. More...
 
virtual void setSubDataCb (AdapterSubDataCb cb)
 Sets callback for incoming subscription data. More...
 
virtual void setConnectedCb (AdapterConnectedCb cb)
 Sets connected callback. More...
 

Protected Member Functions

bool connect ()
 Connects to MQTT server. More...
 

Static Protected Member Functions

static const char * stringToCOrNull (const std::string &str)
 Helper to convert std::string to C string or nullptr More...
 
static void connectedCb (void *ctx, char *cause)
 Connected callback. More...
 
static void connFailureCb (void *ctx, MQTTAsync_failureData *resp)
 Connection failure callback. More...
 
static void connLostCb (void *ctx, char *cause)
 Connection lost callback. More...
 
static int subMsgCb (void *ctx, char *topic, int topicLen, MQTTAsync_message *msg)
 Subscription message callback. More...
 
static const char * stringToCOrNull (const std::string &str)
 Helper to convert std::string to C string or nullptr More...
 

Detailed Description

MQTT adapter for ESP platform.

Generic MQTT adapter for testing.

MQTT adapter for Linux platform.

Doesn't check if connection was successfully established within time limit.

Only one MQTT instance can use this at a time and there may be many Adapter instances at a time.

Only one MQTT instance can use this at a time and there may be many Adapter instances at a time.

Definition at line 27 of file espidf/spsp/mqtt_adapter.hpp.

Constructor & Destructor Documentation

◆ Adapter() [1/2]

SPSP::FarLayers::MQTT::Adapter::Adapter ( const Config conf)

Constructs a new MQTT layer object.

Requires already initialized WiFi (with IP address).

Parameters
confConfiguration
Exceptions
AdapterErrorwhen MQTT client can't be created and started

◆ ~Adapter() [1/2]

SPSP::FarLayers::MQTT::Adapter::~Adapter ( )

Destroys MQTT layer object.

◆ Adapter() [2/2]

SPSP::FarLayers::MQTT::Adapter::Adapter ( const Config conf)

Constructs a new MQTT layer object.

Requires already initialized WiFi (with IP address).

Parameters
confConfiguration
Exceptions
AdapterErrorwhen MQTT client can't be created and started

◆ ~Adapter() [2/2]

SPSP::FarLayers::MQTT::Adapter::~Adapter ( )

Destroys MQTT layer object.

Member Function Documentation

◆ connect()

bool SPSP::FarLayers::MQTT::Adapter::connect ( )
protected

Connects to MQTT server.

Returns
true Connection process started successfully
false Connection failed

◆ connectedCb()

static void SPSP::FarLayers::MQTT::Adapter::connectedCb ( void *  ctx,
char *  cause 
)
staticprotected

Connected callback.

Passed to underlaying library.

Parameters
ctxContext
causeCause

◆ connFailureCb()

static void SPSP::FarLayers::MQTT::Adapter::connFailureCb ( void *  ctx,
MQTTAsync_failureData *  resp 
)
staticprotected

Connection failure callback.

Passed to underlaying library.

Parameters
ctxContext
respResponse

◆ connLostCb()

static void SPSP::FarLayers::MQTT::Adapter::connLostCb ( void *  ctx,
char *  cause 
)
staticprotected

Connection lost callback.

Passed to underlaying library.

Parameters
ctxContext
causeCause

◆ getConnectedCb() [1/2]

AdapterConnectedCb SPSP::FarLayers::MQTT::Adapter::getConnectedCb ( ) const

Gets connected callback.

Returns
Callback

◆ getConnectedCb() [2/2]

AdapterConnectedCb SPSP::FarLayers::MQTT::Adapter::getConnectedCb ( ) const

Gets connected callback.

Returns
Callback

◆ getSubDataCb() [1/2]

AdapterSubDataCb SPSP::FarLayers::MQTT::Adapter::getSubDataCb ( ) const

Gets callback for incoming subscription data.

Returns
Callback

◆ getSubDataCb() [2/2]

AdapterSubDataCb SPSP::FarLayers::MQTT::Adapter::getSubDataCb ( ) const

Gets callback for incoming subscription data.

Returns
Callback

◆ publish() [1/3]

virtual bool SPSP::FarLayers::MQTT::Adapter::publish ( const std::string &  topic,
const std::string &  payload 
)
inlinevirtual

Publishes message coming from node.

Parameters
topicTopic
payloadPayload (data)
Returns
true Delivery successful
false Delivery failed

Implements SPSP::FarLayers::MQTT::IAdapter.

Definition at line 32 of file testing/spsp/mqtt_adapter.hpp.

◆ publish() [2/3]

bool SPSP::FarLayers::MQTT::Adapter::publish ( const std::string &  topic,
const std::string &  payload 
)
virtual

Publishes message coming from node.

This doesn't block.

Parameters
topicTopic
payloadPayload (data)
Returns
true Delivery successful
false Delivery failed

Implements SPSP::FarLayers::MQTT::IAdapter.

◆ publish() [3/3]

bool SPSP::FarLayers::MQTT::Adapter::publish ( const std::string &  topic,
const std::string &  payload 
)
virtual

Publishes message coming from node.

This doesn't block.

Parameters
topicTopic
payloadPayload (data)
Returns
true Delivery successful
false Delivery failed

Implements SPSP::FarLayers::MQTT::IAdapter.

◆ setConnectedCb() [1/3]

virtual void SPSP::FarLayers::MQTT::Adapter::setConnectedCb ( AdapterConnectedCb  cb)
inlinevirtual

Sets connected callback.

Should be called on successful connection and reconnection.

Parameters
cbCallback

Implements SPSP::FarLayers::MQTT::IAdapter.

Definition at line 77 of file testing/spsp/mqtt_adapter.hpp.

◆ setConnectedCb() [2/3]

void SPSP::FarLayers::MQTT::Adapter::setConnectedCb ( AdapterConnectedCb  cb)
virtual

Sets connected callback.

Should be called on successful connection and reconnection.

Parameters
cbCallback

Implements SPSP::FarLayers::MQTT::IAdapter.

◆ setConnectedCb() [3/3]

void SPSP::FarLayers::MQTT::Adapter::setConnectedCb ( AdapterConnectedCb  cb)
virtual

Sets connected callback.

Should be called on successful connection and reconnection.

Parameters
cbCallback

Implements SPSP::FarLayers::MQTT::IAdapter.

◆ setSubDataCb() [1/3]

virtual void SPSP::FarLayers::MQTT::Adapter::setSubDataCb ( AdapterSubDataCb  cb)
inlinevirtual

Sets callback for incoming subscription data.

Parameters
cbCallback

Implements SPSP::FarLayers::MQTT::IAdapter.

Definition at line 68 of file testing/spsp/mqtt_adapter.hpp.

◆ setSubDataCb() [2/3]

void SPSP::FarLayers::MQTT::Adapter::setSubDataCb ( AdapterSubDataCb  cb)
virtual

Sets callback for incoming subscription data.

Parameters
cbCallback

Implements SPSP::FarLayers::MQTT::IAdapter.

◆ setSubDataCb() [3/3]

void SPSP::FarLayers::MQTT::Adapter::setSubDataCb ( AdapterSubDataCb  cb)
virtual

Sets callback for incoming subscription data.

Parameters
cbCallback

Implements SPSP::FarLayers::MQTT::IAdapter.

◆ stringToCOrNull() [1/2]

static const char* SPSP::FarLayers::MQTT::Adapter::stringToCOrNull ( const std::string &  str)
inlinestaticprotected

Helper to convert std::string to C string or nullptr

Parameters
strString
Returns
If string is empty, nullptr, otherwise C string.

Definition at line 122 of file espidf/spsp/mqtt_adapter.hpp.

◆ stringToCOrNull() [2/2]

static const char* SPSP::FarLayers::MQTT::Adapter::stringToCOrNull ( const std::string &  str)
inlinestaticprotected

Helper to convert std::string to C string or nullptr

Parameters
strString
Returns
If string is empty, nullptr, otherwise C string.

Definition at line 171 of file linux/spsp/mqtt_adapter.hpp.

◆ subMsgCb()

static int SPSP::FarLayers::MQTT::Adapter::subMsgCb ( void *  ctx,
char *  topic,
int  topicLen,
MQTTAsync_message *  msg 
)
staticprotected

Subscription message callback.

Passed to underlaying library.

Parameters
ctxContext
topicTopic
topicLenLength of topic
msgMQTT message

◆ subscribe() [1/3]

virtual bool SPSP::FarLayers::MQTT::Adapter::subscribe ( const std::string &  topic)
inlinevirtual

Subscribes to given topic.

Parameters
topicTopic
Returns
true Subscribe successful
false Subscribe failed

Implements SPSP::FarLayers::MQTT::IAdapter.

Definition at line 44 of file testing/spsp/mqtt_adapter.hpp.

◆ subscribe() [2/3]

bool SPSP::FarLayers::MQTT::Adapter::subscribe ( const std::string &  topic)
virtual

Subscribes to given topic.

This blocks.

Parameters
topicTopic
Returns
true Subscribe successful
false Subscribe failed

Implements SPSP::FarLayers::MQTT::IAdapter.

◆ subscribe() [3/3]

bool SPSP::FarLayers::MQTT::Adapter::subscribe ( const std::string &  topic)
virtual

Subscribes to given topic.

This blocks.

Parameters
topicTopic
Returns
true Subscribe successful
false Subscribe failed

Implements SPSP::FarLayers::MQTT::IAdapter.

◆ unsubscribe() [1/3]

virtual bool SPSP::FarLayers::MQTT::Adapter::unsubscribe ( const std::string &  topic)
inlinevirtual

Unsubscribes from given topic.

This blocks.

Parameters
topicTopic
Returns
true Unsubscribe successful
false Unsubscribe failed

Implements SPSP::FarLayers::MQTT::IAdapter.

Definition at line 58 of file testing/spsp/mqtt_adapter.hpp.

◆ unsubscribe() [2/3]

bool SPSP::FarLayers::MQTT::Adapter::unsubscribe ( const std::string &  topic)
virtual

Unsubscribes from given topic.

This blocks.

Parameters
topicTopic
Returns
true Unsubscribe successful
false Unsubscribe failed

Implements SPSP::FarLayers::MQTT::IAdapter.

◆ unsubscribe() [3/3]

bool SPSP::FarLayers::MQTT::Adapter::unsubscribe ( const std::string &  topic)
virtual

Unsubscribes from given topic.

This blocks.

Parameters
topicTopic
Returns
true Unsubscribe successful
false Unsubscribe failed

Implements SPSP::FarLayers::MQTT::IAdapter.


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