22 #ifdef _GLIBCXX_FUNCTIONAL
23 typedef std::function<void(const MQTT::Publish&)> callback_t;
30 String server_hostname;
35 uint16_t nextMsgId, keepalive;
37 unsigned long lastOutActivity;
38 unsigned long lastInActivity;
52 bool _send_message(
MQTT::Message& msg,
bool need_reply =
false);
70 bool _wait_for(MQTT::message_type wait_type, uint16_t wait_pid = 0);
73 uint16_t _next_packet_id(
void) {
75 if (nextMsgId == 0) nextMsgId = 1;
87 PubSubClient(Client& c, IPAddress &ip, uint16_t port = 1883);
89 PubSubClient(Client& c, String hostname, uint16_t port = 1883);
97 callback_t
callback(
void)
const {
return _callback; }
122 bool connect(String
id, String willTopic, uint8_t willQos,
bool willRetain, String willMessage);
132 bool publish(String topic, String payload);
143 bool publish(String topic,
const uint8_t *payload, uint32_t plength,
bool retained =
false);
151 bool publish(String topic, MQTT::payload_callback_t pcb, uint32_t length,
bool retained =
false);
162 bool publish_P(String topic, PGM_P payload, uint32_t plength,
bool retained =
false);
169 bool subscribe(String topic, uint8_t qos = 0);
Main do-everything class that sketches will use.
Definition: PubSubClient.h:20
PubSubClient & set_callback(callback_t cb)
Set the callback function.
Definition: PubSubClient.h:99
bool publish_P(String topic, PGM_P payload, uint32_t plength, bool retained=false)
Publish an arbitrary data payload stored in "program" memory.
Definition: PubSubClient.cpp:250
bool subscribe(String topic, uint8_t qos=0)
Subscribe to a topic.
Definition: PubSubClient.cpp:282
bool publish(String topic, String payload)
Publish a string payload.
Definition: PubSubClient.cpp:222
Subscribe to one or more topics.
Definition: MQTT.h:398
PubSubClient & set_server(IPAddress &ip, uint16_t port=1883)
Set the server ip address.
Definition: PubSubClient.cpp:32
PubSubClient & unset_callback(void)
Unset the callback function.
Definition: PubSubClient.h:101
callback_t callback(void) const
Get the callback function.
Definition: PubSubClient.h:97
Message sent when connecting to a broker.
Definition: MQTT.h:157
Unsubscribe from one or more topics.
Definition: MQTT.h:455
bool connected()
Are we connected?
Definition: PubSubClient.cpp:325
bool connect(String id)
Connect to the server with a client id.
Definition: PubSubClient.cpp:153
Publish a payload to a topic.
Definition: MQTT.h:221
bool loop()
Wait for packets to come in, processing them.
Definition: PubSubClient.cpp:193
PubSubClient(Client &c)
Simple constructor.
Definition: PubSubClient.cpp:10
void disconnect(void)
Disconnect from the server.
Definition: PubSubClient.cpp:315
bool unsubscribe(String topic)
Unsubscribe from a topic.
Definition: PubSubClient.cpp:300
PubSubClient & set_max_retries(uint8_t mr)
Set the maximum number of retries when waiting for response packets.
Definition: PubSubClient.h:104
Abstract base class.
Definition: MQTT.h:63