SPSP
Simple publish-subscribe protocol. Connects low power IoT clients to MQTT.
All Classes Files Functions Variables Typedefs Enumerations
mqtt.hpp
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <future>
13 
14 #include "spsp/layers.hpp"
15 #include "spsp/mqtt_adapter_if.hpp"
16 #include "spsp/mqtt_types.hpp"
17 #include "spsp/node.hpp"
18 
19 namespace SPSP::FarLayers::MQTT
20 {
25  class MQTT : public IFarLayer
26  {
27  Config m_conf;
28  bool m_initializing = true;
29  std::promise<void> m_connectingPromise;
30  IAdapter& m_adapter;
31 
32  public:
43  MQTT(IAdapter& adapter, const Config& conf);
44 
49  ~MQTT();
50 
60  bool publish(const std::string& src, const std::string& topic,
61  const std::string& payload);
62 
72  bool subscribe(const std::string& topic);
73 
83  bool unsubscribe(const std::string& topic);
84 
85  protected:
90  void connectedCb();
91 
98  void subDataCb(const std::string& topic, const std::string& payload);
99  };
100 } // namespace SPSP::FarLayers::MQTT
SPSP::FarLayers::MQTT::MQTT::subscribe
bool subscribe(const std::string &topic)
Subscribes to given topic.
SPSP::FarLayers::MQTT::MQTT::MQTT
MQTT(IAdapter &adapter, const Config &conf)
Constructs a new MQTT layer object.
mqtt_adapter_if.hpp
Interface for platform-dependent MQTT adapter.
SPSP::FarLayers::MQTT::IAdapter
Interface for platform-dependent MQTT adapter.
Definition: mqtt_adapter_if.hpp:37
SPSP::FarLayers::MQTT::MQTT::connectedCb
void connectedCb()
Signalizes successful initial connection to broker.
SPSP::IFarLayer
Interface for far layer.
Definition: layers.hpp:83
node.hpp
Node interface for SPSP.
SPSP::FarLayers::MQTT::MQTT::publish
bool publish(const std::string &src, const std::string &topic, const std::string &payload)
Publishes message coming from node.
SPSP::FarLayers::MQTT::Config
MQTT client configuration.
Definition: mqtt_types.hpp:35
layers.hpp
Local and far layers for SPSP.
SPSP::FarLayers::MQTT::MQTT
MQTT far layer.
Definition: mqtt.hpp:25
mqtt_types.hpp
MQTT types.
SPSP::FarLayers::MQTT::MQTT::~MQTT
~MQTT()
Destroys MQTT layer object.
SPSP::FarLayers::MQTT::MQTT::subDataCb
void subDataCb(const std::string &topic, const std::string &payload)
Callback for underlaying adapter to receive subscribe data.
SPSP::FarLayers::MQTT::MQTT::unsubscribe
bool unsubscribe(const std::string &topic)
Unsubscribes from given topic.