m2mb API docs  37.00.006.0
m2mb API sets documentation
m2mb_mqtt.h File Reference

MQTT(Message Queuing Telemetry Transport) Client service. More...

Go to the source code of this file.

Data Structures

struct  M2MB_MQTT_TOPIC
 MQTT Topic Structure This is used in m2mb_mqtt_subscribe and m2mb_mqtt_unsubscribe API. More...
 

Functions

M2MB_MQTT_RESPONSE_E m2mb_mqtt_get_new_msg_status (M2MB_MQTT_HANDLE handle, UINT8 *new_msg_ind)
 m2mb_mqtt_get_new_msg_status gets MQTT new publish message status More...
 
#define m2mb_mqtt_conf_(h, args, ...)   m2mb_mqtt_conf( h, CMDS( args ) )
 
enum  M2MB_MQTT_IND_E { M2MB_MQTT_INDICATION_DISCONNECT }
 MQTT Indications enum. More...
 
enum  M2MB_MQTT_RESPONSE_E {
  M2MB_MQTT_SUCCESS = 0, M2MB_MQTT_ERROR_BAD_ARG = -1, M2MB_MQTT_ERROR_OUT_OF_BUFFER = -2, M2MB_MQTT_ERROR_MALFORMED_DATA = -3,
  M2MB_MQTT_ERROR_PACKET_TYPE = -4, M2MB_MQTT_ERROR_PACKET_ID = -5, M2MB_MQTT_ERROR_TLS_CONNECT = -6, M2MB_MQTT_ERROR_TIMEOUT = -7,
  M2MB_MQTT_ERROR_NETWORK = -8, M2MB_MQTT_ERROR_MEMORY = -9, M2MB_MQTT_ERROR_STAT = -10, M2MB_MQTT_ERROR_PROPERTY = -11,
  M2MB_MQTT_ERROR_SERVER_PROP = -12, M2MB_MQTT_ERROR_CALLBACK = -13, M2MB_MQTT_ERROR_SEM = -14, M2MB_MQTT_ERROR_TOPIC_LIST = -15,
  M2MB_MQTT_ERROR_ASYNC_THREAD = -16, M2MB_MQTT_ERROR_QUEUE = -17, M2MB_MQTT_PROTOCOL_UNSUPPORTED = -51, M2MB_MQTT_IDENTIFIER_REJECTED = -52,
  M2MB_MQTT_SERVER_UNAVAILABLE = -53, M2MB_MQTT_BAD_USER_PASS = -54, M2MB_MQTT_NOT_AUTHORISED = -55, M2MB_MQTT_CONTINUE = -101,
  M2MB_MQTT_STDIN_WAKE = -102
}
 MQTT APIs response enum. More...
 
enum  M2MB_MQTT_STATUS_E {
  M2MB_MQTT_NOT_CONNECTED, M2MB_MQTT_CLIENT_CONNECTED, M2MB_MQTT_CONN_RESET_BY_PEER, M2MB_MQTT_PINGREQ_TIMEOUT_FAIL,
  M2MB_MQTT_CONNACK_TIMEOUT, M2MB_MQTT_CONNECT_TIMEOUT, M2MB_MQTT_FATAL_ERROR, M2MB_MQTT_NETWORK_ERROR,
  M2MB_MQTT_STATUS_DISCONNECT_INITIATED, M2MB_MQTT_STATUS_UNKNOWN = 0xFF
}
 mqtt client status enum More...
 
enum  M2MB_MQTT_ACTION_E {
  M2MB_MQTT_SET_CLIENT_ID, M2MB_MQTT_SET_TIMEOUT_MS, M2MB_MQTT_SECURE_OPT, M2MB_MQTT_SET_KEEPALIVE_SEC,
  M2MB_MQTT_SET_CLEAN_SESSION, M2MB_MQTT_SET_PROTOCOL_LEVEL, M2MB_MQTT_SET_LAST_WILL, M2MB_MQTT_SET_USERNAME,
  M2MB_MQTT_SET_PASSWORD, M2MB_MQTT_SET_PDP_CONTEXT, M2MB_MQTT_GET_CLIENT_ID, M2MB_MQTT_GET_TIMEOUT_MS,
  M2MB_MQTT_GET_KEEPALIVE_SEC, M2MB_MQTT_GET_CLEAN_SESSION, M2MB_MQTT_GET_PROTOCOL_LEVEL, M2MB_MQTT_GET_LAST_WILL,
  M2MB_MQTT_GET_PDP_CONTEXT, M2MB_MQTT_SET_PDP_HANDLE, M2MB_MQTT_SET_TCP_WINDOW, M2MB_MQTT_SET_TCP_WINDOWSCALE,
  M2MB_MQTT_MAX_CONF = 0x3F
}
 MQTT actions enum List of actions performed through m2mb_mqtt_conf API. More...
 
