PubSubClient3 v3.1.0
Located at <a href='https://github.com/hmueller01/pubsubclient3'>GitHub</a>
 
Loading...
Searching...
No Matches
PubSubClient Class Reference

This class provides a client for doing simple publish and subscribe messaging with a server that supports MQTT. More...

#include <PubSubClient.h>

Inheritance diagram for PubSubClient:

Public Member Functions

 PubSubClient ()
 Creates an uninitialised client instance.
 
 PubSubClient (Client &client)
 Creates a partially initialised client instance.
 
 PubSubClient (IPAddress addr, uint16_t port, Client &client)
 Creates a fully configured client instance.
 
 PubSubClient (IPAddress addr, uint16_t port, Client &client, Stream &stream)
 Creates a fully configured client instance.
 
 PubSubClient (IPAddress addr, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client &client)
 Creates a fully configured client instance.
 
 PubSubClient (IPAddress addr, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client &client, Stream &stream)
 Creates a fully configured client instance.
 
 PubSubClient (uint8_t *ip, uint16_t port, Client &client)
 Creates a fully configured client instance.
 
 PubSubClient (uint8_t *ip, uint16_t port, Client &client, Stream &stream)
 Creates a fully configured client instance.
 
 PubSubClient (uint8_t *ip, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client &client)
 Creates a fully configured client instance.
 
 PubSubClient (uint8_t *ip, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client &client, Stream &stream)
 Creates a fully configured client instance.
 
 PubSubClient (const char *domain, uint16_t port, Client &client)
 Creates a fully configured client instance.
 
 PubSubClient (const char *domain, uint16_t port, Client &client, Stream &stream)
 Creates a fully configured client instance.
 
 PubSubClient (const char *domain, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client &client)
 Creates a fully configured client instance.
 
 PubSubClient (const char *domain, uint16_t port, MQTT_CALLBACK_SIGNATURE, Client &client, Stream &stream)
 Creates a fully configured client instance.
 
 ~PubSubClient ()
 Destructor for the PubSubClient class.
 
PubSubClientsetServer (IPAddress ip, uint16_t port)
 Sets the server details.
 
PubSubClientsetServer (uint8_t *ip, uint16_t port)
 Sets the server details.
 
PubSubClientsetServer (const char *domain, uint16_t port)
 Sets the server details.
 
PubSubClientsetCallback (MQTT_CALLBACK_SIGNATURE)
 Sets the message callback function.
 
PubSubClientsetClient (Client &client)
 Sets the network client instance to use.
 
PubSubClientsetStream (Stream &stream)
 Sets the stream to write received messages to.
 
PubSubClientsetKeepAlive (uint16_t keepAlive)
 Sets the keep alive interval used by the client. This value should only be changed when the client is not connected. Set keepAlive to zero (0) to turn off the keep alive mechanism.
 
PubSubClientsetSocketTimeout (uint16_t timeout)
 Sets the socket timeout used by the client. This determines how long the client will wait for incoming data when it expects data to arrive - for example, whilst it is in the middle of reading a MQTT packet.
 
bool setBufferSize (size_t size)
 Sets the size, in bytes, of the internal send and receive buffer. This must be large enough to contain the full MQTT packet. When sending or receiving messages, the packet will contain the full topic string, the payload data, and a small number of header bytes.
 
size_t getBufferSize ()
 Gets the current size of the internal buffer.
 
bool connect (const char *id)
 Connects the client using a clean session without username and password.
 
bool connect (const char *id, const char *user, const char *pass)
 Connects the client using a clean session with username and password.
 
bool connect (const char *id, const char *willTopic, uint8_t willQos, bool willRetain, const char *willMessage)
 Connects the client using a clean session and will.
 
bool connect (const char *id, const char *user, const char *pass, const char *willTopic, uint8_t willQos, bool willRetain, const char *willMessage)
 Connects the client using a clean session with username, password and will.
 
bool connect (const char *id, const char *user, const char *pass, const char *willTopic, uint8_t willQos, bool willRetain, const char *willMessage, bool cleanSession)
 Connects the client with all possible parameters (user, password, will and session).
 
