Client for simple MQTT communication.
More...
#include <MQTT.h>
|
| MQTTClient (TransportLayer *tl, uint16_t port=1883) |
| Default constructor. More...
|
|
int16_t | connect (const char *host, const char *clientId, const char *userName="", const char *password="", uint16_t keepAlive=60, bool cleanSession=true, const char *willTopic="", const char *willMessage="") |
| Connects to MQTT broker (/server). More...
|
|
int16_t | disconnect () |
| Disconnect from MQTT broker. More...
|
|
int16_t | publish (String &topic, String &message) |
| Publish MQTT message. More...
|
|
int16_t | publish (const char *topic, const char *message) |
| Publish MQTT message. More...
|
|
int16_t | subscribe (const char *topicFilter) |
| Subscribe to MQTT topic. More...
|
|
int16_t | unsubscribe (const char *topicFilter) |
| Unsubscribe from MQTT topic. More...
|
|
int16_t | ping () |
| Ping MQTT broker. This method can be used to keep connection open. More...
|
|
int16_t | check (void(*func)(const char *, const char *)) |
| Set function to be called when checking new messages in subscribed topics. More...
|
|
Client for simple MQTT communication.
◆ MQTTClient()
Default constructor.
- Parameters
-
tl | Pointer to the wireless module providing TransportLayer communication. |
◆ check()
int16_t MQTTClient::check |
( |
void(*)(const char *, const char *) |
func | ) |
|
Set function to be called when checking new messages in subscribed topics.
- Returns
- Status Codes
◆ connect()
int16_t MQTTClient::connect |
( |
const char * |
host, |
|
|
const char * |
clientId, |
|
|
const char * |
userName = "" , |
|
|
const char * |
password = "" , |
|
|
uint16_t |
keepAlive = 60 , |
|
|
bool |
cleanSession = true , |
|
|
const char * |
willTopic = "" , |
|
|
const char * |
willMessage = "" |
|
) |
| |
Connects to MQTT broker (/server).
- Parameters
-
host | URL of the MQTT broker. |
clientId | ID of the client. |
username | Username to be used in the connection. Defaults to empty string (no username). |
password | Password to be used in the connection. Defaults to empty string (no password). |
keepAlive | Connection keep-alive period in seconds. Defaults to 60. |
cleanSession | MQTT CleanSession flag. Defaults to true. |
willTopic | MQTT will topic. Defaults to empty string (no will topic). |
willMessage | MQTT will message. Defaults to empty string (no will message). |
- Returns
- Status Codes
◆ disconnect()
int16_t MQTTClient::disconnect |
( |
| ) |
|
◆ ping()
int16_t MQTTClient::ping |
( |
| ) |
|
Ping MQTT broker. This method can be used to keep connection open.
- Returns
- Status Codes
◆ publish() [1/2]
int16_t MQTTClient::publish |
( |
String & |
topic, |
|
|
String & |
message |
|
) |
| |
Publish MQTT message.
- Parameters
-
topic | MQTT topic to which the message will be published. |
message | Message to be published. |
- Returns
- Status Codes
◆ publish() [2/2]
int16_t MQTTClient::publish |
( |
const char * |
topic, |
|
|
const char * |
message |
|
) |
| |
Publish MQTT message.
- Parameters
-
topic | MQTT topic to which the message will be published. |
message | Message to be published. |
- Returns
- Status Codes
- Todo:
- implement QoS > 0 and PUBACK response checking
◆ subscribe()
int16_t MQTTClient::subscribe |
( |
const char * |
topicFilter | ) |
|
Subscribe to MQTT topic.
- Parameters
-
topicFilter | Topic to subscribe to. |
- Returns
- Status Codes
◆ unsubscribe()
int16_t MQTTClient::unsubscribe |
( |
const char * |
topicFilter | ) |
|
Unsubscribe from MQTT topic.
- Parameters
-
topicFilter | Topic to unsubscribe from. |
- Returns
- Status Codes
The documentation for this class was generated from the following files:
- src/protocols/MQTT/MQTT.h
- src/protocols/MQTT/MQTT.cpp