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.
[in] | server_ip | - MQTT client keep alive interval |
[in] | server_port | - Client ID of MQTT client which should be unique for different clients. |
[in] | client_port | - User name of the MQTT client which is a credential for logging to MQTT server as an authentication |
[in] | flags | - Password of the MQTT client which is also credential for MQTT server as an authentication |
N/A | keep_alive_interval | |
N/A | clientid | |
N/A | username | |
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
RSI_EMB_MQTT_KEEPALIVE_RETRIES - Configures the MQTT Keep-alive retries in case the MQTT Ping response is not received from the MQTT broker within the command acknowledgement time during the MQTT Keep-alive handshake. This is an optional parameter which can be configured in rsi_wlan_config.h. If this is not configured, then its default value is 0. In that case, firmware will not retry MQTT Ping internally and notify the host of MQTT Keepalive timeout.
Precondition - rsi_config_ipaddress() API needs to be called before this API.
Refer to Error Codes for the description of above error codes.
55
of file network/protocols/rsi_emb_mqtt_client.c
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.
[in] | mqtt_flags | - Network flags. Each bit in the flag has its own significance
| ||||||||
[in] | will_topic | - Will topic that the MQTT client wants the MQTT Server to publish when disconnected unexpectedly. | ||||||||
[in] | will_message_len | - Length of will message | ||||||||
[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.
236
of file network/protocols/rsi_emb_mqtt_client.c
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.
[in] | topic | - Topic string on which MQTT client wants to publish data |
[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.
336
of file network/protocols/rsi_emb_mqtt_client.c
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.
[in] | qos | - Quality of service of message at MQTT protocol level. Valid values are 0, 1, 2. |
[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.
466
of file network/protocols/rsi_emb_mqtt_client.c
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.
[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.
569
of file network/protocols/rsi_emb_mqtt_client.c
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.
[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.
671
of file network/protocols/rsi_emb_mqtt_client.c
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.
[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.
755
of file network/protocols/rsi_emb_mqtt_client.c
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.
[in] | callback_id | - Callback ID for MQTT responses |
[in] | call_back_handler_ptr | - Callback function pointer |
[out] | status | - Success - RSI_SUCCESS. |
[out] | buffer | - Pointer to buffer which holds data |
[out] | length | - Length of the buffer |
Returns
Status of the call_back_handler_ptr
Note
callback_id
ID
Description
RSI_WLAN_NWK_EMB_MQTT_REMOTE_TERMINATE_CB
If registered, this callback notifies the application of disconnection with the MQTT broker.
RSI_WLAN_NWK_EMB_MQTT_PUB_MSG_CB
If registered, this callback provides MQTT publish received data to the application.
RSI_WLAN_NWK_EMB_MQTT_KEEPALIVE_TIMEOUT_CB
If registered, this callback notifies the application of MQTT keepalive response timeout, i.e., ping response is not received within the MQTT Command ACK Timer.
841
of file network/protocols/rsi_emb_mqtt_client.c
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.
[in] | rem_len | - Length |
Returns
Length of MQTT packet (adjusted rem_len)
880
of file network/protocols/rsi_emb_mqtt_client.c