m2mb API docs  25.21.003
m2mb API sets documentation
Documentation for m2mb_mqtt functionalities

This group includes all the information about m2mb_mqtt configuration and usage *. 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_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_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
}
 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...
 
#define M2MB_NTP_DEF_PORT   123
 NTP defaults. More...
 
#define M2MB_NTP_DEF_TIMEOUT   10
 
enum  M2MB_NTP_EVENTS_E {
  M2MB_NTP_VALID_TIME = 0, M2MB_NTP_ERR_NOT_ENOUGH_RESOURCES = -1, M2MB_NTP_ERR_REG_TIMEOUT = -2, M2MB_NTP_ERR_CONN_ERR = -3,
  M2MB_NTP_ERR_CONN_TIMEOUT = -4, M2MB_NTP_ERR_HOST_RESOLVE = -5, M2MB_NTP_ERR_INVALID_PARAMETER = -6, M2MB_NTP_ERR_SOCK_OPEN = -7,
  M2MB_NTP_ERR_TX_TIMEOUT = -8, M2MB_NTP_ERR_TX_ERROR = -9, M2MB_NTP_ERR_RX_TIMEOUT = -11, M2MB_NTP_ERROR = -20,
  M2MB_NTP_ERR_SERVER_AUTH_FAIL = -30, M2MB_NTP_ERR_KEYS_FILE_MISSING = -31
}
 NTP Events. More...
 
enum  M2MB_NTP_AUTH_TYPE_E { m2mb_ntp_noAuth = 0, m2mb_ntp_symmetricKey = 1, m2mb_ntp_autokey = 2 }
 Authentication options. More...
 
enum  M2MB_NTP_CFG_E {
  M2MB_NTP_CFG_TIMEOUT = 0, M2MB_NTP_CFG_PORT = 1, M2MB_NTP_CFG_SERVER = 2, M2MB_NTP_CFG_AUTH_TYPE = 3,
  M2MB_NTP_CFG_AUTH_KEYID = 4, M2MB_NTP_CFG_AUTH_KEYSFILE = 5
}
 
typedef HANDLE M2MB_NTP_HANDLE
 
typedef void(* m2mb_ntp_callback) (M2MB_NTP_HANDLE handle, M2MB_NTP_EVENTS_E ntp_event, UINT16 resp_size, void *resp_struct, void *cb_args)
 This is the ntp user callback function prototype. More...
 
M2MB_RESULT_E m2mb_ntp_init (M2MB_NTP_HANDLE *pHandle, m2mb_ntp_callback callback, void *cb_args)
 This is the ntp initialization function. More...
 
M2MB_RESULT_E m2mb_ntp_setCid (M2MB_NTP_HANDLE handle, INT16 cid)
 Set the CID to be used with NTP. More...
 
M2MB_RESULT_E m2mb_ntp_setCfg (M2MB_NTP_HANDLE handle, M2MB_NTP_CFG_E param, void *value)
 Set the one of the NTP parameters. More...
 
M2MB_RESULT_E m2mb_ntp_queryServerTime (M2MB_NTP_HANDLE handle)
 This is the ntp query function. More...
 
M2MB_RESULT_E m2mb_ntp_getVersion (M2MB_NTP_HANDLE handle, CHAR *version, UINT16 maxlen)
 This is the ntp version get function. More...
 
M2MB_RESULT_E m2mb_ntp_deinit (M2MB_NTP_HANDLE handle)
 This is the ntp deinitialization function. More...
 

Detailed Description

This group includes all the information about m2mb_mqtt configuration and usage *.

Macro Definition Documentation

◆ M2MB_NTP_DEF_PORT

#define M2MB_NTP_DEF_PORT   123

NTP defaults.

These defines provide default values for NTP related parameters. Default NTP server port.

◆ M2MB_NTP_DEF_TIMEOUT

#define M2MB_NTP_DEF_TIMEOUT   10

Default operation timeout in secs.

Typedef Documentation

◆ m2mb_mqtt_ind_callback

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.

This callback is triggered when MQTT client receives any event.(M2MB_MQTT_IND_E)

Parameters
[in]Handlehandle to the MQTT client instance on which MQTT message is received
[in]eventevent indication for which the callback has been triggered
[in]resp_sizesize of the data sent
[in]respresponse
[in]userdatauser data returned by callback function
Returns
None
Note

Example

void m2mb_mqtt_ind_callback( M2MB_MQTT_HANDLE Handle, M2MB_MQTT_IND_E event, UINT16 resp_size, void *resp, void *userdata );
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
result = m2mb_mqtt_init( &p_mqtt, m2mb_mqtt_ind_callback, NULL );
if(result != M2MB_MQTT_SUCCESS)
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
//Set Client ID
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_CLIENT_ID, "MQTT_demo" ) );
//Set Timeout in milliseconds
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_TIMEOUT_MS, 10*1000 ) );
//Set Keepalive in seconds
//Set Username
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_USERNAME, "aabbcc" ) );
//Set Password
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_PASSWORD, "1234567890" ) );
result = m2mb_mqtt_connect( p_mqtt, "api-dev.devicewise.com", 1883 ) );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_deinit succeeded");
}
//... Use MQTT APIs ....
result = m2mb_mqtt_deinit( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_deinit succeeded");
}
}

◆ M2MB_MQTT_MSG_HNDLR_CB_T

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.

This callback function is called when a message is received on a subscribed topic. This is registered while subscribing to a topic.

Parameters
[in]HandleThe mqtt handle associated with the client for which data is received
[in]argUser defined pointer, set while registering the callback
[in]topicThe topic string
[in]topic_LengthThe topic string len
[in]msgThe received payload
[in]msg_LengthThe payload size in bytes
[in]statusStatus whethe more data is pending.
Returns
None
Note
If the message payload is larger than receive data buffer (1024), this callback will be called multiple times for the same message recived. Parameter status is used to identify if there is pending data.

Example

void m2mb_mqtt_ind_callback( M2MB_MQTT_HANDLE Handle, M2MB_MQTT_IND_E event, UINT16 resp_size, void *resp, void *userdata );
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void mqtt_topic_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];
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");
}
}
void main(void)
{
result = m2mb_mqtt_init( &p_mqtt, m2mb_mqtt_ind_callback, NULL );
if(result != M2MB_MQTT_SUCCESS)
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
//Set Client ID
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_CLIENT_ID, "MQTT_demo" ) );
//Set Timeout in milliseconds
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_TIMEOUT_MS, 10*1000 ) );
//Set Keepalive in seconds
//Set Username
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_USERNAME, "aabbcc" ) );
//Set Password
m2mb_mqtt_conf(p_mqtt, CMDS(M2MB_MQTT_SET_PASSWORD, "1234567890"));
result = m2mb_mqtt_connect( p_mqtt, "api-dev.devicewise.com", 1883 );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_connect succeeded");
}
result = m2mb_mqtt_publish( p_mqtt, 0, 0, 10, "things/aabbcc/property/temp", "123", 3 );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_publish succeeded");
}
M2MB_MQTT_TOPIC_T topics[2] = {0};
CHAR* topic1 = "things/topic1";
CHAR* topic2 = "things/topic2";
topics[0].topic_filter = topic1;
topics[0].qos = 0;
topics[0].cb = mqtt_topic_cb;
topics[1].topic_filter = topic2;
topics[1].qos = 1;
topics[1].cb = mqtt_topic_cb;
result = m2mb_mqtt_subscribe( p_mqtt, 11, 2, topics );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_subscribe succeeded");
}
//... Use MQTT APIs ....
result = m2mb_mqtt_disconnect( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_disconnect succeeded");
}
result = m2mb_mqtt_deinit( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_deinit succeeded");
}
}

