Zephyr API Documentation 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
mqtt.h File Reference

MQTT Client Implementation. More...

#include <stddef.h>
#include <zephyr/kernel.h>
#include <zephyr/types.h>
#include <zephyr/net/tls_credentials.h>
#include <zephyr/net/net_ip.h>
#include <zephyr/sys/mutex.h>
#include <zephyr/net/websocket.h>

Go to the source code of this file.

Data Structures

struct  mqtt_utf8
 Abstracts UTF-8 encoded strings. More...
 
struct  mqtt_binstr
 Abstracts binary strings. More...
 
struct  mqtt_topic
 Abstracts MQTT UTF-8 encoded topic that can be subscribed to or published. More...
 
struct  mqtt_publish_message
 Parameters for a publish message. More...
 
struct  mqtt_connack_param
 Parameters for a connection acknowledgment (CONNACK). More...
 
struct  mqtt_puback_param
 Parameters for MQTT publish acknowledgment (PUBACK). More...
 
struct  mqtt_pubrec_param
 Parameters for MQTT publish receive (PUBREC). More...
 
struct  mqtt_pubrel_param
 Parameters for MQTT publish release (PUBREL). More...
 
struct  mqtt_pubcomp_param
 Parameters for MQTT publish complete (PUBCOMP). More...
 
struct  mqtt_suback_param
 Parameters for MQTT subscription acknowledgment (SUBACK). More...
 
struct  mqtt_unsuback_param
 Parameters for MQTT unsubscribe acknowledgment (UNSUBACK). More...
 
struct  mqtt_publish_param
 Parameters for a publish message (PUBLISH). More...
 
struct  mqtt_subscription_list
 List of topics in a subscription request. More...
 
union  mqtt_evt_param
 Defines event parameters notified along with asynchronous events to the application. More...
 
struct  mqtt_evt
 Defines MQTT asynchronous event notified to the application. More...
 
struct  mqtt_sec_config
 TLS configuration for secure MQTT transports. More...
 
struct  mqtt_transport
 MQTT transport specific data. More...
 
struct  mqtt_internal
 MQTT internal state. More...
 
struct  mqtt_client
 MQTT Client definition to maintain information relevant to the client. More...
 

Macros

#define MQTT_UTF8_LITERAL(literal)
 Initialize UTF-8 encoded string from C literal string.
 

Typedefs

typedef void(* mqtt_evt_cb_t) (struct mqtt_client *client, const struct mqtt_evt *evt)
 Asynchronous event notification callback registered by the application.
 

Enumerations

enum  mqtt_evt_type {
  MQTT_EVT_CONNACK , MQTT_EVT_DISCONNECT , MQTT_EVT_PUBLISH , MQTT_EVT_PUBACK ,
  MQTT_EVT_PUBREC , MQTT_EVT_PUBREL , MQTT_EVT_PUBCOMP , MQTT_EVT_SUBACK ,
  MQTT_EVT_UNSUBACK , MQTT_EVT_PINGRESP
}
 MQTT Asynchronous Events notified to the application from the module through the callback registered by the application. More...
 
enum  mqtt_version { MQTT_VERSION_3_1_0 = 3 , MQTT_VERSION_3_1_1 = 4 }
 MQTT version protocol level. More...
 
enum  mqtt_qos { MQTT_QOS_0_AT_MOST_ONCE = 0x00 , MQTT_QOS_1_AT_LEAST_ONCE = 0x01 , MQTT_QOS_2_EXACTLY_ONCE = 0x02 }
 MQTT Quality of Service types. More...
 
enum  mqtt_conn_return_code {
  MQTT_CONNECTION_ACCEPTED = 0x00 , MQTT_UNACCEPTABLE_PROTOCOL_VERSION = 0x01 , MQTT_IDENTIFIER_REJECTED = 0x02 , MQTT_SERVER_UNAVAILABLE = 0x03 ,
  MQTT_BAD_USER_NAME_OR_PASSWORD = 0x04 , MQTT_NOT_AUTHORIZED = 0x05
}
 MQTT CONNACK return codes. More...
 
enum  mqtt_suback_return_code { MQTT_SUBACK_SUCCESS_QoS_0 = 0x00 , MQTT_SUBACK_SUCCESS_QoS_1 = 0x01 , MQTT_SUBACK_SUCCESS_QoS_2 = 0x02 , MQTT_SUBACK_FAILURE = 0x80 }
 MQTT SUBACK return codes. More...
 
enum  mqtt_transport_type { MQTT_TRANSPORT_NON_SECURE , MQTT_TRANSPORT_NUM }
 MQTT transport type. More...
 

Functions

void mqtt_client_init (struct mqtt_client *client)
 Initializes the client instance.
 
int mqtt_connect (struct mqtt_client *client)
 API to request new MQTT client connection.
 
int mqtt_publish (struct mqtt_client *client, const struct mqtt_publish_param *param)
 API to publish messages on topics.
 
int mqtt_publish_qos1_ack (struct mqtt_client *client, const struct mqtt_puback_param *param)
 API used by client to send acknowledgment on receiving QoS1 publish message.
 
int mqtt_publish_qos2_receive (struct mqtt_client *client, const struct mqtt_pubrec_param *param)
 API used by client to send acknowledgment on receiving QoS2 publish message.
 
int mqtt_publish_qos2_release (struct mqtt_client *client, const struct mqtt_pubrel_param *param)
 API used by client to request release of QoS2 publish message.
 
int mqtt_publish_qos2_complete (struct mqtt_client *client, const struct mqtt_pubcomp_param *param)
 API used by client to send acknowledgment on receiving QoS2 publish release message.
 
int mqtt_subscribe (struct mqtt_client *client, const struct mqtt_subscription_list *param)
 API to request subscription of one or more topics on the connection.
 
int mqtt_unsubscribe (struct mqtt_client *client, const struct mqtt_subscription_list *param)
 API to request unsubscription of one or more topics on the connection.
 
int mqtt_ping (struct mqtt_client *client)
 API to send MQTT ping.
 
int mqtt_disconnect (struct mqtt_client *client)
 API to disconnect MQTT connection.
 
int mqtt_abort (struct mqtt_client *client)
 API to abort MQTT connection.
 
int mqtt_live (struct mqtt_client *client)
 This API should be called periodically for the client to be able to keep the connection alive by sending Ping Requests if need be.
 
int mqtt_keepalive_time_left (const struct mqtt_client *client)
 Helper function to determine when next keep alive message should be sent.
 
int mqtt_input (struct mqtt_client *client)
 Receive an incoming MQTT packet.
 
int mqtt_read_publish_payload (struct mqtt_client *client, void *buffer, size_t length)
 Read the payload of the received PUBLISH message.
 
int mqtt_read_publish_payload_blocking (struct mqtt_client *client, void *buffer, size_t length)
 Blocking version of mqtt_read_publish_payload function.
 
int mqtt_readall_publish_payload (struct mqtt_client *client, uint8_t *buffer, size_t length)
 Blocking version of mqtt_read_publish_payload function which runs until the required number of bytes are read.
 

Detailed Description

MQTT Client Implementation.

Note
The implementation assumes TCP module is enabled.
By default the implementation uses MQTT version 3.1.1.