The ESP-AT MQTT library project
A simple wrapper to the MQTT functionality found in the ESP-AT interpreter
|
Go to the documentation of this file.
41 #define MQTT_BUFFER_SIZE 1024
164 AT_MQTT_DO_NOT_RETAIN = 0,
177 #define MQTT_ERROR(x) (x & 0xffff)
179 #define DEFAULT_LINK_ID 0
185 typedef void (*subscription_cb_t)(char *topic, char *mqttdata);
209 EspATMQTT(HardwareSerial* = &ESP_SERIAL_PORT);
213 const char *userName=
"",
const char *password=
"",
214 uint32_t certKeyID=0, uint32_t caID=0,
215 const char *path=
"");
217 const char *userName=
"",
const char *password=
"",
218 uint32_t certKeyID=0, uint32_t caID=0,
219 const char *path=
"");
221 char *userName,
char *password, uint32_t certKeyID=0,
222 uint32_t caID=0,
const char *path=
"");
224 uint32_t port=1883, uint32_t reconnect=0,
233 uint32_t disable_clean_session,
const char* lwt_topic,
234 const char* lwt_message, uint32_t lwt_qos = 0,
235 uint32_t lwt_retain = 0);
237 const char *alpn2 = NULL,
238 const char *alpn3 = NULL,
239 const char *alpn4 = NULL,
240 const char *alpn5 = NULL);
242 uint32_t qos=0, uint32_t retain=0);
244 uint32_t qos=0, uint32_t retain=0);
246 uint32_t qos=0, uint32_t retain=0);
248 uint32_t qos=0, uint32_t retain=0);
257 const char *ts1 = NULL,
const char *ts2 = NULL,
258 const char *ts3 = NULL);
269 int topicSubscriptions;
273 char buff[MQTT_BUFFER_SIZE];
@ AT_MQTT_CLIENT_ID_IS_OVERLENGTH
The client ID is to long.
Definition: EspATMQTT.h:92
@ AT_MQTT_LWT_QOS_VALUE_IS_WRONG
Incorrect LWT QoS value specified.
Definition: EspATMQTT.h:125
@ AT_CONN_SYNCH
MQTT server has connected synchronously.
Definition: EspATMQTT.h:173
@ AT_MQTT_CLIENT_UNSUBSCRIBE_FAILED
Failed to unsubscribe from topic.
Definition: EspATMQTT.h:84
mqtt_status_t pubString(uint32_t linkID, const char *topic, const char *data, uint32_t qos=0, uint32_t retain=0)
Publish a string to a specified topic.
Definition: EspATMQTT.cpp:705
@ AT_MQTT_PARAM_PREPARE_ERROR
?
Definition: EspATMQTT.h:80
@ AT_MQTT_NULL_PARAMTER
A NULL parameter was found when valid data was expected.
Definition: EspATMQTT.h:77
@ AT_MQTT_LWT_QOS_READ_FAILED
Failed to read LWT QoS parameter.
Definition: EspATMQTT.h:124
@ AT_MQTT_USERNAME_READ_FAILED
Failed to read the user name.
Definition: EspATMQTT.h:93
@ AT_MQTT_NULL_LINK
?
Definition: EspATMQTT.h:76
@ AT_MQTT_SCHEME_READ_FAILED
Failed to read the security scheme used.
Definition: EspATMQTT.h:88
@ AT_MQTT_VERSION_READ_FAILED
Failed to read version.
Definition: EspATMQTT.h:112
@ AT_MQTT_PATH_READ_FAILED
Failed to read from path.
Definition: EspATMQTT.h:109
@ AT_CONN_ASYNCH
MQTT server has not connected yet and is awaiting a connection callback.
Definition: EspATMQTT.h:174
EspATMQTT(HardwareSerial *=&ESP_SERIAL_PORT)
The module constructor allows you to select what serial port that should be used to communicate with ...
Definition: EspATMQTT.cpp:72
@ AT_MQTT_KEY_READ_FAILED
Failed to read client key.
Definition: EspATMQTT.h:108
@ AT_MQTT_DATA_READ_FAILED
Failed to read message.
Definition: EspATMQTT.h:138
@ AT_MQTT_CLIENT_ID_READ_FAILED
Failed to read the client ID.
Definition: EspATMQTT.h:90
@ AT_MQTT_LWT_TOPIC_IS_OVERLENGTH
LWT topic is to long.
Definition: EspATMQTT.h:120
@ AT_MQTT_NOT_IN_CONFIGURED_STATE
MQTT layer not in a configured state (same as above ?)
Definition: EspATMQTT.h:72
@ AT_MQTT_LWT_MSG_READ_FAILED
Failed to read LWT message.
Definition: EspATMQTT.h:121
@ AT_MQTT_TOPIC_READ_FAILED
Failed to read topic parameter.
Definition: EspATMQTT.h:135
@ AT_MQTT_CERT_LENGTH_ERROR
Incorrect client certificate length.
Definition: EspATMQTT.h:105
@ AT_MQTT_TOPIC_IS_OVERLENGTH
Failed to set topic, to long.
Definition: EspATMQTT.h:137
mqtt_retain_e
A retained message is a normal MQTT message with the retained flag set to true.
Definition: EspATMQTT.h:163
@ AT_MQTT_LWT_MSG_IS_NULL
LWT message can not be set to NULL.
Definition: EspATMQTT.h:122
@ AT_MQTT_CREATE_SEMA_FAILED
Internal error, failed to create semaphore.
Definition: EspATMQTT.h:148
@ ESP_MQTT_SCHEME_MQTT_OVER_WS_TCP_SEC_TLS_NCV
MQTT over WebSocket Secure (based on TLS, no certificate verification).
Definition: EspATMQTT.h:53
@ AT_MQTT_PUBLISH_LENGTH_READ_FAILED
Failed to read publish length parameter.
Definition: EspATMQTT.h:145
@ AT_MQTT_PUBLISH_LENGTH_VALUE_IS_WRONG
Failed to set published length value.
Definition: EspATMQTT.h:146
@ ESP_MQTT_SCHEME_MQTT_OVER_TLS_NCV
MQTT over TLS (no certificate verification).
Definition: EspATMQTT.h:48
@ ESP_MQTT_SCHEME_MQTT_OVER_WS_TCP_SEC_TLS_VSC
MQTT over WebSocket Secure (based on TLS, verify server certificate).
Definition: EspATMQTT.h:54
mqtt_error_e
The caller should use these error codes to determine the cause of an MQTT error.
Definition: EspATMQTT.h:70
@ AT_MQTT_KEEPALIVE_READ_FAILED
Failed to read keepalive value.
Definition: EspATMQTT.h:113
@ AT_MQTT_TLS_CONFIG_ERROR
Something is wrong with the TLS configuration.
Definition: EspATMQTT.h:79
@ AT_MQTT_NO_CONFIGURED
MQTT layer not configured yet.
Definition: EspATMQTT.h:71
@ AT_MQTT_LINK_ID_READ_FAILED
Failed to read the link ID.
Definition: EspATMQTT.h:86
@ AT_MQTT_IN_DISCONNECTED_STATE
MQTT is in disconnected state.
Definition: EspATMQTT.h:151
mqtt_connectType_e
Definition: EspATMQTT.h:171
@ AT_MQTT_DISABLE_CLEAN_SESSION_READ_FAILED
Failed to read the clean session parameter.
Definition: EspATMQTT.h:116
@ AT_MQTT_QOS_VALUE_IS_WRONG
Incorrect QoS value specified.
Definition: EspATMQTT.h:142
uint32_t mqtt_status_t
The return value of an ESP-AT MQTT operation.
Definition: EspATMQTT.h:202
@ AT_MQTT_CERT_READ_FAILED
Failed to read client certificate.
Definition: EspATMQTT.h:106
@ AT_MQTT_FAILED_TO_PUBLISH_RAW
Failed to publish raw data.
Definition: EspATMQTT.h:153
void(* connected_cb_t)(char *connectionString)
Definition: EspATMQTT.h:195
mqtt_status_t getNTPTime(char **time)
Get the current time from the ESP-AT internal NTP Client.
Definition: EspATMQTT.cpp:1171
mqtt_status_t setUsername(uint32_t linkID, const char *username)
Sets the username used in authenticating the client with the broker.
Definition: EspATMQTT.cpp:365
@ AT_MQTT_USERNAME_IS_OVERLENGTH
The user name is to long.
Definition: EspATMQTT.h:95
@ AT_MQTT_LWT_TOPIC_READ_FAILED
Failed to read the lwt topic.
Definition: EspATMQTT.h:118
@ AT_MQTT_HOST_IS_OVERLENGTH
Host value to long.
Definition: EspATMQTT.h:130
mqtt_status_t connect(uint32_t linkID, const char *host, uint32_t port=1883, uint32_t reconnect=0, uint32_t timeout=5000, connected_cb_t cb=NULL)
Connects to the specified server/broker with the previously defined transport scheme.
Definition: EspATMQTT.cpp:637
@ AT_MQTT_KEEPALIVE_IS_NULL
Keepalive value must not be NULL.
Definition: EspATMQTT.h:114
@ AT_MQTT_LINK_ID_VALUE_IS_WRONG
Wrong link ID value was used.
Definition: EspATMQTT.h:87
@ AT_MQTT_HOST_READ_FAILED
Failed to read host parameter.
Definition: EspATMQTT.h:128
@ AT_MQTT_UNINITIATED_OR_ALREADY_CLEAN
Tried to perform clean when the MQTT layer was already clean.
Definition: EspATMQTT.h:73
@ AT_MQTT_CLIENT_SUBSCRIBE_FAILED
Failed to subscribe to topic at broker.
Definition: EspATMQTT.h:83
@ AT_MQTT_RECV_LENGTH_IS_WRONG
Incorrect receive length is specified.
Definition: EspATMQTT.h:147
@ AT_MQTT_PASSWORD_READ_FAILED
Failed to read the password.
Definition: EspATMQTT.h:96
@ AT_MQTT_PASSWORD_IS_NULL
The password can't be NULL.
Definition: EspATMQTT.h:97
@ AT_MQTT_CREATE_EVENT_GROUP_FAILED
Internal error, failed to create event group.
Definition: EspATMQTT.h:149
@ AT_MQTT_TOPIC_IS_NULL
Failed to set topic, can't be NULL.
Definition: EspATMQTT.h:136
@ ESP_MQTT_SCHEME_MQTT_OVER_WS_TCP_SEC_TLS_VSCPCC
MQTT over WebSocket Secure (based on TLS, verify server certificate and provide client certificate).
Definition: EspATMQTT.h:56
@ AT_MQTT_CLIENT_ID_IS_NULL
The client ID can't be NULL.
Definition: EspATMQTT.h:91
void process()
The process method must be placed in the main loop in order to process MQTT events that are reported ...
Definition: EspATMQTT.cpp:1193
mqtt_status_t enableNTPTime(bool enable, validDateTime_cb_t cb, uint32_t timezone, const char *ts1=NULL, const char *ts2=NULL, const char *ts3=NULL)
Enables the internal NTP Time client.
Definition: EspATMQTT.cpp:1124
@ AT_MQTT_CERT_KEY_ID_READ_FAILED
The cert key ID could not be read.
Definition: EspATMQTT.h:99
@ ESP_MQTT_SCHEME_MQTT_OVER_WS_TCP_SEC_TLS_PCC
MQTT over WebSocket Secure (based on TLS, provide client certificate).
Definition: EspATMQTT.h:55
@ AT_MQTT_DATA_IS_NULL
Incorrect message specified, can't be NULL.
Definition: EspATMQTT.h:139
@ AT_MQTT_RECONNECT_READ_FAILED
Failed to read reconnect parameter.
Definition: EspATMQTT.h:133
@ AT_MQTT_URI_PARSE_FAILED
Internal error, failed to parse URI.
Definition: EspATMQTT.h:150
@ AT_MQTT_CA_ID_READ_FAILED
The CA ID could not be read.
Definition: EspATMQTT.h:101
@ AT_MQTT_CERT_KEY_ID_VALUE_IS_WRONG
The cert key ID is incorrect.
Definition: EspATMQTT.h:100
@ AT_MQTT_DATA_IS_OVERLENGTH
Message to long.
Definition: EspATMQTT.h:140
@ AT_MQTT_USERNAME_IS_NULL
The user name can't be NULL.
Definition: EspATMQTT.h:94
mqtt_status_t begin()
The begin method initializes the system before usage.
Definition: EspATMQTT.cpp:85
mqtt_scheme_e
MQTT configuration schemes.
Definition: EspATMQTT.h:46
@ AT_MQTT_PORT_VALUE_IS_WRONG
Port value is incorrect.
Definition: EspATMQTT.h:132
@ AT_MQTT_MALLOC_FAILED
Failed to allocate memory internally.
Definition: EspATMQTT.h:75
@ AT_MQTT_CLIENT_START_FAILED
Failed to start MQTT client.
Definition: EspATMQTT.h:81
@ AT_MQTT_CLIENT_DISCONNECT_FAILED
Failed to disconnect from the broker.
Definition: EspATMQTT.h:85
mqtt_status_t connectionConfig(uint32_t linkID, uint32_t keepalive, uint32_t disable_clean_session, const char *lwt_topic, const char *lwt_message, uint32_t lwt_qos=0, uint32_t lwt_retain=0)
Sets the configuration of the current MQTT connection.
Definition: EspATMQTT.cpp:495
enum mqtt_connectType_e mqtt_connectType_t
@ AT_MQTT_CA_ID_VALUE_IS_WRONG
The CA ID value is incorrect.
Definition: EspATMQTT.h:102
bool isConnected()
Checks to see if the mqtt client is connected and returns true if it is.
Definition: EspATMQTT.cpp:1182
@ AT_MQTT_SCHEME_VALUE_IS_WRONG
Incorrect scheme value was used.
Definition: EspATMQTT.h:89
@ ESP_MQTT_SCHEME_MQTT_OVER_TLS_PCC
MQTT over TLS (provide client certificate).
Definition: EspATMQTT.h:50
@ ESP_MQTT_SCHEME_MQTT_OVER_TLS_VSCPCC
MQTT over TLS (verify server certificate and provide client certificate).
Definition: EspATMQTT.h:51
@ AT_MQTT_LWT_RETAIN_READ_FAILED
Failed to read LWT retain parameter.
Definition: EspATMQTT.h:126
@ AT_MQTT_LWT_TOPIC_IS_NULL
LWT topic can not be set to NULL.
Definition: EspATMQTT.h:119
EspAT MQTT AT_Class definition.
Definition: AT.h:90
@ ESP_MQTT_SCHEME_MQTT_OVER_TLS_VSC
MQTT over TLS (verify server certificate).
Definition: EspATMQTT.h:49
EspAT MQTT EspATMQTT class definition.
Definition: EspATMQTT.h:207
@ AT_MQTT_LWT_MSG_IS_OVERLENGTH
LWT message is to long.
Definition: EspATMQTT.h:123
@ AT_MQTT_PASSWORD_IS_OVERLENGTH
The password is to long.
Definition: EspATMQTT.h:98
@ AT_MQTT_PARAMETER_COUNTS_IS_WRONG
The number of parameters is incorrect.
Definition: EspATMQTT.h:78
mqtt_status_t unSubscribeTopic(uint32_t linkID, const char *topic)
Unsubscribe from messages with a specific topic.
Definition: EspATMQTT.cpp:1012
mqtt_status_t setALPN(uint32_t linkID, const char *alpn1=NULL, const char *alpn2=NULL, const char *alpn3=NULL, const char *alpn4=NULL, const char *alpn5=NULL)
This function sets the ALPN (Application Layer Protocol Negotiation) of the link.
Definition: EspATMQTT.cpp:539
mqtt_status_t setPassword(uint32_t linkID, const char *password)
Sets the password used in authenticating the client with the broker.
Definition: EspATMQTT.cpp:421
@ AT_MQTT_CLIENT_PUBLISH_FAILED
Failed to publish data to broker.
Definition: EspATMQTT.h:82
@ AT_MQTT_HOST_IS_NULL
Failed to set host, value can not be NULL.
Definition: EspATMQTT.h:129
mqtt_status_t setClientID(uint32_t linkID, const char *clientID)
Sets a new client ID for the connection.
Definition: EspATMQTT.cpp:310
@ AT_MQTT_PATH_IS_OVERLENGTH
The path length is to long.
Definition: EspATMQTT.h:111
@ AT_MQTT_PATH_IS_NULL
The path must not be NULL.
Definition: EspATMQTT.h:110
@ ESP_MQTT_SCHEME_MQTT_OVER_TCP
MQTT over plain TCP.
Definition: EspATMQTT.h:47
@ AT_MQTT_PORT_READ_FAILED
Failed to read port parameter.
Definition: EspATMQTT.h:131
mqtt_status_t subscribeTopic(subscription_cb_t cb, uint32_t linkID, const char *topic, uint32_t qos=0)
Subscribe to messages from a specific topic.
Definition: EspATMQTT.cpp:939
@ AT_MQTT_KEY_LENGTH_ERROR
Incorrect client key length.
Definition: EspATMQTT.h:107
void(* validDateTime_cb_t)(char *dateTime)
Definition: EspATMQTT.h:190
@ AT_CONN_UNCONNECTED
MQTT server still in its unconnected state.
Definition: EspATMQTT.h:172
@ AT_MQTT_RECONNECT_VALUE_IS_WRONG
Incorrect reconnect value specified.
Definition: EspATMQTT.h:134
mqtt_status_t pubRaw(uint32_t linkID, const char *topic, const char *data, uint32_t qos=0, uint32_t retain=0)
Publish raw data to a specified topic.
Definition: EspATMQTT.cpp:810
@ AT_MQTT_ALREADY_CONNECTED
Tried to connect when already connected.
Definition: EspATMQTT.h:74
@ ESP_MQTT_SCHEME_MQTT_OVER_WS_TCP
MQTT over WebSocket (based on TCP).
Definition: EspATMQTT.h:52
@ AT_MQTT_CA_LENGTH_ERROR
The CA length is incorrect.
Definition: EspATMQTT.h:103
mqtt_status_t userConfig(uint32_t linkID, mqtt_scheme_t scheme, const char *clientID, const char *userName="", const char *password="", uint32_t certKeyID=0, uint32_t caID=0, const char *path="")
Setup the connection scheme and how to connect to the server/broker.
Definition: EspATMQTT.cpp:165
@ AT_MQTT_DISABLE_CLEAN_SESSION_VALUE_IS_WRONG
Incorrect value of the clean session value.
Definition: EspATMQTT.h:117
@ AT_MQTT_KEEPALIVE_VALUE_IS_WRONG
Keepalive value is incorrect.
Definition: EspATMQTT.h:115
@ AT_MQTT_RETAIN_VALUE_IS_WRONG
Incorrect retain value specified.
Definition: EspATMQTT.h:144
@ AT_MQTT_LWT_RETAIN_VALUE_IS_WRONG
Incorrect LWT value specified.
Definition: EspATMQTT.h:127
void(* subscription_cb_t)(char *topic, char *mqttdata)
Definition: EspATMQTT.h:185
@ AT_MQTT_CA_READ_FAILED
Failed to read the CA.
Definition: EspATMQTT.h:104
@ AT_MQTT_HOSTNAME_VERIFY_FAILED
Hostname lookup failed.
Definition: EspATMQTT.h:152
@ AT_MQTT_QOS_READ_FAILED
Failed to read QoS parameter.
Definition: EspATMQTT.h:141
@ AT_MQTT_RETAIN_READ_FAILED
Failed to read retain parameter.
Definition: EspATMQTT.h:143
mqtt_status_t close(uint32_t linkID)
Close (all) conection/s with the specified link ID.
Definition: EspATMQTT.cpp:1067