◆ m2mb_ntp_callback

typedef void( * m2mb_ntp_callback) (M2MB_NTP_HANDLE handle, M2MB_NTP_EVENTS_E ntp_event, UINT16 resp_size, void *resp_struct, void *cb_args)

This is the ntp user callback function prototype.

This callback function is executed by ntp core when a query operation completes (either with success or failure).

Parameters
[in]handlethe npt handle associated with the operation
[in]ntp_eventThe resulting event of the operation
[in]resp_sizethe size in bytes of the response structure (depends on the event)
[in]resp_structthe output data pointer. it must be cast to the correct type, depending on the event.
[in]cb_argsUser specific data to be passed to the callback.
Returns
None
#include <time.h>
#include "m2mb_types.h"
#include "m2mb_socket.h"
void m2mb_ntp_ind_callback ( M2MB_NTP_HANDLE h,
M2MB_NTP_EVENTS_E ntp_event,
UINT16 resp_size,
void *resp_struct,
void *cb_args )
{
time_t current_time;
switch(ntp_event)
{
{
tv = (struct M2MB_SOCKET_BSD_TIMEVAL *) resp_struct;
current_time = tv->m_tv_sec;
DEBUG("Received UNIX timestamp: %u\r\n", current_time);
}
break;
default:
ERROR("ntp error %d\r\n", ntp_event);
break;
}
}

Enumeration Type Documentation

◆ M2MB_MQTT_ACTION_E

MQTT actions enum List of actions performed through m2mb_mqtt_conf API.

Enumerator
M2MB_MQTT_SET_CLIENT_ID 

To set client id of the device.
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_CLIENT_ID, "MQTT_demo" ) ); or m2mb_mqtt_conf_( p_mqtt, M2MB_MQTT_SET_CLIENT_ID, "MQTT_demo" );

M2MB_MQTT_SET_TIMEOUT_MS 

To set Timeout for MQTT operations in milliseconds.
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_TIMEOUT_MS, 10*1000 ) );

M2MB_MQTT_SECURE_OPT 

To enable SSL and set SSL configurations. If this is not set, SSL is not enabled.
M2MB_SSL_CONFIG_HANDLE sslConfigHndl; M2MB_SSL_CTXT_HANDLE sslCtxtHndl; Get sslConfigHndl and sslCtxtHndl using m2mb_ssl_create_config, m2mb_ssl_create_ctxt API respectively Perform required SSL configurations. m2mb_mqtt_conf(p_mqtt, CMDS(M2MB_MQTT_SECURE_OPT, sslConfigHndl, sslCtxtHndl));

M2MB_MQTT_SET_KEEPALIVE_SEC 

To set keep alive interval of the connection in seconds
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_KEEPALIVE_SEC, 60 ) );

M2MB_MQTT_SET_CLEAN_SESSION 

Set clean session flag that will be used by the MQTT core. User has to specify value to be set.
If it is set to 1, session will be non-persistent. Else, it will be persistent.
Default value is 1. m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_CLEAN_SESSION, 1 ) );

M2MB_MQTT_SET_PROTOCOL_LEVEL 

Set MQTT Protocol level: Protocol version: 4=v3.1.1 (default), No support 5=v5.0
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_PROTOCOL_LEVEL, 4 ) );

M2MB_MQTT_SET_LAST_WILL 

Set MQTT Protocol will flag that will be used by the MQTT core.
If third parameter is 1, Optional Last will and testament will be enabled. In that case also give the following parameters:
Fourth parameter is the variable containing the will QoS value to be set.
Fifth parmeter is the variable containing the will retain value to be set.
Sixth parmeter is the variable containing the will topic string to be set.
Seventh parmeter is the variable containing the will message string to be set.
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_LAST_WILL, 1, M2MB_MQTT_QOS_1, 1, "things/topic1", "Will Message" ) );

M2MB_MQTT_SET_USERNAME 

Set the MQTT client username that will be used by the MQTT core.
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_USERNAME, "aabbcc" ) );

M2MB_MQTT_SET_PASSWORD 

The MQTT client username that will be used by the MQTT core.
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_PASSWORD, "1234567890" ) );

M2MB_MQTT_SET_PDP_CONTEXT 

To set pdp context to be used for the MQTT client.
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_PDP_CONTEXT, 2 ) );

M2MB_MQTT_GET_CLIENT_ID 

To retrieve client id of the device configured by the user.
UINT8* cid = NULL; m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_GET_CLIENT_ID, &cid ) ); printf("Cid = %s", cid);

M2MB_MQTT_GET_TIMEOUT_MS 

To retrieve timeout of the MQTT operations in milliseconds.
UINT32 timeout = 0; m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_TIMEOUT_MS, &timeout ) ); printf("timeout = %d ms", timeout);

M2MB_MQTT_GET_KEEPALIVE_SEC 

To retrieve Keepalive interval in seconds.
UINT32 keepalive = 0; m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_TIMEOUT_MS, &keepalive ) ); printf("keepalive = %d ms", keepalive);

M2MB_MQTT_GET_CLEAN_SESSION 

To retrieve configured clean session flag that will be used by the MQTT core.
UINT8 clean_session; m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_CLEAN_SESSION, &clean_session ) ); printf("clean session = %d", clean_session);

M2MB_MQTT_GET_PROTOCOL_LEVEL 

To retrieve MQTT protocol version as configured by the user.
INT32 version; m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_GET_PROTOCOL_LEVEL, &version ) ); printf("protocol version = %d", version);

M2MB_MQTT_GET_LAST_WILL 

To retrieve Last will and testament settings used by MQTT core
UINT8 will; M2MB_MQTT_QOS_E qos; UINT8 retain; UINT8* topic = NULL; UINT8* message = NULL; m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_GET_LAST_WILL, &will, &qos, &retain, &topic, &message ) ); printf("last will = %d\r\n", will); printf("will qos = %d\r\n", qos); printf("will retain = %d\r\n", retain); printf("will topic = %s\r\n", topic); printf("will message = %s\r\n", message);

