MQTT Client#
Functions#
Allocate memory for the MQTT for a single client. Returns MQTT Client instance pointer, which is used for further MQTT client operations. This is non-blocking API.
Establish TCP connection with the given MQTT client port and establish MQTT protocol level connection. If Callback is provided it is non-blocking API otherwise it is blocking API.
Disconnect the client from MQTT broker. This is a blocking API.
Publish the given message on the given topic. This is a blocking API.
Subscribe on the specified topic given.If any other client posts any message on the same topic, that message is received if MQTT client is subscribed to that topic. This is a non-blocking API.
Unsubscribe on the specified topic given. If unsubscribed, any messages on the topic is not received further This is a non-blocking API.
Wait for the MQTT messages to receive on the specific MQTT client. This is a non-blocking API.
Function Documentation#
rsi_mqtt_client_init#
rsi_mqtt_client_info_t* rsi_mqtt_client_init (int8_t * buffer, uint32_t length, int8_t * server_ip, uint32_t server_port, uint32_t client_port, uint16_t flags, uint16_t keep_alive_interval)
Allocate memory for the MQTT for a single client. Returns MQTT Client instance pointer, which is used for further MQTT client operations. This is non-blocking API.
Type | Direction | Argument Name | Description | |||||
---|---|---|---|---|---|---|---|---|
int8_t * | [in] | buffer | - Buffer pointer to allocate memory for MQTT Client information | |||||
uint32_t | [in] | length | - Buffer length | |||||
int8_t * | [in] | server_ip | - IPv4 address of the MQTT broker | |||||
uint32_t | [in] | server_port | - MQTT broker port number | |||||
uint32_t | [in] | client_port | - MQTT client port number | |||||
uint16_t | [in] | flags | - Each bit has its own significance
| |||||
uint16_t | [in] | keep_alive_interval | - MQTT client keep alive interval |
rsi_config_ipaddress() API needs to be called before this API
Returns
Positive Value - Returns MQTT client information structure pointer
NULL - In case of failure
rsi_mqtt_connect#
int32_t rsi_mqtt_connect (rsi_mqtt_client_info_t * rsi_mqtt_client, uint16_t flags, int8_t * client_id, int8_t * username, int8_t * password, void(*)(uint32_t sock_no, uint8_t *buffer, uint32_t length) callback)
Establish TCP connection with the given MQTT client port and establish MQTT protocol level connection. If Callback is provided it is non-blocking API otherwise it is blocking API.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_mqtt_client_info_t * | [in] | rsi_mqtt_client | - Callback handler for asynchronous response. |
uint16_t | [out] | flags | - Socket descriptor number |
int8_t * | [out] | client_id | - Buffer |
int8_t * | [out] | username | - length of buffer |
int8_t * | [in] | password | - password for the login credentials of MQTT server |
void(*)(uint32_t sock_no, uint8_t *buffer, uint32_t length) | N/A | callback |
Note
Need to register callback if ASYNC_MQTT is enable For Asynchronous
Returns
Zero - Success
Negative value - Failure
Note
Procedure for connecting MQTT over SSL :
Enable TCP_IP_FEAT_SSL in Opermode parameters as below
#define RSI_TCP_IP_FEATURE_BIT_MAP (TCP_IP_FEAT_DHCPV4_CLIENT | TCP_IP_FEAT_SSL | TCP_IP_FEAT_DNS_CLIENT)
Load the related SSL Certificates in the module using rsi_wlan_set_certificate() API.
rsi_mqtt_disconnect#
int32_t rsi_mqtt_disconnect (rsi_mqtt_client_info_t * rsi_mqtt_client)
Disconnect the client from MQTT broker. This is a blocking API.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_mqtt_client_info_t * | [in] | rsi_mqtt_client | - MQTT client information structure pointer that was returned in rsi_mqtt_client_init() API |
rsi_mqtt_connect() API needs to be called before this API
Returns
Zero - Success
Negative value - Failure
rsi_mqtt_publish#
int32_t rsi_mqtt_publish (rsi_mqtt_client_info_t * rsi_mqtt_client, int8_t * topic, MQTTMessage * publish_msg)
Publish the given message on the given topic. This is a blocking API.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_mqtt_client_info_t * | [in] | rsi_mqtt_client | - MQTT client info structure that was returned in rsi_mqtt_client_init() API |
int8_t * | [in] | topic | - String of topic |
MQTTMessage * | [in] | publish_msg | - Message to publish |
rsi_mqtt_connect() API needs to be called before this API
Returns
Zero - Success
Negative value - Failure
rsi_mqtt_subscribe#
int32_t rsi_mqtt_subscribe (rsi_mqtt_client_info_t * rsi_mqtt_client, uint8_t qos, int8_t * topic, void(*)(MessageData *md) call_back_handler_ptr)
Subscribe on the specified topic given.If any other client posts any message on the same topic, that message is received if MQTT client is subscribed to that topic. This is a non-blocking API.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_mqtt_client_info_t * | [in] | rsi_mqtt_client | - MQTT client structure info pointer that was returned in rsi_mqtt_client_init() API |
uint8_t | [in] | qos | - Quality of service of the message |
int8_t * | [in] | topic | - Topic string |
void(*)(MessageData *md) | [in] | call_back_handler_ptr | - Callback pointer to call when a message is received from MQTT broker |
rsi_mqtt_connect() API needs to be called before this API
Returns
Zero - Success
Negative value - Failure
rsi_mqtt_unsubscribe#
int32_t rsi_mqtt_unsubscribe (rsi_mqtt_client_info_t * rsi_mqtt_client, int8_t * topic)
Unsubscribe on the specified topic given. If unsubscribed, any messages on the topic is not received further This is a non-blocking API.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_mqtt_client_info_t * | [in] | rsi_mqtt_client | - MQTT client instance that was returned in rsi_mqtt_client_init() API |
int8_t * | [in] | topic | - Topic string |
rsi_mqtt_connect() API needs to be called before this API
Returns
Zero - Success
Negative value - Failure
rsi_mqtt_poll_for_recv_data#
int32_t rsi_mqtt_poll_for_recv_data (rsi_mqtt_client_info_t * rsi_mqtt_client, int time_out)
Wait for the MQTT messages to receive on the specific MQTT client. This is a non-blocking API.
Type | Direction | Argument Name | Description |
---|---|---|---|
rsi_mqtt_client_info_t * | [in] | rsi_mqtt_client | - MQTT client instance that was returned in rsi_mqtt_client_init() API |
int | [in] | time_out | - Time out in milliseconds. |
rsi_mqtt_connect() API needs to be called before this API
Returns
Zero - Success
Negative value - Failure