void disconnect ()
 Disconnects the client.
 
bool publish (const char *topic, const char *payload)
 Publishes a non retained message to the specified topic using QoS 0.
 
bool publish (const char *topic, const char *payload, bool retained)
 Publishes a message to the specified topic using QoS 0.
 
bool publish (const char *topic, const char *payload, uint8_t qos, bool retained)
 Publishes a message to the specified topic.
 
bool publish (const char *topic, const uint8_t *payload, size_t plength)
 Publishes a non retained message to the specified topic using QoS 0.
 
bool publish (const char *topic, const uint8_t *payload, size_t plength, bool retained)
 Publishes a message to the specified topic using QoS 0.
 
bool publish (const char *topic, const uint8_t *payload, size_t plength, uint8_t qos, bool retained)
 Publishes a message to the specified topic.
 
bool publish_P (const char *topic, const char *payload, bool retained)
 Publishes a message stored in PROGMEM to the specified topic using QoS 0.
 
bool publish_P (const char *topic, const char *payload, uint8_t qos, bool retained)
 Publishes a message stored in PROGMEM to the specified topic.
 
bool publish_P (const char *topic, const uint8_t *payload, size_t plength, bool retained)
 Publishes a message stored in PROGMEM to the specified topic using QoS 0.
 
bool publish_P (const char *topic, const uint8_t *payload, size_t plength, uint8_t qos, bool retained)
 Publishes a message stored in PROGMEM to the specified topic.
 
bool beginPublish (const char *topic, size_t plength, bool retained)
 Start to publish a message using QoS 0. This API: beginPublish(...) one or more calls to write(...) endPublish() Allows for arbitrarily large payloads to be sent without them having to be copied into a new buffer and held in memory at one time.
 
bool beginPublish (const char *topic, size_t plength, uint8_t qos, bool retained)
 Start to publish a message. This API: beginPublish(...) one or more calls to write(...) endPublish() Allows for arbitrarily large payloads to be sent without them having to be copied into a new buffer and held in memory at one time.
 
bool endPublish ()
 Finish sending a message that was started with a call to beginPublish.
 
virtual size_t write (uint8_t data)
 Writes a single byte as a component of a publish started with a call to beginPublish.
 
virtual size_t write (const uint8_t *buffer, size_t size)
 Writes an array of bytes as a component of a publish started with a call to beginPublish.
 
bool subscribe (const char *topic)
 Subscribes to messages published to the specified topic using QoS 0.
 
bool subscribe (const char *topic, uint8_t qos)
 Subscribes to messages published to the specified topic.
 
bool unsubscribe (const char *topic)
 Unsubscribes from the specified topic.
 
bool loop ()
 This should be called regularly to allow the client to process incoming messages and maintain its connection to the server.
 
bool connected ()
 Checks whether the client is connected to the server.
 
int state ()
 Returns the current state of the client. If a connection attempt fails, this can be used to get more information about the failure.
 

Detailed Description

This class provides a client for doing simple publish and subscribe messaging with a server that supports MQTT.

Definition at line 176 of file PubSubClient.h.

Constructor & Destructor Documentation

◆ PubSubClient() [1/14]

PubSubClient::PubSubClient ( )

Creates an uninitialised client instance.

Note
Before it can be used, it must be configured using the property setters setClient() and setServer().

Definition at line 26 of file PubSubClient.cpp.

◆ PubSubClient() [2/14]

PubSubClient::PubSubClient ( Client & client)

Creates a partially initialised client instance.

Parameters
clientThe network client to use, for example WiFiClient.
Note
Before it can be used, it must be configured with the property setter setServer().

Definition at line 32 of file PubSubClient.cpp.

◆ PubSubClient() [3/14]

PubSubClient::PubSubClient ( IPAddress addr,
uint16_t port,
Client & client )

Creates a fully configured client instance.

Parameters
addrThe address of the server.
portThe port to connect to.
clientThe network client to use, for example WiFiClient.

Definition at line 36 of file PubSubClient.cpp.

◆ PubSubClient() [4/14]