M2MB_MQTT_GET_PDP_CONTEXT 

To retrieve pdp context to be used for the MQTT client.
UINT8 pdp; m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_GET_PDP_CONTEXT, &pdp ) ); printf("pdp = %d", pdp);

M2MB_MQTT_SET_PDP_HANDLE 

To set pdp context to be used for the MQTT client.
M2MB_PDP_HANDLE pdpHndl = NULL; To pass the pdpHndl. m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_PDP_HANDLE, pdpHndl ) );

If user has not passed PDP handle, only IPV4 connection goes through. IPV6 is supported only if it is configured

◆ M2MB_MQTT_IND_E

MQTT Indications enum.

Enumerator
M2MB_MQTT_INDICATION_DISCONNECT 

This event is received when MQTT Broker triggers the disconnect asynchronously or when MQTT ping fails.

◆ M2MB_MQTT_QOS_E

MQTT QoS Enum.

Enumerator
M2MB_MQTT_QOS_0 

At most once delivery

M2MB_MQTT_QOS_1 

At least once delivery

M2MB_MQTT_QOS_2 

Exactly once delivery

◆ M2MB_MQTT_RESPONSE_E

MQTT APIs response enum.

Enumerator
M2MB_MQTT_SUCCESS 

Response is success

M2MB_MQTT_ERROR_BAD_ARG 

Bad argument was passed by the user

M2MB_MQTT_ERROR_OUT_OF_BUFFER 

Out of buffer

M2MB_MQTT_ERROR_MALFORMED_DATA 

Malformed Data

M2MB_MQTT_ERROR_PACKET_TYPE 

Wrong packet type

M2MB_MQTT_ERROR_PACKET_ID 

Wrong packet Id

M2MB_MQTT_ERROR_TLS_CONNECT 

Error in TCP connection

M2MB_MQTT_ERROR_TIMEOUT 

Timeout occurred

M2MB_MQTT_ERROR_NETWORK 

Error in Network

M2MB_MQTT_ERROR_MEMORY 

Out of Memory

M2MB_MQTT_ERROR_STAT 

Error in Stats

M2MB_MQTT_ERROR_PROPERTY 

Error in Properties

M2MB_MQTT_ERROR_SERVER_PROP 

Error in Server Properties

M2MB_MQTT_ERROR_CALLBACK 

Callback Error

M2MB_MQTT_ERROR_SEM 

Error in connection semaphore

M2MB_MQTT_ERROR_TOPIC_LIST 

Error related to list of subscribed topics

M2MB_MQTT_ERROR_ASYNC_THREAD 

Error inAsync thread

M2MB_MQTT_ERROR_QUEUE 

Error in creating queue

M2MB_MQTT_CONTINUE 

MQTT Continue

M2MB_MQTT_STDIN_WAKE 

MQTT STDIN Wake

◆ M2MB_MQTT_RX_STATUS_E

MQTT Receive Data Status Enum.

Enumerator
M2MB_MQTT_RX_FINISHED 

Entire data is received

M2MB_MQTT_RX_MORE_DATA 

Partial data is pending

◆ M2MB_MQTT_STATUS_E

mqtt client status enum

Enumerator
M2MB_MQTT_NOT_CONNECTED 

Client is initialized but not connected

M2MB_MQTT_CLIENT_CONNECTED 

Client performed MQTT authentication with broker

M2MB_MQTT_CONN_RESET_BY_PEER 

Connection closed or reset by the server

M2MB_MQTT_PINGREQ_TIMEOUT_FAIL 

The answer to the ping request packet was not received

M2MB_MQTT_CONNACK_TIMEOUT 

The CONNACK packet was not received

M2MB_MQTT_CONNECT_TIMEOUT 

The CONNECT packet was not delivered

M2MB_MQTT_FATAL_ERROR 

Failure in the m2mb APIs

M2MB_MQTT_NETWORK_ERROR 

Socket timeout or read error

M2MB_MQTT_STATUS_UNKNOWN 

Unknown state or client not initialized

◆ M2MB_NTP_AUTH_TYPE_E

Authentication options.

Enumerator
m2mb_ntp_noAuth 

Do not authenticate server

m2mb_ntp_symmetricKey 

Authenticate server with symmetric key

m2mb_ntp_autokey 

Authenticate server with autokey - Not available yet

◆ M2MB_NTP_CFG_E

Enumerator
M2MB_NTP_CFG_TIMEOUT 

Operation timeout in seconds (UINT32) - the total timeout will be up to 3 times the timeout value set with m2mb_ntp_setCfg (with M2MB_NTP_CFG_TIMEOUT parameter)

M2MB_NTP_CFG_PORT 

Server Port. Set to 0 to use default (UINT16)

M2MB_NTP_CFG_SERVER 

Server name. can be a resolvable address, or IPv4 /v6 ip address string

M2MB_NTP_CFG_AUTH_TYPE 

Authentication type, see enum M2MB_NTP_AUTH_TYPE_E

M2MB_NTP_CFG_AUTH_KEYID 

Authentication key ID (UINT32)

M2MB_NTP_CFG_AUTH_KEYSFILE 

Authentication keys filename, already allocated

◆ M2MB_NTP_EVENTS_E

NTP Events.

Events that will be passed to ntp callback when operation completes (either with error or success).

Enumerator
M2MB_NTP_VALID_TIME 

The provided parameter contains a valid time in unix timestamp format

M2MB_NTP_ERR_NOT_ENOUGH_RESOURCES 

The client was not able to obtain needed resources

M2MB_NTP_ERR_REG_TIMEOUT 

The operation timed out

M2MB_NTP_ERR_CONN_ERR 

Error enabling network

M2MB_NTP_ERR_CONN_TIMEOUT 

Connection timed out

M2MB_NTP_ERR_HOST_RESOLVE 

Error resolving host name

M2MB_NTP_ERR_INVALID_PARAMETER 

An invalid parameter was passed

M2MB_NTP_ERR_SOCK_OPEN 

Error opening socket

M2MB_NTP_ERR_TX_TIMEOUT 

Transmission timeout

M2MB_NTP_ERR_TX_ERROR 

Transmission error

M2MB_NTP_ERR_RX_TIMEOUT 

Receive timeout

M2MB_NTP_ERROR 

Generic error

M2MB_NTP_ERR_SERVER_AUTH_FAIL 

Server authentication failure

M2MB_NTP_ERR_KEYS_FILE_MISSING 

Server keys file missing

Function Documentation

◆ m2mb_mqtt_conf()

M2MB_MQTT_RESPONSE_E m2mb_mqtt_conf ( M2MB_MQTT_HANDLE  Handle,
UINT8  nCmds,
  ... 
)

m2mb_mqtt_conf sets/gets some MQTT parameters and configurations.

m2mb_mqtt_conf sets/gets MQTT parameters listed in the M2MB_MQTT_ACTION_E enum. These are to be performed before m2mb_mqtt_connect.

