Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MQTT client
[Applications]
Data Structures | |
struct | mqtt_connect_client_info_t |
Client information and connection parameters. More... | |
Modules | |
Options | |
Typedefs | |
typedef void(* | mqtt_connection_cb_t )(mqtt_client_t *client, void *arg, mqtt_connection_status_t status) |
Function prototype for mqtt connection status callback. | |
typedef void(* | mqtt_incoming_data_cb_t )(void *arg, const u8_t *data, u16_t len, u8_t flags) |
Function prototype for MQTT incoming publish data callback function. | |
typedef void(* | mqtt_incoming_publish_cb_t )(void *arg, const char *topic, u32_t tot_len) |
Function prototype for MQTT incoming publish function. | |
typedef void(* | mqtt_request_cb_t )(void *arg, err_t err) |
Function prototype for mqtt request callback. | |
Enumerations | |
enum | mqtt_connection_status_t |
Connection status codes. More... | |
enum | { MQTT_DATA_FLAG_LAST = 1 } |
Data callback flags. More... | |
Functions | |
err_t | mqtt_publish (mqtt_client_t *client, const char *topic, const void *payload, u16_t payload_length, u8_t qos, u8_t retain, mqtt_request_cb_t cb, void *arg) |
MQTT publish function. | |
err_t | mqtt_sub_unsub (mqtt_client_t *client, const char *topic, u8_t qos, mqtt_request_cb_t cb, void *arg, u8_t sub) |
MQTT subscribe/unsubscribe function. | |
void | mqtt_set_inpub_callback (mqtt_client_t *client, mqtt_incoming_publish_cb_t pub_cb, mqtt_incoming_data_cb_t data_cb, void *arg) |
Set callback to handle incoming publish requests from server. | |
mqtt_client_t * | mqtt_client_new (void) |
Create a new MQTT client instance. | |
err_t | mqtt_client_connect (mqtt_client_t *client, const ip_addr_t *ip_addr, u16_t port, mqtt_connection_cb_t cb, void *arg, const struct mqtt_connect_client_info_t *client_info) |
Connect to MQTT server. | |
void | mqtt_disconnect (mqtt_client_t *client) |
Disconnect from MQTT server. | |
u8_t | mqtt_client_is_connected (mqtt_client_t *client) |
Check connection with server. |
Detailed Description
Typedef Documentation
typedef void(* mqtt_connection_cb_t)(mqtt_client_t *client, void *arg, mqtt_connection_status_t status) |
Function prototype for mqtt connection status callback.
Called when client has connected to the server after initiating a mqtt connection attempt by calling mqtt_connect() or when connection is closed by server or an error
- Parameters:
-
client MQTT client itself arg Additional argument to pass to the callback function status Connect result code or disconnection notification
- See also:
- mqtt_connection_status_t
typedef void(* mqtt_incoming_data_cb_t)(void *arg, const u8_t *data, u16_t len, u8_t flags) |
Function prototype for MQTT incoming publish data callback function.
Called when data arrives to a subscribed topic
- See also:
- mqtt_subscribe
- Parameters:
-
arg Additional argument to pass to the callback function data User data, pointed object, data may not be referenced after callback return, NULL is passed when all publish data are delivered len Length of publish data fragment flags MQTT_DATA_FLAG_LAST set when this call contains the last part of data from publish message
typedef void(* mqtt_incoming_publish_cb_t)(void *arg, const char *topic, u32_t tot_len) |
Function prototype for MQTT incoming publish function.
Called when an incoming publish arrives to a subscribed topic
- See also:
- mqtt_subscribe
- Parameters:
-
arg Additional argument to pass to the callback function topic Zero terminated Topic text string, topic may not be referenced after callback return tot_len Total length of publish data, if set to 0 (no publish payload) data callback will not be invoked
typedef void(* mqtt_request_cb_t)(void *arg, err_t err) |
Function prototype for mqtt request callback.
Called when a subscribe, unsubscribe or publish request has completed
- Parameters:
-
arg Pointer to user data supplied when invoking request err ERR_OK on success ERR_TIMEOUT if no response was received within timeout, ERR_ABRT if (un)subscribe was denied
Enumeration Type Documentation
anonymous enum |
Function Documentation
err_t mqtt_client_connect | ( | mqtt_client_t * | client, |
const ip_addr_t * | ip_addr, | ||
u16_t | port, | ||
mqtt_connection_cb_t | cb, | ||
void * | arg, | ||
const struct mqtt_connect_client_info_t * | client_info | ||
) |
Connect to MQTT server.
Connect to server.
- Parameters:
-
client MQTT client ip_addr Server IP port Server port cb Connection state change callback arg User supplied argument to connection callback client_info Client identification and connection options
- Returns:
- ERR_OK if successful,
- See also:
- err_t enum for other results
Definition at line 1200 of file lwip_mqtt.c.
u8_t mqtt_client_is_connected | ( | mqtt_client_t * | client ) |
Check connection with server.
Check connection status.
- Parameters:
-
client MQTT client
- Returns:
- 1 if connected to server, 0 otherwise
Definition at line 1335 of file lwip_mqtt.c.
mqtt_client_t* mqtt_client_new | ( | void | ) |
Create a new MQTT client instance.
Create new client.
- Returns:
- Pointer to instance on success, NULL otherwise
Definition at line 1178 of file lwip_mqtt.c.
void mqtt_disconnect | ( | mqtt_client_t * | client ) |
Disconnect from MQTT server.
Disconnect from server.
- Parameters:
-
client MQTT client
Definition at line 1317 of file lwip_mqtt.c.
err_t mqtt_publish | ( | mqtt_client_t * | client, |
const char * | topic, | ||
const void * | payload, | ||
u16_t | payload_length, | ||
u8_t | qos, | ||
u8_t | retain, | ||
mqtt_request_cb_t | cb, | ||
void * | arg | ||
) |
MQTT publish function.
Publish data to topic.
- Parameters:
-
client MQTT client topic Publish topic string payload Data to publish (NULL is allowed) payload_length,: Length of payload (0 is allowed) qos Quality of service, 0 1 or 2 retain MQTT retain flag cb Callback to call when publish is complete or has timed out arg User supplied argument to publish callback
- Returns:
- ERR_OK if successful ERR_CONN if client is disconnected ERR_MEM if short on memory
Definition at line 1024 of file lwip_mqtt.c.
void mqtt_set_inpub_callback | ( | mqtt_client_t * | client, |
mqtt_incoming_publish_cb_t | pub_cb, | ||
mqtt_incoming_data_cb_t | data_cb, | ||
void * | arg | ||
) |
Set callback to handle incoming publish requests from server.
Set callback to call for incoming publish.
- Parameters:
-
client MQTT client pub_cb Callback invoked when publish starts, contain topic and total length of payload data_cb Callback for each fragment of payload that arrives arg User supplied argument to both callbacks
Definition at line 1163 of file lwip_mqtt.c.
err_t mqtt_sub_unsub | ( | mqtt_client_t * | client, |
const char * | topic, | ||
u8_t | qos, | ||
mqtt_request_cb_t | cb, | ||
void * | arg, | ||
u8_t | sub | ||
) |
MQTT subscribe/unsubscribe function.
Common function for subscribe and unsubscribe.
- Parameters:
-
client MQTT client topic topic to subscribe to qos Quality of service, 0 1 or 2 (only used for subscribe) cb Callback to call when subscribe/unsubscribe reponse is received arg User supplied argument to publish callback sub 1 for subscribe, 0 for unsubscribe
- Returns:
- ERR_OK if successful,
- See also:
- err_t enum for other results
Definition at line 1099 of file lwip_mqtt.c.
Generated on Tue Jul 12 2022 12:22:34 by