PubSubClient::PubSubClient ( IPAddress addr,
uint16_t port,
Client & client,
Stream & stream )

Creates a fully configured client instance.

Parameters
addrThe address of the server.
portThe port to connect to.
clientThe network client to use, for example WiFiClient.
streamA stream to write received messages to.

Definition at line 41 of file PubSubClient.cpp.

◆ PubSubClient() [5/14]

PubSubClient::PubSubClient ( IPAddress addr,
uint16_t port,
MQTT_CALLBACK_SIGNATURE ,
Client & client )

Creates a fully configured client instance.

Parameters
addrThe address of the server.
portThe port to connect to.
callbackPointer to a message callback function. Called when a message arrives for a subscription created by this client.
clientThe network client to use, for example WiFiClient.

Definition at line 47 of file PubSubClient.cpp.

◆ PubSubClient() [6/14]

PubSubClient::PubSubClient ( IPAddress addr,
uint16_t port,
MQTT_CALLBACK_SIGNATURE ,
Client & client,
Stream & stream )

Creates a fully configured client instance.

Parameters
addrThe address of the server.
portThe port to connect to.
callbackPointer to a message callback function. Called when a message arrives for a subscription created by this client.
clientThe network client to use, for example WiFiClient.
streamA stream to write received messages to.

Definition at line 53 of file PubSubClient.cpp.

◆ PubSubClient() [7/14]

PubSubClient::PubSubClient ( uint8_t * ip,
uint16_t port,
Client & client )

Creates a fully configured client instance.

Parameters
ipThe address of the server.
portThe port to connect to.
clientThe network client to use, for example WiFiClient.

Definition at line 60 of file PubSubClient.cpp.

◆ PubSubClient() [8/14]

PubSubClient::PubSubClient ( uint8_t * ip,
uint16_t port,
Client & client,
Stream & stream )

Creates a fully configured client instance.

Parameters
ipThe address of the server.
portThe port to connect to.
clientThe network client to use, for example WiFiClient.
streamA stream to write received messages to.

Definition at line 65 of file PubSubClient.cpp.

◆ PubSubClient() [9/14]

PubSubClient::PubSubClient ( uint8_t * ip,
uint16_t port,
MQTT_CALLBACK_SIGNATURE ,
Client & client )

Creates a fully configured client instance.

Parameters
ipThe address of the server.
portThe port to connect to.
callbackPointer to a message callback function. Called when a message arrives for a subscription created by this client.
clientThe network client to use, for example WiFiClient.

Definition at line 71 of file PubSubClient.cpp.

◆ PubSubClient() [10/14]

PubSubClient::PubSubClient ( uint8_t * ip,
uint16_t port,
MQTT_CALLBACK_SIGNATURE ,
Client & client,
Stream & stream )

Creates a fully configured client instance.

Parameters
ipThe address of the server.
portThe port to connect to.
callbackPointer to a message callback function. Called when a message arrives for a subscription created by this client.
clientThe network client to use, for example WiFiClient.
streamA stream to write received messages to.

Definition at line 77 of file PubSubClient.cpp.

◆ PubSubClient() [11/14]

PubSubClient::PubSubClient ( const char * domain,
uint16_t port,
Client & client )

Creates a fully configured client instance.

Parameters
domainThe address of the server.
portThe port to connect to.
clientThe network client to use, for example WiFiClient.

Definition at line 84 of file PubSubClient.cpp.

◆ PubSubClient() [12/14]

PubSubClient::PubSubClient ( const char * domain,
uint16_t port,
Client & client,
Stream & stream )

Creates a fully configured client instance.

Parameters
domainThe address of the server.
portThe port to connect to.
clientThe network client to use, for example WiFiClient.
streamA stream to write received messages to.

Definition at line 89 of file PubSubClient.cpp.

◆ PubSubClient() [13/14]

PubSubClient::PubSubClient ( const char * domain,
uint16_t port,
MQTT_CALLBACK_SIGNATURE ,
Client & client )

Creates a fully configured client instance.

Parameters
domainThe address of the server.
portThe port to connect to.
callbackPointer to a message callback function. Called when a message arrives for a subscription created by this client.
clientThe network client to use, for example WiFiClient.

