Zephyr Project API  3.3.0
A Scalable Open Source RTOS
MQTT Client library

MQTT-SN Client Implementation. More...

Data Structures

struct  mqtt_sn_data
 Abstracts memory buffers. More...
 
union  mqtt_sn_evt_param
 
struct  mqtt_sn_evt
 
struct  mqtt_sn_transport
 Structure to describe an MQTT-SN transport. More...
 
struct  mqtt_sn_client
 

Macros

#define MQTT_SN_DATA_STRING_LITERAL(literal)   ((struct mqtt_sn_data){literal, sizeof(literal) - 1})
 Initialize memory buffer from C literal string. More...
 
#define MQTT_SN_DATA_BYTES(...)    ((struct mqtt_sn_data) { (uint8_t[]){ __VA_ARGS__ }, sizeof((uint8_t[]){ __VA_ARGS__ })})
 Initialize memory buffer from single bytes. More...
 

Typedefs

typedef void(* mqtt_sn_evt_cb_t) (struct mqtt_sn_client *client, const struct mqtt_sn_evt *evt)
 Asynchronous event notification callback registered by the application. More...
 

Enumerations

enum  mqtt_sn_qos { MQTT_SN_QOS_0 , MQTT_SN_QOS_1 , MQTT_SN_QOS_2 , MQTT_SN_QOS_M1 }
 
enum  mqtt_sn_topic_type { MQTT_SN_TOPIC_TYPE_NORMAL , MQTT_SN_TOPIC_TYPE_PREDEF , MQTT_SN_TOPIC_TYPE_SHORT }
 
enum  mqtt_sn_return_code { MQTT_SN_CODE_ACCEPTED = 0x00 , MQTT_SN_CODE_REJECTED_CONGESTION = 0x01 , MQTT_SN_CODE_REJECTED_TOPIC_ID = 0x02 , MQTT_SN_CODE_REJECTED_NOTSUP = 0x03 }
 
enum  mqtt_sn_evt_type {
  MQTT_SN_EVT_CONNECTED , MQTT_SN_EVT_DISCONNECTED , MQTT_SN_EVT_ASLEEP , MQTT_SN_EVT_AWAKE ,
  MQTT_SN_EVT_PUBLISH , MQTT_SN_EVT_PINGRESP
}
 

Functions

int mqtt_sn_client_init (struct mqtt_sn_client *client, const struct mqtt_sn_data *client_id, struct mqtt_sn_transport *transport, mqtt_sn_evt_cb_t evt_cb, void *tx, size_t txsz, void *rx, size_t rxsz)
 Initialize a client. More...
 
void mqtt_sn_client_deinit (struct mqtt_sn_client *client)
 Deinitialize the client. More...
 
int mqtt_sn_connect (struct mqtt_sn_client *client, bool will, bool clean_session)
 Connect the client. More...
 
int mqtt_sn_disconnect (struct mqtt_sn_client *client)
 Disconnect the client. More...
 
int mqtt_sn_sleep (struct mqtt_sn_client *client, uint16_t duration)
 Set the client into sleep state for the given duration (seconds). More...
 
int mqtt_sn_subscribe (struct mqtt_sn_client *client, enum mqtt_sn_qos qos, struct mqtt_sn_data *topic_name)
 Subscribe to a given topic. More...
 
int mqtt_sn_unsubscribe (struct mqtt_sn_client *client, enum mqtt_sn_qos qos, struct mqtt_sn_data *topic_name)
 Unsubscribe from a topic. More...
 
int mqtt_sn_publish (struct mqtt_sn_client *client, enum mqtt_sn_qos qos, struct mqtt_sn_data *topic_name, bool retain, struct mqtt_sn_data *data)
 Publish a value. More...
 
int mqtt_sn_input (struct mqtt_sn_client *client)
 Check the transport for new incoming data. More...
 

Detailed Description

MQTT-SN Client Implementation.

MQTT-SN Client's Application interface is defined in this header. Targets protocol version 1.2.

Macro Definition Documentation

◆ MQTT_SN_DATA_BYTES

#define MQTT_SN_DATA_BYTES (   ...)     ((struct mqtt_sn_data) { (uint8_t[]){ __VA_ARGS__ }, sizeof((uint8_t[]){ __VA_ARGS__ })})

#include <include/zephyr/net/mqtt_sn.h>

Initialize memory buffer from single bytes.

Use it as follows:

struct mqtt_sn_data data = MQTT_SN_DATA_BYTES(0x13, 0x37);

◆ MQTT_SN_DATA_STRING_LITERAL

#define MQTT_SN_DATA_STRING_LITERAL (   literal)    ((struct mqtt_sn_data){literal, sizeof(literal) - 1})

#include <include/zephyr/net/mqtt_sn.h>

Initialize memory buffer from C literal string.

Use it as follows:

struct mqtt_sn_data topic = MQTT_SN_DATA_STRING_LITERAL("/zephyr");

Parameters
[in]literalLiteral string from which to generate mqtt_sn_data object.

Typedef Documentation

◆ mqtt_sn_evt_cb_t

typedef void(* mqtt_sn_evt_cb_t) (struct mqtt_sn_client *client, const struct mqtt_sn_evt *evt)

