MQTT Client#

Functions#

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.

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(*callback)(uint32_t sock_no, uint8_t *buffer, uint32_t length))

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.

int32_t
rsi_mqtt_disconnect(rsi_mqtt_client_info_t *rsi_mqtt_client)

Disconnect the client from MQTT broker. This is a blocking API.

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.

int32_t
rsi_mqtt_subscribe(rsi_mqtt_client_info_t *rsi_mqtt_client, uint8_t qos, int8_t *topic, void(*call_back_handler_ptr)(MessageData *md))

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.

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.

int32_t
rsi_mqtt_poll_for_recv_data(rsi_mqtt_client_info_t *rsi_mqtt_client, uint16_t time_out)

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.

Parameters
[in]buffer

- Buffer pointer to allocate memory for MQTT Client information

[in]length

- Buffer length

[in]server_ip

- IPv4 address of the MQTT broker

[in]server_port

- MQTT broker port number

[in]client_port

- MQTT client port number

[in]flags

- Each bit has its own significance

Flags

Description

Bit(0) - Server IP version

1 - IPv6

0 - IPv4

[in]keep_alive_interval

- MQTT client keep alive interval If there are no transactions between MQTT client and broker with in this time period, MQTT Broker disconnects the MQTT client If 0 -> Server does not disconnect

Returns

  • Positive Value - Returns MQTT client information structure pointer NULL - In case of failure


Definition at line 56 of file network/protocols/rsi_mqtt_client.c

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.

Parameters
[in]rsi_mqtt_client

- Callback handler for asynchronous response.

[out]flags

- Socket descriptor number

[out]client_id

- Buffer

[out]username

- length of buffer

[in]password

- password for the login credentials of MQTT server

N/Acallback

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.


Definition at line 157 of file network/protocols/rsi_mqtt_client.c

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.

Parameters
[in]rsi_mqtt_client

- MQTT client information structure pointer that was returned in rsi_mqtt_client_init() API

Returns

  • Zero - Success Negative value - Failure


Definition at line 247 of file network/protocols/rsi_mqtt_client.c

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.

Parameters
[in]rsi_mqtt_client

- MQTT client info structure that was returned in rsi_mqtt_client_init() API

[in]topic

- String of topic

[in]publish_msg

- Message to publish

Returns

  • Zero - Success Negative value - Failure


Definition at line 278 of file network/protocols/rsi_mqtt_client.c

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.

Parameters
[in]rsi_mqtt_client

- MQTT client structure info pointer that was returned in rsi_mqtt_client_init() API

[in]qos

- Quality of service of the message

[in]topic

- Topic string

[in]call_back_handler_ptr

- Callback pointer to call when a message is received from MQTT broker

Returns

  • Zero - Success Negative value - Failure


Definition at line 309 of file network/protocols/rsi_mqtt_client.c

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.

Parameters
[in]rsi_mqtt_client

- MQTT client instance that was returned in rsi_mqtt_client_init() API

[in]topic

- Topic string

Returns

  • Zero - Success Negative value - Failure


Definition at line 348 of file network/protocols/rsi_mqtt_client.c

rsi_mqtt_poll_for_recv_data#

int32_t rsi_mqtt_poll_for_recv_data (rsi_mqtt_client_info_t * rsi_mqtt_client, uint16_t time_out)

Wait for the MQTT messages to receive on the specific MQTT client. This is a non-blocking API.

Parameters
[in]rsi_mqtt_client

- MQTT client instance that was returned in rsi_mqtt_client_init() API

[in]time_out

- Time out in milliseconds.

Returns

  • Zero - Success Negative value - Failure


Definition at line 372 of file network/protocols/rsi_mqtt_client.c