Definition at line 95 of file PubSubClient.cpp.

◆ PubSubClient() [14/14]

PubSubClient::PubSubClient ( const char * domain,
uint16_t port,
MQTT_CALLBACK_SIGNATURE ,
Client & client,
Stream & stream )

Creates a fully configured client instance.

Parameters
domainThe address of the server.
portThe port to connect to.
callbackPointer to a message callback function. Called when a message arrives for a subscription created by this client.
clientThe network client to use, for example WiFiClient.
streamA stream to write received messages to.

Definition at line 101 of file PubSubClient.cpp.

◆ ~PubSubClient()

PubSubClient::~PubSubClient ( )

Destructor for the PubSubClient class.

Definition at line 108 of file PubSubClient.cpp.

Member Function Documentation

◆ beginPublish() [1/2]

bool PubSubClient::beginPublish ( const char * topic,
size_t plength,
bool retained )

Start to publish a message using QoS 0. This API: beginPublish(...) one or more calls to write(...) endPublish() Allows for arbitrarily large payloads to be sent without them having to be copied into a new buffer and held in memory at one time.

Parameters
topicThe topic to publish to.
plengthThe length of the payload.
retainedPublish the message with the retain flag.
Returns
true If the publish succeeded. false If the publish failed, either connection lost or message too large.

Definition at line 557 of file PubSubClient.cpp.

◆ beginPublish() [2/2]

bool PubSubClient::beginPublish ( const char * topic,
size_t plength,
uint8_t qos,
bool retained )

Start to publish a message. This API: beginPublish(...) one or more calls to write(...) endPublish() Allows for arbitrarily large payloads to be sent without them having to be copied into a new buffer and held in memory at one time.

Parameters
topicThe topic to publish to.
plengthThe length of the payload.
qosThe quality of service (QoS levels) to publish at. [0, 1, 2].
retainedPublish the message with the retain flag.
Returns
true If the publish succeeded. false If the publish failed, either connection lost or message too large.

Definition at line 561 of file PubSubClient.cpp.

◆ connect() [1/5]

bool PubSubClient::connect ( const char * id)

Connects the client using a clean session without username and password.

Parameters
idThe client ID to use when connecting to the server.
Returns
true If client succeeded in establishing a connection to the broker. false If client failed to establish a connection to the broker.

Definition at line 113 of file PubSubClient.cpp.

◆ connect() [2/5]

bool PubSubClient::connect ( const char * id,
const char * user,
const char * pass )

Connects the client using a clean session with username and password.

Parameters
idThe client ID to use when connecting to the server.
userThe username to use.
passThe password to use.
Note
If user is NULL, no username or password is used.
If pass is NULL, no password is used.
Returns
true If client succeeded in establishing a connection to the broker. false If client failed to establish a connection to the broker.

Definition at line 117 of file PubSubClient.cpp.

◆ connect() [3/5]

bool PubSubClient::connect ( const char * id,
const char * user,
const char * pass,
const char * willTopic,
uint8_t willQos,
bool willRetain,
const char * willMessage )

Connects the client using a clean session with username, password and will.

Parameters
idThe client ID to use when connecting to the server.
userThe username to use.
passThe password to use.
willTopicThe topic to be used by the will message.
willQosThe quality of service to be used by the will message. [0, 1, 2].
willRetainPublish the will message with the retain flag.
willMessageThe message to be used by the will message.
Note
If user is NULL, no username or password is used.
If pass is NULL, no password is used.
If willTopic is NULL, no will message is sent.
Returns
true If client succeeded in establishing a connection to the broker. false If client failed to establish a connection to the broker.

Definition at line 125 of file PubSubClient.cpp.

◆ connect() [4/5]

bool PubSubClient::connect ( const char * id,
const char * user,
const char * pass,
const char * willTopic,
uint8_t willQos,
bool willRetain,
const char * willMessage,
bool cleanSession )

Connects the client with all possible parameters (user, password, will and session).