Parameters
[in]Handlehandle to the MQTT client service, previously initialized by the m2mb_mqtt_init function.
[in]argcdetermines the number of parameters that follows
[in]action(among the ones listed in M2MB_MQTT_ACTION_E), while the parameters that follow depend on the action (see following note for further details)
Returns
M2MB_MQTT_RESPONSE_E values.
Note
Action: M2MB_MQTT_SET_CLIENT_ID refer m2mb_mqtt_conf_ to avoid specifiying number of arguments or without using CMDS

Description: set the Unique clinet ID in order to connect to the MQTT broker. This setting could be performed only before m2mb_mqtt_connect.

Params(in): h(M2MB_MQTT_HANDLE), action(M2MB_MQTT_ACTION_E), format(UINT8*)

  • example: set the CId 2

m2mb_mqtt_conf_( h, M2MB_MQTT_SET_CLIENT_ID, "MQTT_demo" ); or m2mb_mqtt_conf( h, CMDS( M2MB_MQTT_SET_CLIENT_ID, "MQTT_demo" ) );

Example

void m2mb_mqtt_ind_callback(M2MB_MQTT_HANDLE Handle, M2MB_MQTT_IND_E event, UINT16 resp_size, void *resp, void *userdata );
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
result = m2mb_mqtt_init( &p_mqtt, m2mb_mqtt_ind_callback, NULL );
if(result != M2MB_MQTT_SUCCESS)
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
//Set Client ID
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_CLIENT_ID, "MQTT_demo" ) );
//Set Timeout in milliseconds
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_TIMEOUT_MS, 10*1000 ) );
//Set Keepalive in seconds
//Set Username
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_USERNAME, "aabbcc" ) );
//Set Password
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_PASSWORD, "1234567890" ) );
//... Use MQTT APIs ....
result = m2mb_mqtt_deinit( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_deinit succeeded");
}
}

◆ m2mb_mqtt_connect()

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.

m2mb_mqtt_connect performs MQTT connection to the URL specified in host.

Parameters
[in]Handlehandle to the MQTT client service, previously initialized by the m2mb_mqtt_init function.
[in]hostURL of the remote MQTT Broker that MQTT client needs to connect.(Ex: "api-dev.devicewise.com")
[in]portPort number of the remote MQTT Broker that MQTT client needs to connect.(Ex: 1883)
Returns
M2MB_MQTT_RESPONSE_E values.
Note

Example

void m2mb_mqtt_ind_callback( M2MB_MQTT_HANDLE Handle, M2MB_MQTT_IND_E event, UINT16 resp_size, void *resp, void *userdata );
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
result = m2mb_mqtt_init( &p_mqtt, m2mb_mqtt_ind_callback, NULL );
if(result != M2MB_MQTT_SUCCESS)
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
//Set Client ID
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_CLIENT_ID, "MQTT_demo" ) );
//Set Timeout in milliseconds
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_TIMEOUT_MS, 10*1000 ) );
//Set Keepalive in seconds
//Set Username
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_USERNAME, "aabbcc" ) );
//Set Password
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_PASSWORD, "1234567890" ) );
result = m2mb_mqtt_connect( p_mqtt, "api-dev.devicewise.com", 1883 );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_deinit succeeded");
}
//... Use MQTT APIs ....
result = m2mb_mqtt_deinit( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_deinit succeeded");
}
}

◆ m2mb_mqtt_deinit()

M2MB_MQTT_RESPONSE_E m2mb_mqtt_deinit ( M2MB_MQTT_HANDLE  Handle)

m2mb_mqtt_deinit deinitializes MQTT service for specified MQTT client.

m2mb_mqtt_deinit deinitialize MQTT service for specified MQTT client releasing the resources associated with the handle as first parameter. Calling the m2mb_mqtt_deinit is needed after having completed the usage of MQTT service to release reserved memory

Parameters
[in]Handlehandle to the MQTT client service, that will be deinitialized by the function.
Returns
M2MB_MQTT_RESPONSE_E values.
Note

Example

void m2mb_mqtt_ind_callback( M2MB_MQTT_HANDLE Handle, M2MB_MQTT_IND_E event, UINT16 resp_size, void *resp, void *userdata );
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
result = m2mb_mqtt_init( &p_mqtt, m2mb_mqtt_ind_callback, NULL );
if(result != M2MB_MQTT_SUCCESS)
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
//... Use MQTT APIs ....
result = m2mb_mqtt_deinit( p_mqtt );
if ( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_deinit succeeded");
}
}

◆ m2mb_mqtt_disconnect()

M2MB_MQTT_RESPONSE_E m2mb_mqtt_disconnect ( M2MB_MQTT_HANDLE  Handle)

m2mb_mqtt_disconnect is called to disconnect from the MQTT broker.

m2mb_mqtt_disconnect disconnects the specified MQTT client from the Broker.

Parameters
[in]Handlehandle to the MQTT client service, previously initialized by the m2mb_mqtt_init function.
Returns
M2MB_MQTT_RESPONSE_E values.
Note

Example

void m2mb_mqtt_ind_callback( M2MB_MQTT_HANDLE Handle, M2MB_MQTT_IND_E event, UINT16 resp_size, void *resp, void *userdata );
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
result = m2mb_mqtt_init( &p_mqtt, m2mb_mqtt_ind_callback, NULL );
if(result != M2MB_MQTT_SUCCESS)
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
//Set Client ID
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_CLIENT_ID, "MQTT_demo" ) );
//Set Timeout in milliseconds
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_TIMEOUT_MS, 10*1000 ) );
//Set Keepalive in seconds
//Set Username
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_USERNAME, "aabbcc" ) );
//Set Password
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_PASSWORD, "1234567890" ) );
result = m2mb_mqtt_connect( p_mqtt, "api-dev.devicewise.com", 1883 );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_connect succeeded");
}
//... Use MQTT APIs ....
result = m2mb_mqtt_disconnect( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_disconnect succeeded");
}
result = m2mb_mqtt_deinit( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_deinit succeeded");
}
}

◆ m2mb_mqtt_getClientStatus()

M2MB_MQTT_RESPONSE_E m2mb_mqtt_getClientStatus ( M2MB_MQTT_HANDLE  handle,
M2MB_MQTT_STATUS_E status 
)

m2mb_mqtt_getClientStatus gets MQTT client current status

This function allows to retrieve current status of the specified client.

Parameters
[in]handlehandle of the mqtt client
[out]statuspointer to the variable that will be filled with current client status (refer to M2MB_MQTT_STATUS_E enum)
Returns
M2MB_MQTT_RESPONSE_E values.
Note

Example

