 |
m2mb API docs
25.21.003
m2mb API sets documentation
|
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...
|
| |
This group includes all the information about m2mb_mqtt configuration and usage *.
◆ 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.
◆ m2mb_mqtt_ind_callback
MQTT call back prototype.
This callback is triggered when MQTT client receives any event.(M2MB_MQTT_IND_E)
- Parameters
-
| [in] | Handle | handle to the MQTT client instance on which MQTT message is received |
| [in] | event | event indication for which the callback has been triggered |
| [in] | resp_size | size of the data sent |
| [in] | resp | response |
| [in] | userdata | user data returned by callback function |
- Returns
- None
- Note
Example
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
{
printf( "m2mb_mqtt_deinit succeeded");
}
{
printf( "m2mb_mqtt_deinit succeeded");
}
}
◆ M2MB_MQTT_MSG_HNDLR_CB_T
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] | Handle | The mqtt handle associated with the client for which data is received |
| [in] | arg | User defined pointer, set while registering the callback |
| [in] | topic | The topic string |
| [in] | topic_Length | The topic string len |
| [in] | msg | The received payload |
| [in] | msg_Length | The payload size in bytes |
| [in] | status | Status 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)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
{
UINT8 buf[1024];
memcpy(buf, topic, topic_length);
buf[topic_length] = '\0';
printf("MQTT Message: Topic %s, Len %d\r\n", buf, msg_length);
memcpy(buf, msg, msg_length);
buf[msg_length] = '\0';
printf("Message: %s", buf);
{
printf("More data to be received");
}
}
void main(void)
{
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
{
printf( "m2mb_mqtt_connect succeeded");
}
result =
m2mb_mqtt_publish( p_mqtt, 0, 0, 10,
"things/aabbcc/property/temp",
"123", 3 );
{
printf( "m2mb_mqtt_publish succeeded");
}
CHAR* topic1 = "things/topic1";
CHAR* topic2 = "things/topic2";
topics[0].
cb = mqtt_topic_cb;
topics[1].
cb = mqtt_topic_cb;
{
printf( "m2mb_mqtt_subscribe succeeded");
}
{
printf( "m2mb_mqtt_disconnect succeeded");
}
{
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] | handle | the npt handle associated with the operation |
| [in] | ntp_event | The resulting event of the operation |
| [in] | resp_size | the size in bytes of the response structure (depends on the event) |
| [in] | resp_struct | the output data pointer. it must be cast to the correct type, depending on the event. |
| [in] | cb_args | User specific data to be passed to the callback. |
- Returns
- None
#include <time.h>
void m2mb_ntp_ind_callback ( M2MB_NTP_HANDLE h,
UINT16 resp_size,
void *resp_struct,
void *cb_args )
{
time_t current_time;
switch(ntp_event)
{
{
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;
}
}
◆ 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
|
◆ m2mb_mqtt_conf()
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] | Handle | handle to the MQTT client service, previously initialized by the m2mb_mqtt_init function. |
| [in] | argc | determines 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*)
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)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
{
printf( "m2mb_mqtt_deinit succeeded");
}
}
◆ m2mb_mqtt_connect()
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] | Handle | handle to the MQTT client service, previously initialized by the m2mb_mqtt_init function. |
| [in] | host | URL of the remote MQTT Broker that MQTT client needs to connect.(Ex: "api-dev.devicewise.com") |
| [in] | port | Port number of the remote MQTT Broker that MQTT client needs to connect.(Ex: 1883) |
- Returns
- M2MB_MQTT_RESPONSE_E values.
- Note
Example
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
{
printf( "m2mb_mqtt_deinit succeeded");
}
{
printf( "m2mb_mqtt_deinit succeeded");
}
}
◆ m2mb_mqtt_deinit()
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] | Handle | handle to the MQTT client service, that will be deinitialized by the function. |
- Returns
- M2MB_MQTT_RESPONSE_E values.
- Note
Example
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
{
printf( "m2mb_mqtt_deinit succeeded");
}
}
◆ m2mb_mqtt_disconnect()
m2mb_mqtt_disconnect is called to disconnect from the MQTT broker.
m2mb_mqtt_disconnect disconnects the specified MQTT client from the Broker.
- Parameters
-
| [in] | Handle | handle to the MQTT client service, previously initialized by the m2mb_mqtt_init function. |
- Returns
- M2MB_MQTT_RESPONSE_E values.
- Note
Example
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
{
printf( "m2mb_mqtt_connect succeeded");
}
{
printf( "m2mb_mqtt_disconnect succeeded");
}
{
printf( "m2mb_mqtt_deinit succeeded");
}
}
◆ m2mb_mqtt_getClientStatus()
m2mb_mqtt_getClientStatus gets MQTT client current status
This function allows to retrieve current status of the specified client.
- Parameters
-
| [in] | handle | handle of the mqtt client |
| [out] | status | pointer 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)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
{
printf("Client is initialized but not connected");
}
}
◆ m2mb_mqtt_init()
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] | pHandle | pointer to MQTT context handle that is is initialized by the function. This is to be used in subsequent MQTT APIs. |
| [out] | callback | callback that will be called if client receives an event. (ex: server disconnect the client and disconnect event is triggered) |
| [out] | userdata | a pointer to generic user data that will be returned as it is in the callback. |
- Returns
- M2MB_MQTT_RESPONSE_E values.
- Note
Example
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
}
◆ m2mb_mqtt_ping()
m2mb_mqtt_ping is called to ping
m2mb_mqtt_ping is called to ping the remote MQTT broker
- Parameters
-
| [in] | Handle | handle to the MQTT client service, previously initialized by the m2mb_mqtt_init function. |
- Returns
- M2MB_MQTT_RESPONSE_E values.
- Note
Example
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
{
printf( "m2mb_mqtt_connect succeeded");
}
{
printf( "m2mb_mqtt_ping succeeded");
}
{
printf( "m2mb_mqtt_disconnect succeeded");
}
{
printf( "m2mb_mqtt_deinit succeeded");
}
}
◆ m2mb_mqtt_publish()
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] | Handle | handle to the MQTT client service, previously initialized by the m2mb_mqtt_init function |
| [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 of the MQTT message |
| [in] | topic | Topic name |
| [in] | data | MQTT Message payload data |
| [in] | data_len | Data length |
- Returns
- M2MB_MQTT_RESPONSE_E values.
- Note
- Example
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
{
printf( "m2mb_mqtt_connect succeeded");
}
result =
m2mb_mqtt_publish( p_mqtt, 0, 0, 10,
"things/aabbcc/property/temp",
"123", 3 );
{
printf( "m2mb_mqtt_publish succeeded");
}
{
printf( "m2mb_mqtt_disconnect succeeded");
}
{
printf( "m2mb_mqtt_deinit succeeded");
}
}
◆ m2mb_mqtt_setClientStatus()
m2mb_mqtt_setClientStatus sets MQTT client current status
This function allows to set current status of the specified client.
- Parameters
-
| [in] | Handle | handle of the mqtt client |
| [in] | status | set as current client status (refer to M2MB_MQTT_STATUS_E enum) |
- Returns
- M2MB_MQTT_RESPONSE_E values.
- Note
Example
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
{
printf("Client status set successfully");
}
}
◆ m2mb_mqtt_subscribe()
m2mb_mqtt_subscribe is called to Subscribe.
m2mb_mqtt_subscribe Subscribes to one or multiple topics.
- Parameters
-
| [in] | Handle | handle to the MQTT client service, previously initialized by the m2mb_mqtt_init function. |
| [in] | message_id | Message ID of the MQTT message |
| [in] | topic_count | Number of topics to be subscribed |
| [in] | topics | Contiguous list of topics to subscribe to |
- Returns
- M2MB_MQTT_RESPONSE_E values.
- Note
Example
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
{
UINT8 buf[1024];
memcpy(buf, topic, topic_length);
buf[topic_length] = '\0';
printf("MQTT Message: Topic %s, Len %d\r\n", buf, msg_length);
memcpy(buf, msg, msg_length);
buf[msg_length] = '\0';
printf("Message: %s", buf);
{
printf("More data to be received");
}
}
void main(void)
{
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
{
printf( "m2mb_mqtt_connect succeeded");
}
result =
m2mb_mqtt_publish( p_mqtt, 0, 0, 10,
"things/aabbcc/property/temp",
"123", 3 );
{
printf( "m2mb_mqtt_publish succeeded");
}
CHAR* topic1 = "things/topic1";
CHAR* topic2 = "things/topic2";
topics[0].
cb = mqtt_topic_cb;
topics[1].
cb = mqtt_topic_cb;
{
printf( "m2mb_mqtt_subscribe succeeded");
}
{
printf( "m2mb_mqtt_disconnect succeeded");
}
{
printf( "m2mb_mqtt_deinit succeeded");
}
}
◆ m2mb_mqtt_unsubscribe()
m2mb_mqtt_unsubscribe is called to unsubscribe.
m2mb_mqtt_unsubscribe unsubscribes to one or multiple topics.
- Parameters
-
| [in] | Handle | handle to the MQTT client service, previously initialized by the m2mb_mqtt_init function. |
| [in] | message_id | Message ID of the MQTT message |
| [in] | topic_count | Number of topics to be subscribed |
| [in] | topics | Contiguous list of topics to unsubscribe to |
- Returns
- M2MB_MQTT_RESPONSE_E values.
- Note
Example
{
(void)handle;
switch(event)
{
printf("Disconnect Callback: event = %d", event);
break;
default :
printf("default case");
break;
}
}
void main(void)
{
{
return;
}
else
{
printf("m2mb_mqtt_init succeeded");
}
{
printf( "m2mb_mqtt_connect succeeded");
}
result =
m2mb_mqtt_publish( p_mqtt, 0, 0, 10,
"things/aabbcc/property/temp",
"123", 3 );
{
printf( "m2mb_mqtt_publish succeeded");
}
CHAR* topic1 = "things/topic1";
CHAR* topic2 = "things/topic2";
{
printf( "m2mb_mqtt_subscribe succeeded");
}
{
printf( "m2mb_mqtt_unsubscribe succeeded");
}
{
printf( "m2mb_mqtt_disconnect succeeded");
}
{
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] | handle | the handle that will be deinitialized |
- Returns
- M2MB_RESULT_E value
void m2mb_ntp_ind_callback ( M2MB_NTP_HANDLE h,
UINT16 resp_size,
void *resp_struct,
void *cb_args )
{
...
}
void main(void)
{
M2MB_NTP_HANDLE ntpH;
M2MB_RESULT_E retVal;
void *userContext = NULL;
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] | handle | the handle to be used for the operation |
| [in,out] | version | pointer to an allocated buffer (at least 20 bytes in size) to which copy the version string |
| [in] | maxlen | length of the allocated buffer (at least 20 bytes in size) |
- Returns
void m2mb_ntp_ind_callback ( M2MB_NTP_HANDLE h,
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;
retVal =
m2mb_ntp_init(&ntpH, m2mb_ntp_ind_callback, (
void*) userContext);
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("init failed.\r\n");
return;
}
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] | pHandle | pointer 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] | callback | User callback that will be called by ntp core |
| [in] | cb_args | User 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,
UINT16 resp_size,
void *resp_struct,
void *cb_args )
{
...
}
void main(void)
{
M2MB_NTP_HANDLE ntpH;
M2MB_RESULT_E retVal;
void *userContext = NULL;
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] | handle | the handle to be used for the operation |
- Returns
- M2MB_RESULT_E value
#include <time.h>
void m2mb_ntp_ind_callback ( M2MB_NTP_HANDLE h,
UINT16 resp_size,
void *resp_struct,
void *cb_args )
{
time_t current_time;
switch(ntp_event)
{
{
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;
CHAR ntpServer[] = "0.pool.ntp.org";
void *userContext = NULL;
retVal =
m2mb_ntp_init(&ntpH, m2mb_ntp_ind_callback, (
void*) userContext);
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("init failed.\r\n");
return;
}
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("Set cid failed.\r\n");
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set server failed.\r\n");
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set server port failed.\r\n");
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set timeout failed.\r\n");
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
CID activation
=======
if(M2MB_RESULT_SUCCESS != retVal)
{
FATAL("query failed.\r\n");
return;
}
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] | handle | the handle to be used for the operation |
| [in] | param | enum selecting which param should be set |
| [in] | value | opaque pointer to the parameter value to be set |
- Returns
- M2MB_RESULT_E value
void m2mb_ntp_ind_callback ( M2MB_NTP_HANDLE h,
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;
UINT32 keyId = 0;
CHAR authKeysFilePath[] = "/path/to/server/keys/file";
CHAR ntpServer[] = "0.pool.ntp.org";
void *userContext = NULL;
retVal =
m2mb_ntp_init(&ntpH, m2mb_ntp_ind_callback, (
void*) userContext);
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("init failed.\r\n");
return;
}
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set server failed.\r\n");
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set server port failed.\r\n");
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set timeout failed.\r\n");
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set authType failed.\r\n");
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set key id failed.\r\n");
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("set server keys file failed.\r\n");
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] | handle | the handle to be used for the operation |
| [in] | cid | CID value to be associated with the NTP client |
- Returns
- M2MB_RESULT_E value
void m2mb_ntp_ind_callback ( M2MB_NTP_HANDLE h,
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;
retVal =
m2mb_ntp_init(&ntpH, m2mb_ntp_ind_callback, (
void*) userContext);
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("init failed.\r\n");
return;
}
if(M2MB_RESULT_SUCCESS != retVal)
{
ERROR("Set cid failed.\r\n");
if(retVal == M2MB_RESULT_SUCCESS)
{
DEBUG("Deinit OK\r\n");
}
return;
}
...
}
M2MB_MQTT_STATUS_E
mqtt client status enum
Definition: m2mb_mqtt.h:99
M2MB_MQTT_RESPONSE_E m2mb_mqtt_setClientStatus(M2MB_MQTT_HANDLE handle, M2MB_MQTT_STATUS_E status)
m2mb_mqtt_setClientStatus sets MQTT client current status
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_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.
Definition: m2mb_mqtt.h:127
Definition: m2mb_mqtt.h:252
Definition: m2mb_ntp.h:101
M2MB_MQTT_RESPONSE_E m2mb_mqtt_deinit(M2MB_MQTT_HANDLE Handle)
m2mb_mqtt_deinit deinitializes MQTT service for specified MQTT client.
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
MQTT Receive Data Status Enum.
Definition: m2mb_mqtt.h:249
M2MB_RESULT_E m2mb_ntp_getVersion(M2MB_NTP_HANDLE handle, CHAR *version, UINT16 maxlen)
This is the ntp version get function.
Definition: m2mb_ntp.h:97
M2MB_MQTT_RESPONSE_E m2mb_mqtt_disconnect(M2MB_MQTT_HANDLE Handle)
m2mb_mqtt_disconnect is called to disconnect from the MQTT broker.
Definition: m2mb_ntp.h:103
M2MB_RESULT_E m2mb_ntp_init(M2MB_NTP_HANDLE *pHandle, m2mb_ntp_callback callback, void *cb_args)
This is the ntp initialization function.
Definition: m2mb_mqtt.h:102
M2MB_MQTT_RESPONSE_E m2mb_mqtt_ping(M2MB_MQTT_HANDLE Handle)
m2mb_mqtt_ping is called to ping
Definition: m2mb_mqtt.h:167
M2MB_MQTT_RESPONSE_E m2mb_mqtt_conf(M2MB_MQTT_HANDLE Handle, UINT8 nCmds,...)
m2mb_mqtt_conf sets/gets some MQTT parameters and configurations.
Definition: m2mb_mqtt.h:139
Definition: m2mb_mqtt.h:163
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.
Definition: m2mb_socket.h:249
const CHAR * topic_filter
Definition: m2mb_mqtt.h:500
M2MB_MQTT_QOS_E qos
Definition: m2mb_mqtt.h:501
Definition: m2mb_mqtt.h:63
Definition: m2mb_ntp.h:102
Definition: m2mb_mqtt.h:72
Definition: m2mb_ntp.h:68
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_RESULT_E m2mb_ntp_setCid(M2MB_NTP_HANDLE handle, INT16 cid)
Set the CID to be used with NTP.
Definition: m2mb_ntp.h:100
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
MQTT APIs response enum.
Definition: m2mb_mqtt.h:70
M2MB_RESULT_E m2mb_ntp_deinit(M2MB_NTP_HANDLE handle)
This is the ntp deinitialization function.
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 base types (ver. 121626N)
M2MB_MQTT_MSG_HNDLR_CB_T cb
Definition: m2mb_mqtt.h:502
M2MB_NTP_EVENTS_E
NTP Events.
Definition: m2mb_ntp.h:66
Definition: m2mb_ntp.h:91
M2MB_RESULT_E m2mb_ntp_setCfg(M2MB_NTP_HANDLE handle, M2MB_NTP_CFG_E param, void *value)
Set the one of the NTP parameters.
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
Definition: m2mb_mqtt.h:121
Definition: m2mb_ntp.h:104
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
MQTT Indications enum.
Definition: m2mb_mqtt.h:61
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_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_RESULT_E m2mb_ntp_queryServerTime(M2MB_NTP_HANDLE handle)
This is the ntp query function.