|
SPSP
Simple publish-subscribe protocol. Connects low power IoT clients to MQTT.
|
Go to the documentation of this file.
12 #include "MQTTAsync.h"
17 namespace SPSP::FarLayers::MQTT
25 class Adapter :
public IAdapter
29 AdapterSubDataCb m_subDataCb =
nullptr;
30 AdapterConnectedCb m_connectedCb =
nullptr;
59 bool publish(
const std::string& topic,
const std::string& payload);
140 static void connFailureCb(
void* ctx, MQTTAsync_failureData* resp);
150 static void connLostCb(
void* ctx,
char* cause);
162 static int subMsgCb(
void* ctx,
char* topic,
int topicLen,
163 MQTTAsync_message* msg);
173 return str.empty() ? nullptr : str.c_str();
~Adapter()
Destroys MQTT layer object.
Adapter(const Config &conf)
Constructs a new MQTT layer object.
Interface for platform-dependent MQTT adapter.
static void connectedCb(void *ctx, char *cause)
Connected callback.
bool connect()
Connects to MQTT server.
AdapterSubDataCb getSubDataCb() const
Gets callback for incoming subscription data.
static int subMsgCb(void *ctx, char *topic, int topicLen, MQTTAsync_message *msg)
Subscription message callback.
static const char * stringToCOrNull(const std::string &str)
Helper to convert std::string to C string or nullptr
void setSubDataCb(AdapterSubDataCb cb)
Sets callback for incoming subscription data.
bool subscribe(const std::string &topic)
Subscribes to given topic.
bool publish(const std::string &topic, const std::string &payload)
Publishes message coming from node.
void setConnectedCb(AdapterConnectedCb cb)
Sets connected callback.
bool unsubscribe(const std::string &topic)
Unsubscribes from given topic.
static void connFailureCb(void *ctx, MQTTAsync_failureData *resp)
Connection failure callback.
AdapterConnectedCb getConnectedCb() const
Gets connected callback.
static void connLostCb(void *ctx, char *cause)
Connection lost callback.