void m2mb_mqtt_ind_callback( M2MB_MQTT_HANDLE Handle, M2MB_MQTT_IND_E event, UINT16 resp_size, void *resp, void *userdata );
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
result = m2mb_mqtt_init( &p_mqtt, m2mb_mqtt_ind_callback, NULL );
if(result != M2MB_MQTT_SUCCESS)
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
m2mb_mqtt_getClientStatus( p_mqtt, &status );
{
printf("Client is initialized but not connected");
}
//... Use MQTT APIs ....
}

◆ m2mb_mqtt_init()

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.

m2mb_mqtt_init initialize MQTT client context returning the handle that must be passed as first parameter for all MQTT actions. Calling the m2mb_mqtt_init is mandatory before using the MQTT client service. It should be called once for each MQTT client.

Parameters
[out]pHandlepointer to MQTT context handle that is is initialized by the function. This is to be used in subsequent MQTT APIs.
[out]callbackcallback that will be called if client receives an event. (ex: server disconnect the client and disconnect event is triggered)
[out]userdataa pointer to generic user data that will be returned as it is in the callback.
Returns
M2MB_MQTT_RESPONSE_E values.
Note

Example

void m2mb_mqtt_ind_callback( M2MB_MQTT_HANDLE Handle, M2MB_MQTT_IND_E event, UINT16 resp_size, void *resp, void *userdata );
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
result = m2mb_mqtt_init( &p_mqtt, m2mb_mqtt_ind_callback, NULL );
if(result != M2MB_MQTT_SUCCESS)
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
//... Use MQTT APIs ....
}

◆ m2mb_mqtt_ping()

M2MB_MQTT_RESPONSE_E m2mb_mqtt_ping ( M2MB_MQTT_HANDLE  Handle)

m2mb_mqtt_ping is called to ping

m2mb_mqtt_ping is called to ping the remote MQTT broker

Parameters
[in]Handlehandle to the MQTT client service, previously initialized by the m2mb_mqtt_init function.
Returns
M2MB_MQTT_RESPONSE_E values.
Note

Example

void m2mb_mqtt_ind_callback( M2MB_MQTT_HANDLE Handle, M2MB_MQTT_IND_E event, UINT16 resp_size, void *resp, void *userdata );
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
result = m2mb_mqtt_init( &p_mqtt, m2mb_mqtt_ind_callback, NULL );
if(result != M2MB_MQTT_SUCCESS)
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
//Set Client ID
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_CLIENT_ID, "MQTT_demo" ) );
//Set Timeout in milliseconds
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_TIMEOUT_MS, 10*1000 ) );
//Set Keepalive in seconds
//Set Username
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_USERNAME, "aabbcc" ) );
//Set Password
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_PASSWORD, "1234567890" ) );
result = m2mb_mqtt_connect( p_mqtt, "api-dev.devicewise.com", 1883 );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_connect succeeded");
}
result = m2mb_mqtt_ping( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_ping succeeded");
}
//... Use MQTT APIs ....
result = m2mb_mqtt_disconnect( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_disconnect succeeded");
}
result = m2mb_mqtt_deinit( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_deinit succeeded");
}
}

◆ m2mb_mqtt_publish()

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.

m2mb_mqtt_publish Publishes a message on a given topic.

Parameters
[in]Handlehandle to the MQTT client service, previously initialized by the m2mb_mqtt_init function
[in]qosInteger value 0, 1, or 2 indicating the QOS to be used for msg.
[in]retainSet to TRUE to make the message retained
[in]message_idMessage ID of the MQTT message
[in]topicTopic name
[in]dataMQTT Message payload data
[in]data_lenData length
Returns
M2MB_MQTT_RESPONSE_E values.
Note
Example
void m2mb_mqtt_ind_callback( M2MB_MQTT_HANDLE Handle, M2MB_MQTT_IND_E event, UINT16 resp_size, void *resp, void *userdata );
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
result = m2mb_mqtt_init( &p_mqtt, m2mb_mqtt_ind_callback, NULL );
if(result != M2MB_MQTT_SUCCESS)
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
//Set Client ID
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_CLIENT_ID, "MQTT_demo" ) );
//Set Timeout in milliseconds
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_TIMEOUT_MS, 10*1000 ) );
//Set Keepalive in seconds
//Set Username
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_USERNAME, "aabbcc" ) );
//Set Password
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_PASSWORD, "1234567890" ) );
result = m2mb_mqtt_connect( p_mqtt, "api-dev.devicewise.com", 1883 );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_connect succeeded");
}
result = m2mb_mqtt_publish( p_mqtt, 0, 0, 10, "things/aabbcc/property/temp", "123", 3 );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_publish succeeded");
}
//... Use MQTT APIs ....
result = m2mb_mqtt_disconnect( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_disconnect succeeded");
}
result = m2mb_mqtt_deinit( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_deinit succeeded");
}
}

◆ m2mb_mqtt_setClientStatus()

M2MB_MQTT_RESPONSE_E m2mb_mqtt_setClientStatus ( M2MB_MQTT_HANDLE  handle,
M2MB_MQTT_STATUS_E  status 
)

m2mb_mqtt_setClientStatus sets MQTT client current status

This function allows to set current status of the specified client.

Parameters
[in]Handlehandle of the mqtt client
[in]statusset as current client status (refer to M2MB_MQTT_STATUS_E enum)
Returns
M2MB_MQTT_RESPONSE_E values.
Note

Example

void m2mb_mqtt_ind_callback( M2MB_MQTT_HANDLE Handle, M2MB_MQTT_IND_E event, UINT16 resp_size, void *resp, void *userdata );
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
result = m2mb_mqtt_init( &p_mqtt, m2mb_mqtt_ind_callback, NULL );
if(result != M2MB_MQTT_SUCCESS)
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
if(result == M2MB_MQTT_SUCCESS)
{
printf("Client status set successfully");
}
//... Use MQTT APIs ....
}

◆ m2mb_mqtt_subscribe()

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.

m2mb_mqtt_subscribe Subscribes to one or multiple topics.

Parameters
[in]Handlehandle to the MQTT client service, previously initialized by the m2mb_mqtt_init function.
[in]message_idMessage ID of the MQTT message
[in]topic_countNumber of topics to be subscribed
[in]topicsContiguous list of topics to subscribe to
Returns
M2MB_MQTT_RESPONSE_E values.
Note

Example

