1 #if !defined(_RADIOLIB_MQTT_H) 2 #define _RADIOLIB_MQTT_H 4 #include "../../TypeDef.h" 6 #if !defined(RADIOLIB_EXCLUDE_MQTT) 8 #include "../TransportLayer/TransportLayer.h" 11 #define MQTT_CONNECT 0x01 12 #define MQTT_CONNACK 0x02 13 #define MQTT_PUBLISH 0x03 14 #define MQTT_PUBACK 0x04 15 #define MQTT_PUBREC 0x05 16 #define MQTT_PUBREL 0x06 17 #define MQTT_PUBCOMP 0x07 18 #define MQTT_SUBSCRIBE 0x08 19 #define MQTT_SUBACK 0x09 20 #define MQTT_UNSUBSCRIBE 0x0A 21 #define MQTT_UNSUBACK 0x0B 22 #define MQTT_PINGREQ 0x0C 23 #define MQTT_PINGRESP 0x0D 24 #define MQTT_DISCONNECT 0x0E 27 #define MQTT_CONNECT_USER_NAME_FLAG 0b10000000 28 #define MQTT_CONNECT_PASSWORD_FLAG 0b01000000 29 #define MQTT_CONNECT_WILL_RETAIN 0b00100000 30 #define MQTT_CONNECT_WILL_FLAG 0b00000100 31 #define MQTT_CONNECT_CLEAN_SESSION 0b00000010 70 int16_t
connect(
const char* host,
const char* clientId,
const char* userName =
"",
const char* password =
"", uint16_t keepAlive = 60,
bool cleanSession =
true,
const char* willTopic =
"",
const char* willMessage =
"");
88 int16_t
publish(String& topic, String& message);
99 int16_t
publish(
const char* topic,
const char* message);
108 int16_t
subscribe(
const char* topicFilter);
131 int16_t
check(
void (*func)(
const char*,
const char*));
133 #ifndef RADIOLIB_GODMODE 141 static size_t encodeLength(uint32_t len, uint8_t* encoded);
142 static uint32_t decodeLength(uint8_t* encoded, uint8_t& numBytes);
int16_t subscribe(const char *topicFilter)
Subscribe to MQTT topic.
Definition: MQTT.cpp:211
Provides common interface for protocols that run on modules with Internet connectivity, such as HTTP or MQTT. Because this class is used mainly as interface, all of its virtual members must be implemented in the module class.
Definition: TransportLayer.h:12
int16_t ping()
Ping MQTT broker. This method can be used to keep connection open.
Definition: MQTT.cpp:356
int16_t disconnect()
Disconnect from MQTT broker.
Definition: MQTT.cpp:146
MQTTClient(TransportLayer *tl, uint16_t port=1883)
Default constructor.
Definition: MQTT.cpp:4
int16_t connect(const char *host, const char *clientId, const char *userName="", const char *password="", uint16_t keepAlive=60, bool cleanSession=true, const char *willTopic="", const char *willMessage="")
Connects to MQTT broker (/server).
Definition: MQTT.cpp:10
int16_t publish(String &topic, String &message)
Publish MQTT message.
Definition: MQTT.cpp:164
int16_t check(void(*func)(const char *, const char *))
Set function to be called when checking new messages in subscribed topics.
Definition: MQTT.cpp:396
int16_t unsubscribe(const char *topicFilter)
Unsubscribe from MQTT topic.
Definition: MQTT.cpp:285
Client for simple MQTT communication.
Definition: MQTT.h:38