MQTT Client interface that contains the method that a class that can be used to send and receive data over an MQTT connection should implement.
More...
|
| virtual | ~IMQTT_Client () |
| | Virtual default destructor, created to ensure that if a pointer to this class is used and deleted, we will also call the derived base class destructor. More...
|
| |
| 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. More...
|
| |
| 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 broker. More...
|
| |
| 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. More...
|
| |
| virtual uint16_t | get_receive_buffer_size ()=0 |
| | Gets the previously set size of the internal buffer size meant for incoming MQTT data. More...
|
| |
| virtual uint16_t | get_send_buffer_size ()=0 |
| | Gets the previously set size of the internal buffer size meant for outgoing MQTT data. More...
|
| |
| virtual void | set_server (char const *domain, uint16_t port)=0 |
| | Configures the server and port that the client should connect with over MQTT. More...
|
| |
| 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 credentials. More...
|
| |
| virtual void | disconnect ()=0 |
| | Force disconnects from the previously connected server and should release all used resources. More...
|
| |
| virtual bool | loop ()=0 |
| | Receives / sends any outstanding messages from and to the MQTT broker. More...
|
| |
| virtual bool | publish (char const *topic, uint8_t const *payload, size_t const &length)=0 |
| | Sends the given payload over the previously established connection. More...
|
| |
| 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 each message received on that topic from the server, it should then, call the previously configured callback with set_data_callback() with the received data. More...
|
| |
| virtual bool | unsubscribe (char const *topic)=0 |
| | Unsubscribes to previously subscribed MQTT messages of the given topic. More...
|
| |
| virtual bool | connected ()=0 |
| | Returns our current connection status to MQTT, true meaning we are connected, false meaning we have been disconnected or have not established a connection yet. More...
|
| |
| virtual MQTT_Connection_State | get_connection_state () const =0 |
| | Get the current connection state to the server includes possible intermediate states between connecting and disconnecting. More...
|
| |
| 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 broker. More...
|
| |
| 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 broker changes. More...
|
| |
MQTT Client interface that contains the method that a class that can be used to send and receive data over an MQTT connection should implement.
- Note
- Seperates the specific implementation used from the ThingsBoard client, allows to use different clients depending on different needs. In this case the main use case of the seperation is to both support Espressif IDF and Arduino with the following libraries as recommendations. The default MQTT Client for Arduino is the PubSubClient forked from ThingsBoard (https://github.com/thingsboard/pubsubclient), it includes fixes to solve issues with using std::function callbacks for non ESP boards. For Espressif IDF however the default MQTT Client is the esp-mqtt (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/protocols/mqtt.html) component. The aforementioned recommendations are already implemented in the library and can can simply be used and included when using the library, for Arduino the Arduino_MQTT_Client can simply be included and for Espressif IDF the Espressif_MQTT_Client can simply be included, the implementations have been tested and should be compatible when used in conjunction with the ThingsBoard client. Alternatively when using Arduino it is possible to enable support for THINGSBOARD_ENABLE_STREAM_UTILS by importing the ArduinoStreamUtils (https://github.com/bblanchon/ArduinoStreamUtils) in the project. This feature allows to improve the underlying data streams by directly writing the data into the MQTT Client instead of into an output buffer, but writing each byte one by one, would be too slow, therefore the ArduinoStreamUtils (https://github.com/bblanchon/ArduinoStreamUtils) library is used to buffer those calls into bigger packets. This allows sending data that is very big without requiring to allocate that much memory, because it is sent in smaller packets. To support this feature, however this interface needs to additionally implement the Print interface, because that is required by the wrapper class BufferingPrint, which only exists on Arduino This then allows to send arbitrary size payloads if that is done the internal buffer of the MQTT Client implementation can theoretically set the value as big as the buffering_size passed to the constructor + enough memory to hold the topic and MQTT Header ~= 20 bytes. This will mean though that all messages are sent over the StreamUtils library as long as they are bigger than the internal send buffer size, which needs more time than sending a message directly but has the advantage of requiring less memory