void m2mb_mqtt_ind_callback( M2MB_MQTT_HANDLE Handle, M2MB_MQTT_IND_E event, UINT16 resp_size, void *resp, void *userdata );
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void mqtt_topic_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];
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");
}
}
void main(void)
{
result = m2mb_mqtt_init( &p_mqtt, m2mb_mqtt_ind_callback, NULL );
if(result != M2MB_MQTT_SUCCESS)
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
//Set Client ID
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_CLIENT_ID, "MQTT_demo" ) );
//Set Timeout in milliseconds
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_TIMEOUT_MS, 10*1000 ) );
//Set Keepalive in seconds
//Set Username
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_USERNAME, "aabbcc" ) );
//Set Password
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_PASSWORD, "1234567890" ) );
result = m2mb_mqtt_connect( p_mqtt, "api-dev.devicewise.com", 1883 );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_connect succeeded");
}
result = m2mb_mqtt_publish( p_mqtt, 0, 0, 10, "things/aabbcc/property/temp", "123", 3 );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_publish succeeded");
}
M2MB_MQTT_TOPIC_T topics[2] = {0};
CHAR* topic1 = "things/topic1";
CHAR* topic2 = "things/topic2";
topics[0].topic_filter = topic1;
topics[0].qos = 0;
topics[0].cb = mqtt_topic_cb;
topics[1].topic_filter = topic2;
topics[1].qos = 1;
topics[1].cb = mqtt_topic_cb;
result = m2mb_mqtt_subscribe( p_mqtt, 11, 2, topics );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_subscribe succeeded");
}
//... Use MQTT APIs ....
result = m2mb_mqtt_disconnect( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_disconnect succeeded");
}
result = m2mb_mqtt_deinit( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_deinit succeeded");
}
}

◆ m2mb_mqtt_unsubscribe()

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.

m2mb_mqtt_unsubscribe unsubscribes to one or multiple topics.

Parameters
[in]Handlehandle to the MQTT client service, previously initialized by the m2mb_mqtt_init function.
[in]message_idMessage ID of the MQTT message
[in]topic_countNumber of topics to be subscribed
[in]topicsContiguous list of topics to unsubscribe to
Returns
M2MB_MQTT_RESPONSE_E values.
Note

Example

void m2mb_mqtt_ind_callback( M2MB_MQTT_HANDLE Handle, M2MB_MQTT_IND_E event, UINT16 resp_size, void *resp, void *userdata );
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
result = m2mb_mqtt_init( &p_mqtt, m2mb_mqtt_ind_callback, NULL );
if(result != M2MB_MQTT_SUCCESS)
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
//Set Client ID
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_CLIENT_ID, "MQTT_demo" ) );
//Set Timeout in milliseconds
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_TIMEOUT_MS, 10*1000 ) );
//Set Keepalive in seconds
//Set Username
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_USERNAME, "aabbcc" ) );
//Set Password
m2mb_mqtt_conf( p_mqtt, CMDS( M2MB_MQTT_SET_PASSWORD, "1234567890" ) );
result = m2mb_mqtt_connect( p_mqtt, "api-dev.devicewise.com", 1883 );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_connect succeeded");
}
result = m2mb_mqtt_publish( p_mqtt, 0, 0, 10, "things/aabbcc/property/temp", "123", 3 );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_publish succeeded");
}
M2MB_MQTT_TOPIC_T topics[2] = {0};
CHAR* topic1 = "things/topic1";
CHAR* topic2 = "things/topic2";
topics[0].topic_filter = topic1;
topics[0].qos = 0;
topics[1].topic_filter = topic2;
topics[1].qos = 1;
result = m2mb_mqtt_subscribe( p_mqtt, 11, 2, topics );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_subscribe succeeded");
}
//... Use MQTT APIs ....
result = m2mb_mqtt_unsubscribe( p_mqtt, 11, 2, topics );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_unsubscribe succeeded");
}
result = m2mb_mqtt_disconnect( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_disconnect succeeded");
}
result = m2mb_mqtt_deinit( p_mqtt );
if( result == M2MB_MQTT_SUCCESS )
{
printf( "m2mb_mqtt_deinit succeeded");
}
}

◆ m2mb_ntp_deinit()

M2MB_RESULT_E m2mb_ntp_deinit ( M2MB_NTP_HANDLE  handle)

This is the ntp deinitialization function.

This function will deinitialize the ntp core, releasing all resources (including PDP context

Parameters
[in]handlethe handle that will be deinitialized
Returns
M2MB_RESULT_E value
void m2mb_ntp_ind_callback ( M2MB_NTP_HANDLE h,
M2MB_NTP_EVENTS_E ntp_event,
UINT16 resp_size,
void *resp_struct,
void *cb_args )
{
...
}
void main(void)
{
M2MB_NTP_HANDLE ntpH;
M2MB_RESULT_E retVal;
void *userContext = NULL; //user provided context data
retVal = m2mb_ntp_init(&ntpH, m2mb_ntp_ind_callback, (void*) userContext);
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("init failed.\r\n");
return;
}
...
}

◆ m2mb_ntp_getVersion()

M2MB_RESULT_E m2mb_ntp_getVersion ( M2MB_NTP_HANDLE  handle,
CHAR *  version,
UINT16  maxlen 
)

This is the ntp version get function.

This function will return the ntp lib version as a string.

Parameters
[in]handlethe handle to be used for the operation
[in,out]versionpointer to an allocated buffer (at least 20 bytes in size) to which copy the version string
[in]maxlenlength of the allocated buffer (at least 20 bytes in size)
Returns
void m2mb_ntp_ind_callback ( M2MB_NTP_HANDLE h,
M2MB_NTP_EVENTS_E ntp_event,
UINT16 resp_size,
void *resp_struct,
void *cb_args )
{
...
}
void main(void)
{
M2MB_NTP_HANDLE ntpH;
M2MB_RESULT_E retVal;
CHAR ntp_ver[32];
void *userContext = NULL; //user provided context data
retVal = m2mb_ntp_init(&ntpH, m2mb_ntp_ind_callback, (void*) userContext);
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("init failed.\r\n");
return;
}
m2mb_ntp_getVersion(ntpH, ntp_ver, 32);
INFO("ntp_version: %s\r\n",ntp_ver);
}

◆ m2mb_ntp_init()

M2MB_RESULT_E m2mb_ntp_init ( M2MB_NTP_HANDLE *  pHandle,
m2mb_ntp_callback  callback,
void *  cb_args 
)

This is the ntp initialization function.

This function will initialize the ntp core allowing to perform further operations.

Parameters
[in]pHandlepointer to the handle that will be initialized, and will be used by all other APIs. Handle pointed by pHandle must be initialized to NULL before calling this API.
[in]callbackUser callback that will be called by ntp core
[in]cb_argsUser specific data, that will be passed to user callback when it is called.
Returns
M2MB_RESULT_E value
void m2mb_ntp_ind_callback ( M2MB_NTP_HANDLE h,
M2MB_NTP_EVENTS_E ntp_event,
UINT16 resp_size,
void *resp_struct,
void *cb_args )
{
...
}
void main(void)
{
M2MB_NTP_HANDLE ntpH;
M2MB_RESULT_E retVal;
void *userContext = NULL; //user provided context data
retVal = m2mb_ntp_init(&ntpH, m2mb_ntp_ind_callback, (void*) userContext);
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("init failed.\r\n");
return;
}
}

◆ m2mb_ntp_queryServerTime()

M2MB_RESULT_E m2mb_ntp_queryServerTime ( M2MB_NTP_HANDLE  handle)

This is the ntp query function.

