10 #define PubSubClient_h
14 #include "FreeRTOSTimer.h"
16 #define MQTT_VERSION_3_1 3
17 #define MQTT_VERSION_3_1_1 4
22 #define MQTT_VERSION MQTT_VERSION_3_1_1
26 #ifndef MQTT_MAX_PACKET_SIZE
27 #define MQTT_MAX_PACKET_SIZE 128
31 #ifndef MQTT_KEEPALIVE
32 #define MQTT_KEEPALIVE 15
36 #ifndef MQTT_SOCKET_TIMEOUT
37 #define MQTT_SOCKET_TIMEOUT 15
55 const char* willTopic;
58 const char* willMessage;
62 CONNECTION_TIMEOUT = -4,
67 CONNECT_BAD_PROTOCOL = 1,
68 CONNECT_BAD_CLIENT_ID = 2,
69 CONNECT_UNAVAILABLE = 3,
70 CONNECT_BAD_CREDENTIALS = 4,
71 CONNECT_UNAUTHORIZED = 5,
84 UNSUBSCRIBE = 10 << 4,
108 #define MQTT_CALLBACK_SIGNATURE void (*callback) (std::string, std::string)
126 bool connect(
const char*
id,
const char* user,
const char* pass);
127 bool connect(
const char*
id,
const char* willTopic, uint8_t willQos,
bool willRetain,
const char* willMessage);
128 bool connect(
const char*
id,
const char* user,
const char* pass,
const char* willTopic, uint8_t willQos,
bool willRetain,
const char* willMessage);
131 bool publish(
const char* topic,
const char* payload);
132 bool publish(
const char* topic,
const char* payload,
bool retained);
133 bool publish(
const char* topic,
const uint8_t* payload,
unsigned int plength);
134 bool publish(
const char* topic,
const uint8_t* payload,
unsigned int plength,
bool retained);
137 bool subscribe(
const char* topic,
bool ack =
false);
138 bool unsubscribe(
const char* topic,
bool ack =
false);
153 uint8_t buffer[MQTT_MAX_PACKET_SIZE];
155 bool PING_outstanding;
156 bool SUBACK_outstanding;
157 bool UNSUBACK_Outstanding;
161 MQTT_CALLBACK_SIGNATURE;
164 bool write(uint8_t header, uint8_t* buf, uint16_t length);
165 uint16_t writeString(
const char*
string, uint8_t* buf, uint16_t pos);
168 std::string messageType_toString(uint8_t type);
Definition: PubSubClient.h:112
Encapsulate a socket.
Definition: Socket.h:62
bool connect()
Connect to a MQTT server with the with the previous settings. Note: do not call this function without...
Definition: PubSubClient.cpp:311
void timeoutChecker()
This is a Timer called routine, which is called, when we reach the timeout. Used is this function for...
Definition: PubSubClient.cpp:233
PubSubClient & setServer(std::string ip, uint16_t port)
Set server ip and Port of my MQTT server.
Definition: PubSubClient.cpp:719
Definition: PubSubClient.h:98
bool publish(const char *topic, const char *payload)
Publish a MQTT message.
Definition: PubSubClient.cpp:419
bool connected()
Check the connection to the MQTT server.
Definition: PubSubClient.cpp:694
bool unsubscribe(const char *topic, bool ack=false)
Unsubscribe a MQTT topic.
Definition: PubSubClient.cpp:625
bool subscribe(const char *topic, bool ack=false)
Subscribe a MQTT topic.
Definition: PubSubClient.cpp:584
Definition: PubSubClient.h:47
int state()
Get the current MYTT state form the instance.
Definition: PubSubClient.cpp:753
PubSubClient & setCallback(MQTT_CALLBACK_SIGNATURE)
Set the callback function for incoming data.
Definition: PubSubClient.cpp:731
void disconnect()
Disconnect form MQTT server and close the socket.
Definition: PubSubClient.cpp:662
PubSubClient & setClient(Socket &client)
Set the socket, which we want to use for our MQTT communication.
Definition: PubSubClient.cpp:742
bool isSubscribeDone()
Check the state of subscription. If there was received a subscription ACK, we return a true here...
Definition: PubSubClient.cpp:614
bool isUnsubscribeDone()
Check the state of unsubscription. If there was received a unsubscription ACK, we return a true here...
Definition: PubSubClient.cpp:653
A task that will handle the PubSubClient.
Definition: PubSubClient.cpp:27
Wrapper around the FreeRTOS timer functions.
Definition: FreeRTOSTimer.h:16
void keepAliveChecker()
This is a Timer called routine, which checks the PING_outstanding flag. This flag is set in this func...
Definition: PubSubClient.cpp:210