|
PubSubClient
MQTT client library for Arduino
|
Main do-everything class that sketches will use. More...
#include <PubSubClient.h>
Public Types | |
| typedef void(* | callback_t) (const MQTT::Publish &) |
Public Member Functions | |
| PubSubClient (Client &c) | |
| Simple constructor. More... | |
| PubSubClient (Client &c, IPAddress &ip, uint16_t port=1883) | |
| Constructor with the server ip address. | |
| PubSubClient (Client &c, String hostname, uint16_t port=1883) | |
| Constructors with the host name. | |
| PubSubClient & | set_server (IPAddress &ip, uint16_t port=1883) |
| Set the server ip address. | |
| PubSubClient & | set_server (String hostname, uint16_t port=1883) |
| Set the server host name. | |
| callback_t | callback (void) const |
| Get the callback function. | |
| PubSubClient & | set_callback (callback_t cb) |
| Set the callback function. | |
| PubSubClient & | unset_callback (void) |
| Unset the callback function. | |
| PubSubClient & | set_max_retries (uint8_t mr) |
| Set the maximum number of retries when waiting for response packets. | |
| bool | connect (String id) |
| Connect to the server with a client id. More... | |
| bool | connect (String id, String willTopic, uint8_t willQos, bool willRetain, String willMessage) |
| Connect to the server with a client id and "will" parameters. More... | |
| void | disconnect (void) |
| Disconnect from the server. | |
| bool | publish (String topic, String payload) |
| Publish a string payload. More... | |
| bool | publish (String topic, const uint8_t *payload, uint32_t plength, bool retained=false) |
| Publish an arbitrary data payload. More... | |
| bool | publish (String topic, MQTT::payload_callback_t pcb, uint32_t length, bool retained=false) |
| Publish an arbitrary data payload from a callback. More... | |
| bool | publish_P (String topic, PGM_P payload, uint32_t plength, bool retained=false) |
| Publish an arbitrary data payload stored in "program" memory. More... | |
| bool | subscribe (String topic, uint8_t qos=0) |
| Subscribe to a topic. More... | |
| bool | unsubscribe (String topic) |
| Unsubscribe from a topic. | |
| bool | loop () |
| Wait for packets to come in, processing them. More... | |
| bool | connected () |
| Are we connected? | |
| bool | connect (MQTT::Connect &conn) |
| Connect with a pre-constructed MQTT message object. | |
| bool | publish (MQTT::Publish &pub) |
| Publish with a pre-constructed MQTT message object. | |
| bool | subscribe (MQTT::Subscribe &sub) |
| Subscribe with a pre-constructed MQTT message object. | |
| bool | unsubscribe (MQTT::Unsubscribe &unsub) |
| Unsubscribe with a pre-constructed MQTT message object. | |
Main do-everything class that sketches will use.
| PubSubClient::PubSubClient | ( | Client & | c | ) |
Simple constructor.
Use set_server() before connect()
| bool PubSubClient::connect | ( | String | id | ) |
Connect to the server with a client id.
| id | Client id for this device |
| bool PubSubClient::connect | ( | String | id, |
| String | willTopic, | ||
| uint8_t | willQos, | ||
| bool | willRetain, | ||
| String | willMessage | ||
| ) |
Connect to the server with a client id and "will" parameters.
The "will" is a message that is published when this client unexpectantly disconnects from the broker i.e without sending a DISCONNECT message.
| id | Client id for this device |
| willTopic | Topic of the "will" message |
| willQos | QoS level of the "will" message |
| willRetain | Retain setting of the "will" message |
| willMessage | Content (payload) of the "will" message |
| bool PubSubClient::loop | ( | ) |
Wait for packets to come in, processing them.
Also periodically pings the server
| bool PubSubClient::publish | ( | String | topic, |
| String | payload | ||
| ) |
Publish a string payload.
| topic | Topic of the message |
| payload | String text of the message |
| bool PubSubClient::publish | ( | String | topic, |
| const uint8_t * | payload, | ||
| uint32_t | plength, | ||
| bool | retained = false |
||
| ) |
Publish an arbitrary data payload.
| topic | Topic of the message |
| payload | Pointer to contents of the message |
| plength | Length of the message (pointed to by payload) in bytes |
| retained | If true, this message will be stored on the server and supplied to any future subscribers whose subscriptions match its topic name. |
| bool PubSubClient::publish | ( | String | topic, |
| MQTT::payload_callback_t | pcb, | ||
| uint32_t | length, | ||
| bool | retained = false |
||
| ) |
Publish an arbitrary data payload from a callback.
| topic | Topic of this message |
| pcb | A callback function that writes the payload directly to the network Client object |
| length | The length of the data that 'pcb' will send |
| bool PubSubClient::publish_P | ( | String | topic, |
| PGM_P | payload, | ||
| uint32_t | plength, | ||
| bool | retained = false |
||
| ) |
Publish an arbitrary data payload stored in "program" memory.
| topic | Topic of the message |
| payload | Pointer to contents of the message, stored in "program" memory |
| plength | Length of the message (pointed to by payload) in bytes |
| retained | If true, this message will be stored on the server and supplied to any future subscribers whose subscriptions match its topic name. |
| bool PubSubClient::subscribe | ( | String | topic, |
| uint8_t | qos = 0 |
||
| ) |
Subscribe to a topic.
| topic | Topic filter |
| qos | QoS value. 0 => no handshake, 1 => single handshake, 2 => two-way handshake |
1.8.9.1