This function will ask for a time value to the server specified in the passed parameters. IMPORTANT: This function returns immediately, operation result will be reported in user callback

Parameters
[in]handlethe handle to be used for the operation
Returns
M2MB_RESULT_E value
#include <time.h>
#include "m2mb_types.h"
#include "m2mb_socket.h"
void m2mb_ntp_ind_callback ( M2MB_NTP_HANDLE h,
M2MB_NTP_EVENTS_E ntp_event,
UINT16 resp_size,
void *resp_struct,
void *cb_args )
{
time_t current_time;
switch(ntp_event)
{
{
tv = (struct M2MB_SOCKET_BSD_TIMEVAL *) resp_struct;
current_time = tv->m_tv_sec;
DEBUG("Received UNIX timestamp: %u\r\n", current_time);
}
break;
default:
ERROR("ntp error %d\r\n", ntp_event);
break;
}
}
void main(void)
{
M2MB_NTP_HANDLE ntpH;
M2MB_RESULT_E retVal;
INT32 cid = 1;
UINT16 ntpPort = 123;
UINT32 timeout = 5; //5 seconds
CHAR ntpServer[] = "0.pool.ntp.org";
void *userContext = NULL; //user provided context data
retVal = m2mb_ntp_init(&ntpH, m2mb_ntp_ind_callback, (void*) userContext);
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("init failed.\r\n");
return;
}
retVal = m2mb_ntp_setCid(ntpH, cid);
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("Set cid failed.\r\n");
retVal = m2mb_ntp_deinit(ntpH);
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
retVal = m2mb_ntp_setCfg(ntpH, M2MB_NTP_CFG_SERVER, (void*)ntpServer);
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set server failed.\r\n");
retVal = m2mb_ntp_deinit(ntpH);
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
retVal = m2mb_ntp_setCfg(ntpH, M2MB_NTP_CFG_PORT, (void*) &(ntpPort));
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set server port failed.\r\n");
retVal = m2mb_ntp_deinit(ntpH);
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
retVal = m2mb_ntp_setCfg(ntpH, M2MB_NTP_CFG_TIMEOUT, (void*) &(timeout));
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set timeout failed.\r\n");
retVal = m2mb_ntp_deinit(ntpH);
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
CID activation
m2mb_pdp_activate(...,cid,...)
=======
retVal = m2mb_ntp_queryServerTime( ntpH );
if(M2MB_RESULT_SUCCESS != retVal)
{
FATAL("query failed.\r\n");
return;
}
// Wait for ntp callback to complete and return the outcome,
// either by sleep or by semaphore/event-flag
retVal = m2mb_ntp_deinit(ntpH);
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
else
{
ERROR("Cannot deinit! retVal: %d\r\n", retVal);
}
}

◆ m2mb_ntp_setCfg()

M2MB_RESULT_E m2mb_ntp_setCfg ( M2MB_NTP_HANDLE  handle,
M2MB_NTP_CFG_E  param,
void *  value 
)

Set the one of the NTP parameters.

will set the requested parameter associated to the NTP core to perform further operations. refer to M2MB_NTP_CFG_E values.

Parameters
[in]handlethe handle to be used for the operation
[in]paramenum selecting which param should be set
[in]valueopaque pointer to the parameter value to be set
Returns
M2MB_RESULT_E value
void m2mb_ntp_ind_callback ( M2MB_NTP_HANDLE h,
M2MB_NTP_EVENTS_E ntp_event,
UINT16 resp_size,
void *resp_struct,
void *cb_args )
{
...
}
void main(void)
{
M2MB_NTP_HANDLE ntpH;
M2MB_RESULT_E retVal;
UINT16 ntpPort = 123;
UINT32 timeout = 5; //5 seconds
UINT16 authType = m2mb_ntp_symmetricKey;
UINT32 keyId = 0;
CHAR authKeysFilePath[] = "/path/to/server/keys/file";
CHAR ntpServer[] = "0.pool.ntp.org";
void *userContext = NULL; //user provided context data
retVal = m2mb_ntp_init(&ntpH, m2mb_ntp_ind_callback, (void*) userContext);
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("init failed.\r\n");
return;
}
retVal = m2mb_ntp_setCfg(ntpH, M2MB_NTP_CFG_SERVER, (void*)ntpServer);
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set server failed.\r\n");
retVal = m2mb_ntp_deinit(ntpH);
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
retVal = m2mb_ntp_setCfg(ntpH, M2MB_NTP_CFG_PORT, (void*) &(ntpPort));
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set server port failed.\r\n");
retVal = m2mb_ntp_deinit(ntpH);
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
retVal = m2mb_ntp_setCfg(ntpH, M2MB_NTP_CFG_TIMEOUT, (void*) &(timeout));
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set timeout failed.\r\n");
retVal = m2mb_ntp_deinit(ntpH);
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
// OPTIONAL: authentication configuration
retVal = m2mb_ntp_setCfg(ntpH, M2MB_NTP_CFG_AUTH_TYPE, (void*) &(authType));
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set authType failed.\r\n");
retVal = m2mb_ntp_deinit(ntpH);
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
retVal = m2mb_ntp_setCfg(ntpH, M2MB_NTP_CFG_AUTH_KEYID, (void*) &(keyId));
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set key id failed.\r\n");
retVal = m2mb_ntp_deinit(ntpH);
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
retVal = m2mb_ntp_setCfg(ntpH, M2MB_NTP_CFG_AUTH_KEYSFILE, (void*) authKeysFilePath);
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set server keys file failed.\r\n");
retVal = m2mb_ntp_deinit(ntpH);
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
...
}

◆ m2mb_ntp_setCid()

M2MB_RESULT_E m2mb_ntp_setCid ( M2MB_NTP_HANDLE  handle,
INT16  cid 
)

Set the CID to be used with NTP.

This function will set the CID associated to the NTP core to perform further operations. NOTE: The PDP context associated with the CID must be activated with m2mb_pdp_* APIs (refer to m2mb_pdp_activate).