Parameters
idThe client ID to use when connecting to the server.
userThe username to use.
passThe password to use.
willTopicThe topic to be used by the will message.
willQosThe quality of service to be used by the will message. [0, 1, 2].
willRetainPublish the will message with the retain flag.
willMessageThe message to be used by the will message.
cleanSessionTrue to connect with a clean session.
Note
If user is NULL, no username or password is used.
If pass is NULL, no password is used.
If willTopic is NULL, no will message is sent.
Returns
true If client succeeded in establishing a connection to the broker. false If client failed to establish a connection to the broker.

Definition at line 130 of file PubSubClient.cpp.

◆ connect() [5/5]

bool PubSubClient::connect ( const char * id,
const char * willTopic,
uint8_t willQos,
bool willRetain,
const char * willMessage )

Connects the client using a clean session and will.

Parameters
idThe client ID to use when connecting to the server.
willTopicThe topic to be used by the will message.
willQosThe quality of service to be used by the will message. [0, 1, 2].
willRetainPublish the will message with the retain flag.
willMessageThe message to be used by the will message.
Note
If willTopic is NULL, no will message is sent.
Returns
true If client succeeded in establishing a connection to the broker. false If client failed to establish a connection to the broker.

Definition at line 121 of file PubSubClient.cpp.

◆ connected()

bool PubSubClient::connected ( )

Checks whether the client is connected to the server.

Returns
true If the client is connected. false If the client is not connected.

Definition at line 230 of file PubSubClient.cpp.

◆ disconnect()

void PubSubClient::disconnect ( )

Disconnects the client.

Definition at line 244 of file PubSubClient.cpp.

◆ endPublish()

bool PubSubClient::endPublish ( )

Finish sending a message that was started with a call to beginPublish.

Returns
true If the publish succeeded. false If the publish failed, either connection lost or message too large.

Definition at line 587 of file PubSubClient.cpp.

◆ getBufferSize()

size_t PubSubClient::getBufferSize ( )

Gets the current size of the internal buffer.

Returns
The size of the internal buffer.

Definition at line 838 of file PubSubClient.cpp.

◆ loop()

bool PubSubClient::loop ( )

This should be called regularly to allow the client to process incoming messages and maintain its connection to the server.

Returns
true If the client is still connected. false If the client is no longer connected.

Definition at line 464 of file PubSubClient.cpp.

◆ publish() [1/6]

bool PubSubClient::publish ( const char * topic,
const char * payload )

Publishes a non retained message to the specified topic using QoS 0.

Parameters
topicThe topic to publish to.
payloadThe message to publish.
Returns
true If the publish succeeded. false If the publish failed, either connection lost or message too large.

Definition at line 504 of file PubSubClient.cpp.

◆ publish() [2/6]

bool PubSubClient::publish ( const char * topic,
const char * payload,
bool retained )

Publishes a message to the specified topic using QoS 0.

Parameters
topicThe topic to publish to.
payloadThe message to publish.
retainedPublish the message with the retain flag.
Returns
true If the publish succeeded. false If the publish failed, either connection lost or message too large.

Definition at line 508 of file PubSubClient.cpp.

◆ publish() [3/6]

bool PubSubClient::publish ( const char * topic,
const char * payload,
uint8_t qos,
bool retained )

Publishes a message to the specified topic.

Parameters
topicThe topic to publish to.
payloadThe message to publish.
qosThe quality of service (QoS levels) to publish at. [0, 1, 2].
retainedPublish the message with the retain flag.
Returns
true If the publish succeeded. false If the publish failed, either connection lost or message too large.

Definition at line 512 of file PubSubClient.cpp.

◆ publish() [4/6]

bool PubSubClient::publish ( const char * topic,
const uint8_t * payload,
size_t plength )

Publishes a non retained message to the specified topic using QoS 0.

Parameters
topicThe topic to publish to.
payloadThe message to publish.
plengthThe length of the payload.
Returns
true If the publish succeeded. false If the publish failed, either connection lost or message too large.

Definition at line 516 of file PubSubClient.cpp.

◆ publish() [5/6]

bool PubSubClient::publish ( const char * topic,
const uint8_t * payload,
size_t plength,
bool retained )

Publishes a message to the specified topic using QoS 0.

Parameters
topicThe topic to publish to.
payloadThe message to publish.
plengthThe length of the payload.
retainedPublish the message with the retain flag.
Returns
true If the publish succeeded. false If the publish failed, either connection lost or message too large.

Definition at line 520 of file PubSubClient.cpp.

◆ publish() [6/6]

bool PubSubClient::publish ( const char * topic,
const uint8_t * payload,
size_t plength,
uint8_t qos,
bool retained )

Publishes a message to the specified topic.

Parameters
topicThe topic to publish to.
payloadThe message to publish.
plengthThe length of the payload.
qosThe quality of service (QoS levels) to publish at. [0, 1, 2].
retainedPublish the message with the retain flag.
Returns
true If the publish succeeded. false If the publish failed, either connection lost or message too large.

Definition at line 524 of file PubSubClient.cpp.

◆ publish_P() [1/4]

bool PubSubClient::publish_P ( const char * topic,
const char * payload,
bool retained )

Publishes a message stored in PROGMEM to the specified topic using QoS 0.

Parameters
topicThe topic to publish to.
payloadThe message to publish.
retainedPublish the message with the retain flag.
Returns
true If the publish succeeded. false If the publish failed, either connection lost or message too large.

Definition at line 533 of file PubSubClient.cpp.

◆ publish_P() [2/4]

bool PubSubClient::publish_P ( const char * topic,
const char * payload,
uint8_t qos,
bool retained )

Publishes a message stored in PROGMEM to the specified topic.

Parameters
topicThe topic to publish to.
payloadThe message to publish.
qosThe quality of service (QoS levels) to publish at. [0, 1, 2].
retainedPublish the message with the retain flag.
Returns
true If the publish succeeded. false If the publish failed, either connection lost or message too large.

Definition at line 537 of file PubSubClient.cpp.

◆ publish_P() [3/4]

bool PubSubClient::publish_P ( const char * topic,
const uint8_t * payload,
size_t plength,
bool retained )

Publishes a message stored in PROGMEM to the specified topic using QoS 0.

Parameters
topicThe topic to publish to.
payloadThe message to publish.
plengthThe length of the payload.
retainedPublish the message with the retain flag.
Returns
true If the publish succeeded. false If the publish failed, either connection lost or message too large.

Definition at line 541 of file PubSubClient.cpp.

◆ publish_P() [4/4]

bool PubSubClient::publish_P ( const char * topic,
const uint8_t * payload,
size_t plength,
uint8_t qos,
bool retained )

Publishes a message stored in PROGMEM to the specified topic.

Parameters
topicThe topic to publish to.
payloadThe message to publish.
plengthThe length of the payload.
qosThe quality of service (QoS levels) to publish at. [0, 1, 2].
retainedPublish the message with the retain flag.
Returns
true If the publish succeeded. false If the publish failed, either connection lost or message too large.

Definition at line 545 of file PubSubClient.cpp.

◆ setBufferSize()

bool PubSubClient::setBufferSize ( size_t size)

Sets the size, in bytes, of the internal send and receive buffer. This must be large enough to contain the full MQTT packet. When sending or receiving messages, the packet will contain the full topic string, the payload data, and a small number of header bytes.

Parameters
sizeThe size, in bytes, for the internal buffer.
Returns
true If the buffer was resized. false If the buffer could not be resized.

Definition at line 819 of file PubSubClient.cpp.

◆ setCallback()

PubSubClient & PubSubClient::setCallback ( MQTT_CALLBACK_SIGNATURE )

Sets the message callback function.

Parameters
callbackPointer to a message callback function. Called when a message arrives for a subscription created by this client.
Returns
The client instance, allowing the function to be chained.

Definition at line 804 of file PubSubClient.cpp.

◆ setClient()

PubSubClient & PubSubClient::setClient ( Client & client)

Sets the network client instance to use.

Parameters
clientThe network client to use, for example WiFiClient.
Returns
The client instance, allowing the function to be chained.

Definition at line 809 of file PubSubClient.cpp.

◆ setKeepAlive()

