ThingsBoard Client SDK 0.16.0
Client SDK to connect with ThingsBoard IoT Platform from IoT devices (Arduino, Espressif, etc.)
Loading...
Searching...
No Matches
IMQTT_Client.h
Go to the documentation of this file.
1#ifndef IMQTT_Client_h
2#define IMQTT_Client_h
3
4// Local include.
5#include "Callback.h"
6#include "DefaultLogger.h"
9
10// Library include.
11#if THINGSBOARD_ENABLE_STREAM_UTILS
12#include <Print.h>
13#endif // THINGSBOARD_ENABLE_STREAM_UTILS
14
15
33#if THINGSBOARD_ENABLE_STREAM_UTILS
34class IMQTT_Client : public Print {
35#else
37#endif // THINGSBOARD_ENABLE_STREAM_UTILS
38 public:
40 virtual ~IMQTT_Client() {}
41
48
54
74 virtual bool set_buffer_size(uint16_t receive_buffer_size, uint16_t send_buffer_size) = 0;
75
78 virtual uint16_t get_receive_buffer_size() = 0;
79
82 virtual uint16_t get_send_buffer_size() = 0;
83
95 virtual void set_server(char const * domain, uint16_t port) = 0;
96
105 virtual bool connect(char const * client_id, char const * user_name, char const * password) = 0;
106
109 virtual void disconnect() = 0;
110
119 virtual bool loop() = 0;
120
127 virtual bool publish(char const * topic, uint8_t const * payload, size_t const & length) = 0;
128
135 virtual bool subscribe(char const * topic) = 0;
136
142 virtual bool unsubscribe(char const * topic) = 0;
143
147 virtual bool connected() = 0;
148
155
160
167
168#if THINGSBOARD_ENABLE_STREAM_UTILS
169
177 virtual bool begin_publish(char const * topic, size_t const & length) = 0;
178
181 virtual bool end_publish() = 0;
182
183 //----------------------------------------------------------------------------
184 // Print interface
185 //----------------------------------------------------------------------------
186
193 virtual size_t write(uint8_t payload_byte) = 0;
194
201 virtual size_t write(uint8_t const * buffer, size_t const & size) = 0;
202
203#endif // THINGSBOARD_ENABLE_STREAM_UTILS
204};
205
206#endif // IMQTT_Client_h
MQTT_Connection_Error
Possible error states the MQTT broker connection can be in, if connecting the device to the MQTT brok...
Definition: MQTT_Connection_Error.h:9
MQTT_Connection_State
Possible states the MQTT broker connection can be in.
Definition: MQTT_Connection_State.h:11
std::function< return_type(argument_types... arguments)> function
Callback signature.
Definition: Callback.h:34
MQTT Client interface that contains the method that a class that can be used to send and receive data...
Definition: IMQTT_Client.h:36
virtual void disconnect()=0
Force disconnects from the previously connected server and should release all used resources.
virtual ~IMQTT_Client()
Virtual default destructor, created to ensure that if a pointer to this class is used and deleted,...
Definition: IMQTT_Client.h:40
virtual bool loop()=0
Receives / sends any outstanding messages from and to the MQTT broker.
virtual bool connect(char const *client_id, char const *user_name, char const *password)=0
Connects to the previously with set_server configured server instance and port with the given credent...
virtual void subscribe_connection_state_changed_callback(Callback< void, MQTT_Connection_State, MQTT_Connection_Error >::function callback)=0
Sets the callback that is called, whenever the underlying state of our connection with the MQTT broke...
virtual MQTT_Connection_Error get_last_connection_error() const =0
Allows to deciper the reason for a failure, while attempting to establish a connection to the MQTT br...
virtual uint16_t get_receive_buffer_size()=0
Gets the previously set size of the internal buffer size meant for incoming MQTT data.
virtual void set_data_callback(Callback< void, char *, uint8_t *, unsigned int >::function callback)=0
Sets the callback that is called, if any message is received by the MQTT broker.
virtual bool unsubscribe(char const *topic)=0
Unsubscribes to previously subscribed MQTT messages of the given topic.
virtual bool set_buffer_size(uint16_t receive_buffer_size, uint16_t send_buffer_size)=0
Changes the size of the buffer for sent and received MQTT messages.
virtual MQTT_Connection_State get_connection_state() const =0
Get the current connection state to the server includes possible intermediate states between connecti...
virtual void set_server(char const *domain, uint16_t port)=0
Configures the server and port that the client should connect with over MQTT.
virtual bool publish(char const *topic, uint8_t const *payload, size_t const &length)=0
Sends the given payload over the previously established connection.
virtual uint16_t get_send_buffer_size()=0
Gets the previously set size of the internal buffer size meant for outgoing MQTT data.
virtual bool connected()=0
Returns our current connection status to MQTT, true meaning we are connected, false meaning we have b...
virtual bool subscribe(char const *topic)=0
Subscribes to MQTT message on the given topic, which will cause an internal callback to be called for...
virtual void set_connect_callback(Callback< void >::function callback)=0
Sets the callback that is called, if we have successfully established a connection with the MQTT brok...