Parameters
[in]handlethe handle to be used for the operation
[in]cidCID value to be associated with the NTP client
Returns
M2MB_RESULT_E value
void m2mb_ntp_ind_callback ( M2MB_NTP_HANDLE h,
M2MB_NTP_EVENTS_E ntp_event,
UINT16 resp_size,
void *resp_struct,
void *cb_args )
{
...
}
void main(void)
{
M2MB_NTP_HANDLE ntpH;
M2MB_RESULT_E retVal;
INT32 cid = 1;
void *userContext = NULL; //user provided context data
retVal = m2mb_ntp_init(&ntpH, m2mb_ntp_ind_callback, (void*) userContext);
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("init failed.\r\n");
return;
}
retVal = m2mb_ntp_setCid(ntpH, cid);
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("Set cid failed.\r\n");
retVal = m2mb_ntp_deinit(ntpH);
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
...
}
M2MB_MQTT_STATUS_E
M2MB_MQTT_STATUS_E
mqtt client status enum
Definition: m2mb_mqtt.h:99
m2mb_mqtt_setClientStatus
M2MB_MQTT_RESPONSE_E m2mb_mqtt_setClientStatus(M2MB_MQTT_HANDLE handle, M2MB_MQTT_STATUS_E status)
m2mb_mqtt_setClientStatus sets MQTT client current status
m2mb_mqtt_ind_callback
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.
Definition: m2mb_mqtt.h:344
m2mb_mqtt_publish
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.
M2MB_MQTT_SET_TIMEOUT_MS
Definition: m2mb_mqtt.h:127
M2MB_MQTT_RX_MORE_DATA
Definition: m2mb_mqtt.h:252
M2MB_NTP_CFG_SERVER
Definition: m2mb_ntp.h:101
m2mb_mqtt_deinit
M2MB_MQTT_RESPONSE_E m2mb_mqtt_deinit(M2MB_MQTT_HANDLE Handle)
m2mb_mqtt_deinit deinitializes MQTT service for specified MQTT client.
M2MB_MQTT_TOPIC
MQTT Topic Structure This is used in m2mb_mqtt_subscribe and m2mb_mqtt_unsubscribe API.
Definition: m2mb_mqtt.h:498
M2MB_MQTT_RX_STATUS_E
M2MB_MQTT_RX_STATUS_E
MQTT Receive Data Status Enum.
Definition: m2mb_mqtt.h:249
m2mb_ntp_getVersion
M2MB_RESULT_E m2mb_ntp_getVersion(M2MB_NTP_HANDLE handle, CHAR *version, UINT16 maxlen)
This is the ntp version get function.
M2MB_NTP_CFG_TIMEOUT
Definition: m2mb_ntp.h:97
m2mb_mqtt_disconnect
M2MB_MQTT_RESPONSE_E m2mb_mqtt_disconnect(M2MB_MQTT_HANDLE Handle)
m2mb_mqtt_disconnect is called to disconnect from the MQTT broker.
M2MB_NTP_CFG_AUTH_KEYID
Definition: m2mb_ntp.h:103
m2mb_ntp_init
M2MB_RESULT_E m2mb_ntp_init(M2MB_NTP_HANDLE *pHandle, m2mb_ntp_callback callback, void *cb_args)
This is the ntp initialization function.
m2mb_socket.h
Socket support.
M2MB_MQTT_NOT_CONNECTED
Definition: m2mb_mqtt.h:102
m2mb_mqtt_ping
M2MB_MQTT_RESPONSE_E m2mb_mqtt_ping(M2MB_MQTT_HANDLE Handle)
m2mb_mqtt_ping is called to ping
M2MB_MQTT_SET_PASSWORD
Definition: m2mb_mqtt.h:167
m2mb_mqtt_conf
M2MB_MQTT_RESPONSE_E m2mb_mqtt_conf(M2MB_MQTT_HANDLE Handle, UINT8 nCmds,...)
m2mb_mqtt_conf sets/gets some MQTT parameters and configurations.
M2MB_MQTT_SET_KEEPALIVE_SEC
Definition: m2mb_mqtt.h:139
M2MB_MQTT_SET_USERNAME
Definition: m2mb_mqtt.h:163
m2mb_mqtt_subscribe
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.
M2MB_SOCKET_BSD_TIMEVAL
Definition: m2mb_socket.h:249
M2MB_MQTT_TOPIC::topic_filter
const CHAR * topic_filter
Definition: m2mb_mqtt.h:500
M2MB_MQTT_TOPIC::qos
M2MB_MQTT_QOS_E qos
Definition: m2mb_mqtt.h:501
M2MB_MQTT_INDICATION_DISCONNECT
Definition: m2mb_mqtt.h:63
M2MB_NTP_CFG_AUTH_TYPE
Definition: m2mb_ntp.h:102
M2MB_MQTT_SUCCESS
Definition: m2mb_mqtt.h:72
M2MB_NTP_VALID_TIME
Definition: m2mb_ntp.h:68
m2mb_mqtt_connect
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.
m2mb_ntp_setCid
M2MB_RESULT_E m2mb_ntp_setCid(M2MB_NTP_HANDLE handle, INT16 cid)
Set the CID to be used with NTP.
M2MB_NTP_CFG_PORT
Definition: m2mb_ntp.h:100
m2mb_pdp_init
M2MB_RESULT_E m2mb_pdp_init(M2MB_PDP_HANDLE *h, m2mb_pdp_ind_callback callback, void *userdata)
m2mb_pdp_init initializes PDP service for current client.
M2MB_MQTT_RESPONSE_E
M2MB_MQTT_RESPONSE_E
MQTT APIs response enum.
Definition: m2mb_mqtt.h:70
m2mb_ntp_deinit
M2MB_RESULT_E m2mb_ntp_deinit(M2MB_NTP_HANDLE handle)
This is the ntp deinitialization function.
m2mb_mqtt_getClientStatus
M2MB_MQTT_RESPONSE_E m2mb_mqtt_getClientStatus(M2MB_MQTT_HANDLE handle, M2MB_MQTT_STATUS_E *status)
m2mb_mqtt_getClientStatus gets MQTT client current status
m2mb_types.h
M2MB base types (ver. 121626N)
M2MB_MQTT_TOPIC::cb
M2MB_MQTT_MSG_HNDLR_CB_T cb
Definition: m2mb_mqtt.h:502
M2MB_NTP_EVENTS_E
M2MB_NTP_EVENTS_E
NTP Events.
Definition: m2mb_ntp.h:66
m2mb_ntp_symmetricKey
Definition: m2mb_ntp.h:91
m2mb_ntp_setCfg
M2MB_RESULT_E m2mb_ntp_setCfg(M2MB_NTP_HANDLE handle, M2MB_NTP_CFG_E param, void *value)
Set the one of the NTP parameters.
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:56
M2MB_MQTT_SET_CLIENT_ID
Definition: m2mb_mqtt.h:121
M2MB_NTP_CFG_AUTH_KEYSFILE
Definition: m2mb_ntp.h:104
m2mb_mqtt_unsubscribe
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.
M2MB_MQTT_IND_E
M2MB_MQTT_IND_E
MQTT Indications enum.
Definition: m2mb_mqtt.h:61
m2mb_mqtt_init
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.
m2mb_pdp_activate
M2MB_RESULT_E m2mb_pdp_activate(M2MB_PDP_HANDLE h, UINT8 cid, CHAR *APN, CHAR *user, CHAR *password, M2MB_PDP_IP_TYPE_E pdpIPver)
m2mb_pdp_activate activates PDP context(or PDN connection)
m2mb_ntp_queryServerTime
M2MB_RESULT_E m2mb_ntp_queryServerTime(M2MB_NTP_HANDLE handle)
This is the ntp query function.