RadioLib
Universal wireless communication library for Arduino
MQTTClient Class Reference

Client for simple MQTT communication. More...

#include <MQTT.h>

Public Member Functions

 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...
 

Detailed Description

Client for simple MQTT communication.

Constructor & Destructor Documentation

◆ MQTTClient()

MQTTClient::MQTTClient ( TransportLayer tl,
uint16_t  port = 1883 
)
explicit

Default constructor.

Parameters
tlPointer to the wireless module providing TransportLayer communication.

Member Function Documentation

◆ 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
hostURL of the MQTT broker.
clientIdID of the client.
usernameUsername to be used in the connection. Defaults to empty string (no username).
passwordPassword to be used in the connection. Defaults to empty string (no password).
keepAliveConnection keep-alive period in seconds. Defaults to 60.
cleanSessionMQTT CleanSession flag. Defaults to true.
willTopicMQTT will topic. Defaults to empty string (no will topic).
willMessageMQTT will message. Defaults to empty string (no will message).
Returns
Status Codes

◆ disconnect()

int16_t MQTTClient::disconnect ( )

Disconnect from MQTT broker.

Returns
Status Codes

◆ 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
topicMQTT topic to which the message will be published.
messageMessage to be published.
Returns
Status Codes

◆ publish() [2/2]

int16_t MQTTClient::publish ( const char *  topic,
const char *  message 
)

Publish MQTT message.

Parameters
topicMQTT topic to which the message will be published.
messageMessage 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
topicFilterTopic to subscribe to.
Returns
Status Codes

◆ unsubscribe()

int16_t MQTTClient::unsubscribe ( const char *  topicFilter)

Unsubscribe from MQTT topic.

Parameters
topicFilterTopic to unsubscribe from.
Returns
Status Codes

The documentation for this class was generated from the following files: