![]() |
WE310F5
39.00.000
|
This section describes the M2MB APIs to perform various MQTT client operations. More...
This section describes the M2MB APIs to perform various MQTT client operations.
#define M2MB_MQTT_MAX_SUBSCRIBE_TOPICS 32 |
Maximum number of topics can be subsribed per connection
Definition at line 66 of file m2mb_mqtt.h.
typedef struct M2MB_MQTT_CONN_PARAMS M2MB_MQTT_CONN_PARAMS_T |
MQTT connect parameters.
MQTT client connect parameters used in m2mb_mqtt_connect API.
typedef VOID(* M2MB_MQTT_CONNECT_CB_T) (M2MB_MQTT_CTXT_HANDLE handle, INT32 status) |
User registered callback for MQTT connection status, registered during m2mb_mqtt_connect call.
This callback function is called to notify the user about the connection request status. This callback function is called to notify the user if the connection status changes(asynchronous disconnect) after connection done. m2mb_mqtt_connect API is non blocking API, so after m2mb_mqtt_connect call returns success, user has to wait till the connect callback gets called to do further operations on perticular MQTT client.
[out] | handle | Argument provided to the user during m2mb_mqtt_open() |
[out] | status | Connection status, status values are explained in m2mb_net_status.h file |
Example
Definition at line 140 of file m2mb_mqtt.h.
typedef enum M2MB_MQTT_CONNECT_STATUS M2MB_MQTT_CONNECT_STATUS_E |
Connection status codes
typedef VOID* M2MB_MQTT_CTXT_HANDLE |
MQTT context handle.
This is obtained from m2mb_mqtt_open API and then used in subsequent MQTT APIs.
Definition at line 70 of file m2mb_mqtt.h.
typedef VOID(* M2MB_MQTT_MSG_HNDLR_CB_T) (M2MB_MQTT_CTXT_HANDLE handle, void *arg, INT32 reason, const UINT8 *topic, UINT16 topic_Length, const UINT8 *msg, UINT32 msg_Length, UINT32 QOS) |
User registered callback for incoming messages for subscribed topics.
This callback function is called to notify user about the incoming messages.
[out] | handle | Argument provided to the user during m2mb_mqtt_open() |
[out] | arg | user provided subscribe call back arguments. |
[out] | reason | reason of incoming topic(M2MB_MQTT_SUBSCRIBE_REASON_E) |
[out] | topic | incoming topic name. |
[out] | topic_Length | incoming topic length. |
[out] | msg | incoming message. |
[out] | msg_Length | incoming message length. |
[out] | QoS | Granted QOS for this subscription when 'reason' is M2MB_MQTT_SUBSCRIPTION_GRANTED or QOS for 'msg' delivered by the broker when 'reason' is M2MB_MQTT_SUBSCRIPTION_MSG. |
Example
Definition at line 183 of file m2mb_mqtt.h.
typedef struct M2MB_MQTT_OPEN_PARAMS M2MB_MQTT_OPEN_PARAMS_T |
MQTT client Open parameters.
MQTT client open parameters used in m2mb_mqtt_open API.
typedef enum M2MB_MQTT_SUBSCRIBE_REASON_E M2MB_MQTT_SUBSCRIBE_REASON_E |
MQTT client subscribe reason.
MQTT client subscribe reason for use in M2MB_MQTT_CONNECT_CB_T callback.
Connection status codes
Definition at line 88 of file m2mb_mqtt.h.
MQTT client subscribe reason.
MQTT client subscribe reason for use in M2MB_MQTT_CONNECT_CB_T callback.
Definition at line 79 of file m2mb_mqtt.h.
M2MB_STATUS_T m2mb_mqtt_close | ( | M2MB_MQTT_CTXT_HANDLE | mqtt_handle | ) |
closes MQTT instance.
m2mb_mqtt_close frees all resources allocated by m2mb_mqtt_open.
[in] | mqtt_handle | mqtt handle obtained from m2mb_mqtt_open API. |
Example
M2MB_STATUS_T m2mb_mqtt_connect | ( | M2MB_MQTT_CTXT_HANDLE | mqtt_handle, |
M2MB_MQTT_CONN_PARAMS_T * | p_conn_params | ||
) |
performs MQTT connection to the server.
m2mb_mqtt_connect API connects to the server.
[in] | mqtt_handle | mqtt handle obtained from m2mb_mqtt_open API. |
[in] | p_conn_params | pointer to connection parameters of type M2MB_MQTT_CONN_PARAMS_T. |
Example
M2MB_STATUS_T m2mb_mqtt_deinit | ( | VOID | ) |
deinitializes MQTT module.
deintializes mqtt module and frees all resources allocated by m2mb_mqtt_init API.
M2MB_STATUS_T m2mb_mqtt_disconnect | ( | M2MB_MQTT_CTXT_HANDLE | mqtt_handle | ) |
Disconnect from the server(broker).
m2mb_mqtt_disconnect API sends disconnect packet to the broker.
[in] | mqtt_handle | mqtt handle obtained from m2mb_mqtt_open API. |
Example
M2MB_STATUS_T m2mb_mqtt_init | ( | VOID | ) |
initializes MQTT module.
m2mb_mqtt_init intializes mqtt module resources required for MQTT.
Example
M2MB_STATUS_T m2mb_mqtt_open | ( | M2MB_MQTT_CTXT_HANDLE * | handle, |
M2MB_MQTT_OPEN_PARAMS_T * | p_open_params | ||
) |
Creates MQTT instance for the MQTT client.
m2mb_mqtt_open creates a new MQTT client instance.
[out] | mqtt_handle | mqtt handle for a new MQTT client instance. |
[in] | p_open_params | pointer to open parameters of type M2MB_MQTT_OPEN_PARAMS_T. |
Example
M2MB_STATUS_T m2mb_mqtt_publish | ( | M2MB_MQTT_CTXT_HANDLE | mqtt_handle, |
INT32 | qos, | ||
INT32 | retain, | ||
UINT16 | message_id, | ||
const UINT8 * | topic, | ||
const UINT8 * | data, | ||
INT32 | data_len | ||
) |
Publishes a message on a given topic.
m2mb_mqtt_publish Publishes a message on a given topic.
[out] | mqtt_handle | mqtt handle obtained from m2mb_mqtt_open API. |
[in] | qos | Integer value 0, 1, or 2 indicating the QOS to be used for msg. |
[in] | retain | Set to TRUE to make the message retained. |
[in] | message_id | Message ID |
[in] | topic | Topic name |
[in] | data | Data to publish |
[in] | data_len | Data length. |
Example
M2MB_STATUS_T m2mb_mqtt_subscribe | ( | M2MB_MQTT_CTXT_HANDLE | mqtt_handle, |
UINT16 | msg_id, | ||
const UINT8 * | topic, | ||
INT32 | qos, | ||
M2MB_MQTT_MSG_HNDLR_CB_T | cbk, | ||
VOID * | cbk_arg | ||
) |
m2mb_mqtt_subscribe is called to Subscribe.
m2mb_mqtt_subscribe Subscribes to one topic.
[out] | mqtt_handle | mqtt handle obtained from m2mb_mqtt_open API. |
[in] | msg_id | message id |
[in] | topic | topic name |
[in] | qos | Integer value 0, 1, or 2 indicating the QOS to be used for msg. |
[in] | cbk | User callback for incoming messages |
[in] | cbk_arg | User callback arguments for incoming messages. |
Example
M2MB_STATUS_T m2mb_mqtt_unsubscribe | ( | M2MB_MQTT_CTXT_HANDLE | mqtt_handle, |
UINT16 | msg_id, | ||
const UINT8 * | topic | ||
) |
unsubscribe to a perticular topic.
unsubscribe to a given topic.
[out] | mqtt_handle | mqtt handle obtained from m2mb_mqtt_open API. |
[in] | msg_id | message id |
[in] | topic | topic name |
Example