#include <MqttClient.h>
Public Member Functions | |
MqttClient (bool withDefaultPayloadParser=true, bool autoDestruct=false) | |
~MqttClient () | |
void | setKeepAlive (uint16_t seconds) |
Sets keep-alive time. That information is sent during connection to the server. More... | |
void | setPingRepeatTime (uint16_t seconds) |
bool | setWill (const String &topic, const String &message, uint8_t flags=0) |
bool | connect (const Url &url, const String &uniqueClientName) |
Connect to a MQTT server. More... | |
bool | publish (const String &topic, const String &message, uint8_t flags=0) |
Publish a message. More... | |
bool | publish (const String &topic, IDataSourceStream *stream, uint8_t flags=0) |
Publish a message. More... | |
bool | subscribe (const String &topic) |
Subscribe to a topic. More... | |
bool | unsubscribe (const String &topic) |
Unsubscribe from a topic. More... | |
void | setEventHandler (mqtt_type_t type, MqttDelegate handler) |
Register a callback function to be invoked on incoming event notification. More... | |
void | setPayloadParser (MqttPayloadParser payloadParser=nullptr) |
Sets or clears a payload parser (for PUBLISH messages from the server to us) More... | |
void | setConnectedHandler (MqttDelegate handler) |
Sets a handler to be called after successful MQTT connection. More... | |
void | setPublishedHandler (MqttDelegate handler) |
Sets a handler to be called after receiving confirmation from the server for a published message from the client. More... | |
void | setMessageHandler (MqttDelegate handler) |
Sets a handler to be called after receiving a PUBLISH message from the server. More... | |
void | setDisconnectHandler (TcpClientCompleteDelegate handler) |
Sets a handler to be called on disconnect from the server. More... | |
void | setCompleteDelegate (TcpClientCompleteDelegate completeCb=nullptr) |
Set or clear the callback for connection close. More... | |
TcpClientState | getConnectionState () |
bool | isProcessing () |
Static Public Member Functions | |
static uint8_t | getFlags (mqtt_qos_t QoS, mqtt_retain_t retain=MQTT_RETAIN_FALSE, mqtt_dup_t dup=MQTT_DUP_FALSE) |
Compute the flags value. More... | |
Protected Member Functions | |
void | onReadyToSendData (TcpConnectionEvent sourceEvent) override |
void | onFinished (TcpClientState finishState) override |
![]() | |
err_t | onConnected (err_t err) override |
err_t | onReceive (pbuf *buf) override |
err_t | onSent (uint16_t len) override |
void | onError (err_t err) override |
void | onClosed () override |
Gets called when there is/was a tcp connection, the latter does not have to be established, that is closed due to error or normal disconnect. More... | |
void | onReadyToSendData (TcpConnectionEvent sourceEvent) override |
void | pushAsyncPart () |
void | freeStreams () |
TcpClient (bool autoDestruct) | |
TcpClient (tcp_pcb *clientTcp, TcpClientDataDelegate clientReceive, TcpClientCompleteDelegate onCompleted) | |
TcpClient (TcpClientCompleteDelegate onCompleted, TcpClientEventDelegate onReadyToSend, TcpClientDataDelegate onReceive=nullptr) | |
TcpClient (TcpClientCompleteDelegate onCompleted, TcpClientDataDelegate onReceive=nullptr) | |
TcpClient (TcpClientDataDelegate onReceive) | |
~TcpClient () | |
bool | connect (const String &server, int port, bool useSsl=false) override |
bool | connect (IpAddress addr, uint16_t port, bool useSsl=false) override |
void | close () override |
void | setReceiveDelegate (TcpClientDataDelegate receiveCb=nullptr) |
Set or clear the callback for received data. More... | |
void | setCompleteDelegate (TcpClientCompleteDelegate completeCb=nullptr) |
Set or clear the callback for connection close. More... | |
bool | send (const char *data, uint16_t len, bool forceCloseAfterSent=false) |
bool | sendString (const String &data, bool forceCloseAfterSent=false) |
bool | send (IDataSourceStream *source, bool forceCloseAfterSent=false) |
Sends data stream. More... | |
bool | isProcessing () |
TcpClientState | getConnectionState () |
void | setCloseAfterSent (bool ignoreIncomingData=false) |
void | commit () |
Tries to send the pending data immediately. More... | |
![]() | |
void | initialize (tcp_pcb *pcb) |
bool | internalConnect (IpAddress addr, uint16_t port) |
bool | sslCreateSession () |
virtual void | sslInitSession (Ssl::Session &session) |
Override in inherited classes to perform custom session initialisation. More... | |
virtual err_t | onPoll () |
void | trySend (TcpConnectionEvent event) |
err_t | internalOnConnected (err_t err) |
err_t | internalOnReceive (pbuf *p, err_t err) |
err_t | internalOnSent (uint16_t len) |
err_t | internalOnPoll () |
void | internalOnError (err_t err) |
void | internalOnDnsResponse (const char *name, LWIP_IP_ADDR_T *ipaddr, int port) |
TcpConnection (bool autoDestruct) | |
TcpConnection (tcp_pcb *connection, bool autoDestruct) | |
virtual | ~TcpConnection () |
void | setAutoSelfDestruct (bool state) |
int | writeString (const char *data, uint8_t apiflags=TCP_WRITE_FLAG_COPY) |
Writes string data directly to the TCP buffer. More... | |
int | writeString (const String &data, uint8_t apiflags=TCP_WRITE_FLAG_COPY) |
Writes string data directly to the TCP buffer. More... | |
virtual int | write (const char *data, int len, uint8_t apiflags=TCP_WRITE_FLAG_COPY) |
Base write operation. More... | |
int | write (IDataSourceStream *stream) |
Writes stream data directly to the TCP buffer. More... | |
uint16_t | getAvailableWriteSize () |
void | flush () |
void | setTimeOut (uint16_t waitTimeOut) |
IpAddress | getRemoteIp () const |
uint16_t | getRemotePort () const |
void | setDestroyedDelegate (TcpConnectionDestroyedDelegate destroyedDelegate) |
Sets a callback to be called when the object instance is destroyed. More... | |
void | setSslInitHandler (Ssl::Session::InitDelegate handler) |
Set the SSL session initialisation callback. More... | |
bool | setSslConnection (Ssl::Connection *connection) |
Ssl::Session * | getSsl () |
Get a pointer to the current SSL session object. More... | |
![]() | |
bool | joinMulticastGroup (IpAddress localIp, IpAddress multicastIp) |
Uses IGMP to add a local network interface to multicast group. More... | |
bool | joinMulticastGroup (IpAddress multicastIp) |
Uses IGMP to add all local network interfaces to multicast group. More... | |
bool | leaveMulticastGroup (IpAddress localIp, IpAddress multicastIp) |
Uses IGMP to remove a local network interface from multicast group. More... | |
bool | leaveMulticastGroup (IpAddress multicastIp) |
Uses IGMP to remove all local network interfaces from multicast group. More... | |
Additional Inherited Members | |
![]() | |
IDataSourceStream * | stream = nullptr |
The currently active stream being sent. More... | |
![]() | |
tcp_pcb * | tcp = nullptr |
uint16_t | sleep = 0 |
uint16_t | timeOut = USHRT_MAX |
By default a TCP connection does not have a time out. More... | |
bool | canSend = true |
bool | autoSelfDestruct = true |
Ssl::Session * | ssl = nullptr |
Ssl::Session::InitDelegate | sslInit |
bool | useSsl = false |
Constructor & Destructor Documentation
◆ MqttClient()
MqttClient::MqttClient | ( | bool | withDefaultPayloadParser = true , |
bool | autoDestruct = false |
||
) |
◆ ~MqttClient()
MqttClient::~MqttClient | ( | ) |
Member Function Documentation
◆ connect()
Connect to a MQTT server.
- Parameters
-
url URL in the form "mqtt://user:password@server:port" or "mqtts://user:password@server:port" uniqueClientName
- Return values
-
bool
◆ getConnectionState()
|
inline |
◆ getFlags()
|
inlinestatic |
Compute the flags value.
- Parameters
-
QoS - Quality of Service retain - Retain flag dup - Duplicate delivery
- Return values
-
uint8_t calculated flags value
◆ isProcessing()
|
inline |
◆ onFinished()
|
overrideprotectedvirtual |
Reimplemented from TcpClient.
◆ onReadyToSendData()
|
overrideprotectedvirtual |
Reimplemented from TcpConnection.
◆ publish() [1/2]
Publish a message.
- Parameters
-
topic message Message content as String flags Optional flags
- Return values
-
bool
◆ publish() [2/2]
bool MqttClient::publish | ( | const String & | topic, |
IDataSourceStream * | stream, | ||
uint8_t | flags = 0 |
||
) |
Publish a message.
- Parameters
-
topic message Message content as read-only stream flags Optional flags
- Return values
-
bool
◆ setCompleteDelegate()
|
inline |
Set or clear the callback for connection close.
- Parameters
-
completeCb callback delegate or nullptr
◆ setConnectedHandler()
|
inline |
Sets a handler to be called after successful MQTT connection.
- Parameters
-
handler
◆ setDisconnectHandler()
|
inline |
Sets a handler to be called on disconnect from the server.
- Parameters
-
handler
◆ setEventHandler()
|
inline |
Register a callback function to be invoked on incoming event notification.
- Parameters
-
type Type of event to be notified of handler The callback. Pass nullptr to cancel callback.
◆ setKeepAlive()
|
inline |
Sets keep-alive time. That information is sent during connection to the server.
- Parameters
-
seconds
◆ setMessageHandler()
|
inline |
Sets a handler to be called after receiving a PUBLISH message from the server.
- Parameters
-
handler
◆ setPayloadParser()
|
inline |
Sets or clears a payload parser (for PUBLISH messages from the server to us)
- Note
- We no longer have size limitation for incoming or outgoing messages but in order to prevent running out of memory we have a "sane" payload parser that will read up to 1K of payload
◆ setPingRepeatTime()
|
inline |
Sets the interval in which to ping the remote server if there was no activity
- Parameters
-
seconds
◆ setPublishedHandler()
|
inline |
Sets a handler to be called after receiving confirmation from the server for a published message from the client.
- Parameters
-
handler
◆ setWill()
Sets last will and testament
- Parameters
-
topic message flags QoS, retain, etc flags
- Return values
-
bool
◆ subscribe()
bool MqttClient::subscribe | ( | const String & | topic | ) |
Subscribe to a topic.
- Parameters
-
topic
- Return values
-
bool
◆ unsubscribe()
bool MqttClient::unsubscribe | ( | const String & | topic | ) |
Unsubscribe from a topic.
- Parameters
-
topic
- Return values
-
bool
The documentation for this class was generated from the following file: