Connectino Library
ConnectinoMqtt.h
1 #ifndef ConnectinoMqtt_h
2 #define ConnectinoMqtt_h
3 
4 #include "ConnectinoModule.h"
5 #include "StxHwSerial.h"
6 
16 {
17  public:
22  ConnectinoMqtt(StxHwSerial &refSerial);
23 
33  bool moduleCallback(uint8_t subId, uint8_t reqId, uint16_t dataSize, uint8_t *data);
34 
40  uint8_t getModId();
41 
60  bool setSessionConfiguration(const char server[], uint16_t port, const char resource[] = "", const char clientId[] = "",
61  const char userName[] = "", const char password[] = "", uint8_t connectionType = 0, bool cleanSession = true,
62  uint16_t keepaliveInterval = 60);
63 
76  void setWill(const char topic[], const char payload[], const bool retain = false, const uint8_t QoS = 0);
77 
91  void setWill(const char topic[], const uint8_t payload[], const uint8_t payloadSize, const bool retain = false, const uint8_t QoS = 0);
92 
105  bool publish(const char topic[], const char payload[], const bool retain = false, const uint8_t QoS = 0);
106 
120  bool publish(const char topic[], const uint8_t payload[], const uint16_t payloadSize, const bool retain = false, const uint8_t QoS = 0);
121 
134  void subscribe(const char topic[], const uint8_t QoS = 0);
135 
144  bool isDataAvailable(const char * topic = NULL);
145 
157  bool getData(char * payloadBuffer, uint16_t &payloadBufferSize, char * topicBuffer = NULL, uint16_t topicBufferSize = 0);
158 
170  bool getData(uint8_t * payloadBuffer, uint16_t &payloadBufferSize, char * topicBuffer = NULL, uint16_t topicBufferSize = 0);
171 
176  bool isConnected();
177 
185  void setState(bool state);
186 
187  private:
199  bool parseData(uint8_t ** topic, uint8_t * topicSize, uint8_t ** payload = NULL, uint16_t * payloadSize = NULL);
200 
201  StxHwSerial &StxSerial;
202  volatile bool setSessionConfiguration_done = false;
203  volatile bool setWill_done = false;
204  volatile bool subscribe_done = false;
205  volatile bool subscribed = false;
206  volatile bool connected = false;
207  volatile bool setState_done = false;
208  volatile bool dataAvailable = false;
209 };
210 
211 #endif
bool getData(char *payloadBuffer, uint16_t &payloadBufferSize, char *topicBuffer=NULL, uint16_t topicBufferSize=0)
Receive data from the message buffer.
Definition: ConnectinoMqtt.cpp:274
bool moduleCallback(uint8_t subId, uint8_t reqId, uint16_t dataSize, uint8_t *data)
Callback function for serial frames of the MQTT module.
Definition: ConnectinoMqtt.cpp:12
bool setSessionConfiguration(const char server[], uint16_t port, const char resource[]="", const char clientId[]="", const char userName[]="", const char password[]="", uint8_t connectionType=0, bool cleanSession=true, uint16_t keepaliveInterval=60)
Set the session configuration.
Definition: ConnectinoMqtt.cpp:91
void setWill(const char topic[], const char payload[], const bool retain=false, const uint8_t QoS=0)
Set a string as the last will.
Definition: ConnectinoMqtt.cpp:128
bool isConnected()
Check connection of the MQTT module.
Definition: ConnectinoMqtt.cpp:200
ConnectinoMqtt(StxHwSerial &refSerial)
MQTT module constructor.
Definition: ConnectinoMqtt.cpp:5
void setState(bool state)
Set the state of the MQTT module.
Definition: ConnectinoMqtt.cpp:64
MQTT module.
Definition: ConnectinoMqtt.h:15
bool isDataAvailable(const char *topic=NULL)
Check for available data.
Definition: ConnectinoMqtt.cpp:255
bool publish(const char topic[], const char payload[], const bool retain=false, const uint8_t QoS=0)
Publish a string on a topic.
Definition: ConnectinoMqtt.cpp:204
void subscribe(const char topic[], const uint8_t QoS=0)
Subscribe to a topic.
Definition: ConnectinoMqtt.cpp:162
uint8_t getModId()
Get the ID of the MQTT module.
Definition: ConnectinoMqtt.cpp:8
Binuart module.
Definition: ConnectinoModule.h:10