PubSubClient & PubSubClient::setKeepAlive ( uint16_t keepAlive)

Sets the keep alive interval used by the client. This value should only be changed when the client is not connected. Set keepAlive to zero (0) to turn off the keep alive mechanism.

Parameters
keepAliveThe keep alive interval, in seconds.
Returns
The client instance, allowing the function to be chained.

Definition at line 842 of file PubSubClient.cpp.

◆ setServer() [1/3]

PubSubClient & PubSubClient::setServer ( const char * domain,
uint16_t port )

Sets the server details.

Parameters
domainThe address of the server.
portThe port to connect to.
Returns
The client instance, allowing the function to be chained.

Definition at line 787 of file PubSubClient.cpp.

◆ setServer() [2/3]

PubSubClient & PubSubClient::setServer ( IPAddress ip,
uint16_t port )

Sets the server details.

Parameters
ipThe address of the server.
portThe port to connect to.
Returns
The client instance, allowing the function to be chained.

Definition at line 779 of file PubSubClient.cpp.

◆ setServer() [3/3]

PubSubClient & PubSubClient::setServer ( uint8_t * ip,
uint16_t port )

Sets the server details.

Parameters
ipThe address of the server.
portThe port to connect to.
Returns
The client instance, allowing the function to be chained.

Definition at line 774 of file PubSubClient.cpp.

◆ setSocketTimeout()

PubSubClient & PubSubClient::setSocketTimeout ( uint16_t timeout)

Sets the socket timeout used by the client. This determines how long the client will wait for incoming data when it expects data to arrive - for example, whilst it is in the middle of reading a MQTT packet.

Parameters
timeoutThe socket timeout, in seconds.
Returns
The client instance, allowing the function to be chained.

Definition at line 847 of file PubSubClient.cpp.

◆ setStream()

PubSubClient & PubSubClient::setStream ( Stream & stream)

Sets the stream to write received messages to.

Parameters
streamA stream to write received messages to.
Returns
The client instance, allowing the function to be chained.

Definition at line 814 of file PubSubClient.cpp.

◆ state()

int PubSubClient::state ( )

Returns the current state of the client. If a connection attempt fails, this can be used to get more information about the failure.

Note
All of the values have corresponding constants defined in PubSubClient.h.
Returns
See state() result

Definition at line 852 of file PubSubClient.cpp.

◆ subscribe() [1/2]

bool PubSubClient::subscribe ( const char * topic)

Subscribes to messages published to the specified topic using QoS 0.

Parameters
topicThe topic to subscribe to.
Returns
true If sending the subscribe succeeded. false If sending the subscribe failed, either connection lost or message too large.

Definition at line 733 of file PubSubClient.cpp.

◆ subscribe() [2/2]

bool PubSubClient::subscribe ( const char * topic,
uint8_t qos )

Subscribes to messages published to the specified topic.

Parameters
topicThe topic to subscribe to.
qosThe qos to subscribe at. [0, 1].
Returns
true If sending the subscribe succeeded. false If sending the subscribe failed, either connection lost or message too large.

Definition at line 737 of file PubSubClient.cpp.

◆ unsubscribe()

bool PubSubClient::unsubscribe ( const char * topic)

Unsubscribes from the specified topic.

Parameters
topicThe topic to unsubscribe from.
Returns
true If sending the unsubscribe succeeded. false If sending the unsubscribe failed, either connection lost or message too large.

Definition at line 757 of file PubSubClient.cpp.

◆ write() [1/2]

size_t PubSubClient::write ( const uint8_t * buffer,
size_t size )
virtual

Writes an array of bytes as a component of a publish started with a call to beginPublish.

Parameters
bufferThe bytes to write.
sizeThe length of the payload to be sent.
Returns
The number of bytes written.

Definition at line 642 of file PubSubClient.cpp.

◆ write() [2/2]

size_t PubSubClient::write ( uint8_t data)
virtual

Writes a single byte as a component of a publish started with a call to beginPublish.

Parameters
dataA byte to write to the publish payload.
Returns
The number of bytes written.

Definition at line 637 of file PubSubClient.cpp.


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