#include <include/zephyr/net/mqtt_sn.h>

Asynchronous event notification callback registered by the application.

Parameters
[in]clientIdentifies the client for which the event is notified.
[in]evtEvent description along with result and associated parameters (if any).

Enumeration Type Documentation

◆ mqtt_sn_evt_type

#include <include/zephyr/net/mqtt_sn.h>

Event types that can be emitted by the library.

Enumerator
MQTT_SN_EVT_CONNECTED 

Connected to a gateway

MQTT_SN_EVT_DISCONNECTED 

Disconnected

MQTT_SN_EVT_ASLEEP 

Entered ASLEEP state

MQTT_SN_EVT_AWAKE 

Entered AWAKE state

MQTT_SN_EVT_PUBLISH 

Received a PUBLISH message

MQTT_SN_EVT_PINGRESP 

Received a PINGRESP

◆ mqtt_sn_qos

#include <include/zephyr/net/mqtt_sn.h>

Quality of Service. QoS 0-2 work the same as basic MQTT, QoS -1 is an MQTT-SN addition. QOS -1 is not supported yet.

Enumerator
MQTT_SN_QOS_0 

QOS 0

MQTT_SN_QOS_1 

QOS 1

MQTT_SN_QOS_2 

QOS 2

MQTT_SN_QOS_M1 

QOS -1

◆ mqtt_sn_return_code

#include <include/zephyr/net/mqtt_sn.h>

Enumerator
MQTT_SN_CODE_ACCEPTED 

Accepted

MQTT_SN_CODE_REJECTED_CONGESTION 

Rejected: congestion

MQTT_SN_CODE_REJECTED_TOPIC_ID 

Rejected: Invalid Topic ID

MQTT_SN_CODE_REJECTED_NOTSUP 

Rejected: Not Supported

◆ mqtt_sn_topic_type

#include <include/zephyr/net/mqtt_sn.h>

MQTT-SN topic types.

Enumerator
MQTT_SN_TOPIC_TYPE_NORMAL 
MQTT_SN_TOPIC_TYPE_PREDEF 
MQTT_SN_TOPIC_TYPE_SHORT 

Function Documentation

◆ mqtt_sn_client_deinit()

void mqtt_sn_client_deinit ( struct mqtt_sn_client client)

#include <include/zephyr/net/mqtt_sn.h>

Deinitialize the client.

This removes all topics and publishes, and also deinits the transport.

◆ mqtt_sn_client_init()

int mqtt_sn_client_init ( struct mqtt_sn_client client,
const struct mqtt_sn_data client_id,
struct mqtt_sn_transport transport,
mqtt_sn_evt_cb_t  evt_cb,
void *  tx,
size_t  txsz,
void *  rx,
size_t  rxsz 
)

#include <include/zephyr/net/mqtt_sn.h>

Initialize a client.

◆ mqtt_sn_connect()

int mqtt_sn_connect ( struct mqtt_sn_client client,
bool  will,
bool  clean_session 
)

#include <include/zephyr/net/mqtt_sn.h>

Connect the client.

Returns
0 or a negative error code (errno.h) indicating reason of failure.

◆ mqtt_sn_disconnect()

int mqtt_sn_disconnect ( struct mqtt_sn_client client)

#include <include/zephyr/net/mqtt_sn.h>

Disconnect the client.

Returns
0 or a negative error code (errno.h) indicating reason of failure.

◆ mqtt_sn_input()

int mqtt_sn_input ( struct mqtt_sn_client client)

#include <include/zephyr/net/mqtt_sn.h>

Check the transport for new incoming data.

Call this function periodically, or if you have good reason to believe there is any data. If the client's transport struct contains a poll-function, this function is non-blocking.

Returns
0 or a negative error code (errno.h) indicating reason of failure.

◆ mqtt_sn_publish()

int mqtt_sn_publish ( struct mqtt_sn_client client,
enum mqtt_sn_qos  qos,
struct mqtt_sn_data topic_name,
bool  retain,
struct mqtt_sn_data data 
)

#include <include/zephyr/net/mqtt_sn.h>

Publish a value.

If the topic is not yet registered with the gateway, the library takes care of it.

Returns
0 or a negative error code (errno.h) indicating reason of failure.

◆ mqtt_sn_sleep()

int mqtt_sn_sleep ( struct mqtt_sn_client client,
uint16_t  duration 
)

#include <include/zephyr/net/mqtt_sn.h>

Set the client into sleep state for the given duration (seconds).

Returns
0 or a negative error code (errno.h) indicating reason of failure.

◆ mqtt_sn_subscribe()

int mqtt_sn_subscribe ( struct mqtt_sn_client client,
enum mqtt_sn_qos  qos,
struct mqtt_sn_data topic_name 
)

#include <include/zephyr/net/mqtt_sn.h>

Subscribe to a given topic.

Returns
0 or a negative error code (errno.h) indicating reason of failure.

◆ mqtt_sn_unsubscribe()

int mqtt_sn_unsubscribe ( struct mqtt_sn_client client,
enum mqtt_sn_qos  qos,
struct mqtt_sn_data topic_name 
)

#include <include/zephyr/net/mqtt_sn.h>

Unsubscribe from a topic.