Embedded MQTT client#
Functions#
Create MQTT objects. TCP level connection happens in this API. This is a blocking API.
Connect to MQTT Server/Broker. MQTT level connection happens in this API. This is a blocking API.
Publish the given message on the topic specified. This is a blocking API.
Subscribe to the topic specified. Thus, MQTT client will receive any data that is published on this topic. This is a blocking API.
Unsubscribe to the topic specified.Thus, MQTT client will not receive any data published on this topic. This is a blocking API.
Disconnect the client from MQTT Server/Broker. TCP and MQTT level disconnection take place here. This is a blocking API.
Delete MQTT clients profile configuration. TCP level disconnection happens here, if required. This is a blocking API.
Register callbacks for MQTT Asynchronous messages. This is a non-blocking API.
Calculate length of MQTT packet. This is a non-blocking API.
Function Documentation#
rsi_emb_mqtt_client_init#
int32_t rsi_emb_mqtt_client_init (int8_t * server_ip, uint32_t server_port, uint32_t client_port, uint16_t flags, uint16_t keep_alive_interval, int8_t * clientid, int8_t * username, int8_t * password)
Create MQTT objects. TCP level connection happens in this API. This is a blocking API.
Type | Direction | Argument Name | Description |
---|---|---|---|
int8_t * | [in] | server_ip | - MQTT client keep alive interval |
uint32_t | [in] | server_port | - Client ID of MQTT client which should be unique for different clients. |
uint32_t | [in] | client_port | - User name of the MQTT client which is a credential for logging to MQTT server as an authentication |
uint16_t | [in] | flags | - Password of the MQTT client which is also credential for MQTT server as an authentication |
uint16_t | N/A | keep_alive_interval | |
int8_t * | N/A | clientid | |
int8_t * | N/A | username | |
int8_t * | N/A | password |
rsi_config_ipaddress() API needs to be called before this API.
Flags | Description |
---|---|
BIT(0) - Clean Session | 1 - Enable clean session for clearing the historic data |
0 - Disable clean session | |
BIT(1) - SSL flag | 1 - SSL Enable |
0 - SSL Disable | |
BIT(2) - Server IP version | 1 - IPV6 |
0 - IPV4 |
Returns
0 - Success
Negative Value - Failure (Possible Error Codes - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xfffffffb, 0xffffffe0)
Note
Precondition - rsi_config_ipaddress() API needs to be called before this API.
Refer to Error Codes for the description of above error codes.
rsi_emb_mqtt_connect#
int32_t rsi_emb_mqtt_connect (uint8_t mqtt_flags, int8_t * will_topic, uint16_t will_message_len, int8_t * will_message)
Connect to MQTT Server/Broker. MQTT level connection happens in this API. This is a blocking API.
Type | Direction | Argument Name | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
uint8_t | [in] | mqtt_flags | - Network flags. Each bit in the flag has its own significance
| ||||||||
int8_t * | [in] | will_topic | - Will topic that the MQTT client wants the MQTT Server to publish when disconnected unexpectedly. | ||||||||
uint16_t | [in] | will_message_len | - Length of will message | ||||||||
int8_t * | [in] | will_message | - Will message issued by the MQTT Server for a broken client. |
Returns
0 - Success
Negative Value - Failure (Possible Error Codes - 0xfffffffd, 0xfffffffc, 0xfffffffb, 0xffffffe0)
Note
Precondition - rsi_emb_mqtt_client_init() API needs to be called before this API.
will_topic and will_message are not supported and should be NULL.
For connecting Embedded MQTT over SSL : Enable TCP_IP_FEAT_SSL in Opermode parameters as here #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.
Refer to Error Codes for the description of above error codes.
rsi_emb_mqtt_publish#
int32_t rsi_emb_mqtt_publish (int8_t * topic, rsi_mqtt_pubmsg_t * publish_msg)
Publish the given message on the topic specified. This is a blocking API.
Type | Direction | Argument Name | Description |
---|---|---|---|
int8_t * | [in] | topic | - Topic string on which MQTT client wants to publish data |
rsi_mqtt_pubmsg_t * | [in] | publish_msg | - Publish message |
Returns
0 - Success
Negative Value - Failure (Possible Error Codes - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xfffffffb, 0xffffffe0)
Note
Precondition - rsi_emb_mqtt_connect() API needs to be called before this API.
Refer to Error Codes for the description of above error codes.
rsi_emb_mqtt_subscribe#
int32_t rsi_emb_mqtt_subscribe (uint8_t qos, int8_t * topic)
Subscribe to the topic specified. Thus, MQTT client will receive any data that is published on this topic. This is a blocking API.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint8_t | [in] | qos | - Quality of service of message at MQTT protocol level. Valid values are 0, 1, 2. |
int8_t * | [in] | topic | - Topic string on which MQTT client wants to subscribe. |
Returns
0 - Success
Negative Value - Failure (Possible Error Codes - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xfffffffb, 0xffffffe0)
Note
Precondition - rsi_emb_mqtt_connect() API needs to be called before this API.
Refer to Error Codes for the description of above error codes.
rsi_emb_mqtt_unsubscribe#
int32_t rsi_emb_mqtt_unsubscribe (int8_t * topic)
Unsubscribe to the topic specified.Thus, MQTT client will not receive any data published on this topic. This is a blocking API.
Type | Direction | Argument Name | Description |
---|---|---|---|
int8_t * | [in] | topic | - Topic string to which MQTT client wants to unsubscribe. |
Returns
0 - Success
Negative Value - Failure (Possible Error Codes - 0xfffffffe, 0xfffffffd, 0xfffffffc, 0xfffffffb, 0xffffffe0)
Note
Precondition - rsi_emb_mqtt_connect() API needs to be called before this API.
Refer to Error Codes for the description of above error codes.
rsi_emb_mqtt_disconnect#
int32_t rsi_emb_mqtt_disconnect ( Void)
Disconnect the client from MQTT Server/Broker. TCP and MQTT level disconnection take place here. This is a blocking API.
Type | Direction | Argument Name | Description |
---|---|---|---|
[in] | Void |
Returns
0 - Success
Negative Value - Failure (Possible Error Codes - 0xfffffffd, 0xfffffffc, 0xfffffffb, 0xffffffe0)
Note
Precondition - rsi_emb_mqtt_connect() API needs to be called before this API.
Refer to Error Codes section for the description of the above error codes Error Codes.
rsi_emb_mqtt_destroy#
int32_t rsi_emb_mqtt_destroy ( Void)
Delete MQTT clients profile configuration. TCP level disconnection happens here, if required. This is a blocking API.
Type | Direction | Argument Name | Description |
---|---|---|---|
[in] | Void |
Returns
0 - Success
Negative Value - Failure (Possible Error Codes - 0xfffffffd, 0xfffffffc, 0xfffffffb, 0xffffffe0)
Note
Precondition - rsi_emb_mqtt_client_init() API needs to be called before this API, based on requirement.This API can also be issued after rsi_emb_mqtt_disconnect() API.
Refer to Error Codes for the description of above error codes.
rsi_emb_mqtt_register_call_back#
int32_t rsi_emb_mqtt_register_call_back (uint32_t callback_id, void(*)(uint16_t status, uint8_t *buffer, const uint32_t length) call_back_handler_ptr, status, buffer, length)
Register callbacks for MQTT Asynchronous messages. This is a non-blocking API.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | callback_id | - Callback ID for MQTT responses |
void(*)(uint16_t status, uint8_t *buffer, const uint32_t length) | [in] | call_back_handler_ptr | - Callback function pointer |
[out] | status | - Success - RSI_SUCCESS. Failure - Possible error codes are : 0x0030, 0x0036, 0x0065, 0xBBF1, 0xBBF2, 0xBBF3, 0xFFF6 | |
[out] | buffer | - Pointer to buffer which holds data | |
[out] | length | - Length of the buffer |
Returns
Status of the call_back_handler_ptr
rsi_cal_mqtt_packet_len#
int32_t rsi_cal_mqtt_packet_len (int32_t rem_len)
Calculate length of MQTT packet. This is a non-blocking API.
Type | Direction | Argument Name | Description |
---|---|---|---|
int32_t | [in] | rem_len | - Length |
Returns
Length of MQTT packet (adjusted rem_len)