enum  M2MB_MQTT_QOS_E { M2MB_MQTT_QOS_0 = 0, M2MB_MQTT_QOS_1 = 1, M2MB_MQTT_QOS_2 = 2 }
 MQTT QoS Enum. More...
 
enum  M2MB_MQTT_RX_STATUS_E { M2MB_MQTT_RX_FINISHED, M2MB_MQTT_RX_MORE_DATA }
 MQTT Receive Data Status Enum. More...
 
typedef HANDLE M2MB_MQTT_HANDLE
 MQTT context handle. This is obtained from m2mb_mqtt_init API and then used in subsequent MQTT APIs.
 
typedef void(* m2mb_mqtt_ind_callback) (M2MB_MQTT_HANDLE Handle, M2MB_MQTT_IND_E event, UINT16 resp_size, void *resp, void *userdata)
 MQTT call back prototype. More...
 
typedef void(* M2MB_MQTT_MSG_HNDLR_CB_T) (M2MB_MQTT_HANDLE Handle, void *arg, const CHAR *topic, UINT16 topic_length, const CHAR *msg, UINT32 msg_length, M2MB_MQTT_RX_STATUS_E status)
 MQTT message handler call back prototype. More...
 
typedef struct M2MB_MQTT_TOPIC M2MB_MQTT_TOPIC_T
 MQTT Topic Structure This is used in m2mb_mqtt_subscribe and m2mb_mqtt_unsubscribe API.
 
M2MB_MQTT_RESPONSE_E m2mb_mqtt_init (M2MB_MQTT_HANDLE *h, m2mb_mqtt_ind_callback callback, void *userdata)
 m2mb_mqtt_init is called to initialize MQTT context. More...
 
M2MB_MQTT_RESPONSE_E m2mb_mqtt_deinit (M2MB_MQTT_HANDLE Handle)
 m2mb_mqtt_deinit deinitializes MQTT service for specified MQTT client. More...
 
M2MB_MQTT_RESPONSE_E m2mb_mqtt_conf (M2MB_MQTT_HANDLE Handle, UINT8 nCmds,...)
 m2mb_mqtt_conf sets/gets some MQTT parameters and configurations. More...
 
M2MB_MQTT_RESPONSE_E m2mb_mqtt_connect (M2MB_MQTT_HANDLE Handle, const CHAR *host, UINT32 port)
 m2mb_mqtt_connect is called to connect to the specified MQTT broker. More...
 
M2MB_MQTT_RESPONSE_E m2mb_mqtt_disconnect (M2MB_MQTT_HANDLE Handle)
 m2mb_mqtt_disconnect is called to disconnect from the MQTT broker. More...
 
M2MB_MQTT_RESPONSE_E m2mb_mqtt_publish (M2MB_MQTT_HANDLE Handle, M2MB_MQTT_QOS_E qos, UINT8 retain, UINT16 message_id, const CHAR *topic, const CHAR *data, UINT32 data_len)
 m2mb_mqtt_publish is called to Publish a message to the MQTT broker. More...
 
M2MB_MQTT_RESPONSE_E m2mb_mqtt_subscribe (M2MB_MQTT_HANDLE Handle, UINT16 message_id, UINT32 topic_count, M2MB_MQTT_TOPIC_T *pTopics)
 m2mb_mqtt_subscribe is called to Subscribe. More...
 
M2MB_MQTT_RESPONSE_E m2mb_mqtt_unsubscribe (M2MB_MQTT_HANDLE Handle, UINT16 message_id, UINT32 topic_count, M2MB_MQTT_TOPIC_T *topics)
 m2mb_mqtt_unsubscribe is called to unsubscribe. More...
 
