![]() |
m2mb API docs
30.00.007
m2mb API sets documentation
|
This group includes all the information about m2mb_mqtt configuration and usage *. More...
This group includes all the information about m2mb_mqtt configuration and usage *.
| 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.
| [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 |
Example
| 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.
| [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. |
Example
| enum M2MB_MQTT_ACTION_E |
MQTT actions enum List of actions performed through m2mb_mqtt_conf API.
| enum M2MB_MQTT_QOS_E |
| enum M2MB_MQTT_RESPONSE_E |
MQTT APIs response enum.
| enum M2MB_MQTT_STATUS_E |
mqtt client status enum
| 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.
| [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) |
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
| 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.
| [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) |
Example
| 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
| [in] | Handle | handle to the MQTT client service, that will be deinitialized by the function. |
Example
| 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.
| [in] | Handle | handle to the MQTT client service, previously initialized by the m2mb_mqtt_init function. |
Example
| 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.
| [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) |
Example
| 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.
| [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. |
Example
| 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
| [in] | Handle | handle to the MQTT client service, previously initialized by the m2mb_mqtt_init function. |
Example
| 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 Publishes a message to the MQTT broker.
m2mb_mqtt_publish Publishes a message on a given topic.
| [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 |
| 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.
| [in] | Handle | handle of the mqtt client |
| [in] | status | set as current client status (refer to M2MB_MQTT_STATUS_E enum) |
Example
| 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.
| [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 |
Example
| M2MB_MQTT_RESPONSE_E m2mb_mqtt_unsubscribe | ( | M2MB_MQTT_HANDLE | Handle, |
| UINT16 | message_id, | ||
| UINT32 | topic_count, | ||
| M2MB_MQTT_TOPIC_T * | topics | ||
| ) |
MqttClient_Unsubscribe is called to unsubscribe.
MqttClient_Unsubscribe unsubscribes to one or multiple topics.
| [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 |
Example