Instantiate a new AsyncMqttClient object.
Set the keep alive. Defaults to 15 seconds.
keepAlive
: Keep alive in seconds
Set the client ID. Defaults to esp8266<chip ID on 6 hex caracters>
.
clientId
: Client ID
Whether or not to set the CleanSession flag. Defaults to true
.
cleanSession
: clean session wanted or not
Set the maximum allowed topic length to receive. If an MQTT packet is received
with a topic longer than this maximum, the packet will be ignored. Defaults to 128
.
maxTopicLength
: Maximum allowed topic length to receive
Set the username/password. Defaults to non-auth.
username
: Usernamepassword
: Password
AsyncMqttClient& setWill(const char* topic
, uint8_t qos
, bool retain
, const char* payload
= nullptr, size_t length
= 0)
Set the Last Will Testament. Defaults to none.
topic
: Topic of the LWTqos
: QoS of the LWTretain
: Retain flag of the LWTpayload
: Payload of the LWT. If unset, the payload will be emptylength
: Payload length. If unset or set to 0, the payload will be considered as a string and its size will be calculated usingstrlen(payload)
Set the server.
ip
: IP of the serverport
: Port of the server
Set the server.
host
: Host of the serverport
: Port of the server
Whether or not to use SSL. Defaults to false
.
secure
: SSL wanted or not.
Adds an acceptable server fingerprint (SHA1). This may be called multiple times to permit any one of the specified fingerprints. By default, if no fingerprint is added, any fingerprint is accepted.
fingerprint
: Fingerprint to add
Add a connect event handler.
callback
: Function to call
Add a disconnect event handler.
callback
: Function to call
Add a subscribe acknowledged event handler.
callback
: Function to call
Add an unsubscribe acknowledged event handler.
callback
: Function to call
Add a publish received event handler.
callback
: Function to call
Add a publish acknowledged event handler.
callback
: Function to call
Return if the client is currently connected to the broker or not.
Connect to the server.
Disconnect from the server.
force
: Whether to force the disconnection. Defaults tofalse
(clean disconnection).
Subscribe to the given topic at the given QoS.
Return the packet ID or 0 if failed.
topic
: Topicqos
: QoS
Unsubscribe from the given topic.
Return the packet ID or 0 if failed.
topic
: Topic
uint16_t publish(const char* topic
, uint8_t qos
, bool retain
, const char* payload
= nullptr, size_t length
= 0, bool dup = false, uint16_t message_id = 0)
Publish a packet.
Return the packet ID (or 1 if QoS 0) or 0 if failed.
topic
: Topicqos
: QoSretain
: Retain flagpayload
: Payload. If unset, the payload will be emptylength
: Payload length. If unset or set to 0, the payload will be considered as a string and its size will be calculated usingstrlen(payload)
dup
:Duplicate flag. If set or set to 1, the payload will be flagged as a duplicateSetting is not used anymoremessage_id
:The message ID. If unset or set to 0, the message ID will be automtaically assigned. Use this with the DUP flag to identify which message is being duplicatedSetting is not used anymore
When disconnected, clears all queued messages
Returns true on succes, false on failure (client is no disconnected)