M2MB_MQTT_RESPONSE_E m2mb_mqtt_ping (M2MB_MQTT_HANDLE Handle)
 m2mb_mqtt_ping is called to ping More...
 
M2MB_MQTT_RESPONSE_E m2mb_mqtt_getClientStatus (M2MB_MQTT_HANDLE handle, M2MB_MQTT_STATUS_E *status)
 m2mb_mqtt_getClientStatus gets MQTT client current status More...
 
M2MB_MQTT_RESPONSE_E m2mb_mqtt_setClientStatus (M2MB_MQTT_HANDLE handle, M2MB_MQTT_STATUS_E status)
 m2mb_mqtt_setClientStatus sets MQTT client current status More...
 
M2MB_MQTT_RESPONSE_E m2mb_mqtt_setMessageCb (M2MB_MQTT_HANDLE h, CHAR *topic_filter, UINT32 topic_size, M2MB_MQTT_MSG_HNDLR_CB_T cb, void *arg, UINT32 arg_size)
 m2mb_mqtt_setMessageCb sets Message callback function More...
 

Detailed Description

MQTT(Message Queuing Telemetry Transport) Client service.

m2m_generic/common/m2mb_inc/m2mb_mqtt.h

The MQTT (Message Queuing Telemetry Transport) Client service provides a collection of APIs that allow the application to implement client functionalities, such as CONNECT, SUBSCRIBE, UNSUBSCRIBE, PUBLISH, DISCONNECT, and so on.

Note
Dependencies: m2mb_types.h
Author
Oshin Bhatia

@changes Somesh Burkule

Date
25/10/2019

Function Documentation

◆ m2mb_mqtt_get_new_msg_status()

M2MB_MQTT_RESPONSE_E m2mb_mqtt_get_new_msg_status ( M2MB_MQTT_HANDLE  handle,
UINT8 *  new_msg_ind 
)

m2mb_mqtt_get_new_msg_status gets MQTT new publish message status

This function allows to identify the received publish message data is from new publish message or the continuation of previous publish message itself. If client handle is not valid, it returns error.

Parameters
[in]handlehandle of the mqtt client
[out]statuspointer to the variable that will be filled with new publish message status (Example: 1 is to indicate new publish message, 0 is to indicate that the recived data is from the previous publish message)
Returns
M2MB_MQTT_RESPONSE_E values.
Note

Example

void mqtt_message_cb( M2MB_MQTT_HANDLE handle, void* arg, const CHAR* topic, UINT16 topic_length,
const CHAR* msg, UINT32 msg_length, M2MB_MQTT_RX_STATUS_E status )
{
UINT8 buf[1024];
UINT8 new_msg_ind = 0;
if(m2mb_mqtt_get_new_msg_status( handle, &new_msg_ind ) == M2MB_MQTT_SUCCESS)
{
if( new_msg_ind )
{
printf("Received data from new publish message");
}
else
{
printf("Received data for previous publish message");
}
}
memcpy(buf, topic, topic_length);
buf[topic_length] = '\0'; // Make sure it is null terminated
printf("MQTT Message: Topic %s, Len %d\r\n", buf, msg_length);
memcpy(buf, msg, msg_length);
buf[msg_length] = '\0'; // Make sure it is null terminated
printf("Message: %s", buf);
if(status == M2MB_MQTT_RX_MORE_DATA)
{
printf("More data to be received");
}
}
M2MB_MQTT_RX_MORE_DATA
Definition: m2mb_mqtt.h:278
m2mb_mqtt_get_new_msg_status
M2MB_MQTT_RESPONSE_E m2mb_mqtt_get_new_msg_status(M2MB_MQTT_HANDLE handle, UINT8 *new_msg_ind)
m2mb_mqtt_get_new_msg_status gets MQTT new publish message status
M2MB_MQTT_RX_STATUS_E
M2MB_MQTT_RX_STATUS_E
MQTT Receive Data Status Enum.
Definition: m2mb_mqtt.h:275
M2MB_MQTT_SUCCESS
Definition: m2mb_mqtt.h:76
M2MB_MQTT_HANDLE
HANDLE M2MB_MQTT_HANDLE
MQTT context handle. This is obtained from m2mb_mqtt_init API and then used in subsequent MQTT APIs.
Definition: m2mb_mqtt.h:60