Functions#
This section provides a reference to the MQTT API functions.
Functions#
Initialize the mqtt_client and registers the event_handler.
Deinitialize the MQTT client.
Connect the client to MQTT broker.
Disconnect the client from MQTT broker.
Publish a message.
Indicate which client can subscribe to a topic.
Indicate which client can unsubscribe a topic.
Function Documentation#
sl_mqtt_client_init#
sl_status_t sl_mqtt_client_init (sl_mqtt_client_t * client, sl_mqtt_client_event_handler event_handler)
Initialize the mqtt_client and registers the event_handler.
[in] | client | Valid pointer to the client structure. This shall not be null. |
[in] | event_handler | Event handler which will be called for various events on client. |
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
38
of file components/service/mqtt/inc/sl_mqtt_client.h
sl_mqtt_client_deinit#
sl_status_t sl_mqtt_client_deinit (sl_mqtt_client_t * client)
Deinitialize the MQTT client.
[in] | client | Valid pointer to the client structure. |
sl_mqtt_client_init should be called before this API.
Returns
sl_status_t. See https://docs.silabs.com/gecko-platform/4.1/common/api/group-status for details.
50
of file components/service/mqtt/inc/sl_mqtt_client.h
sl_mqtt_client_connect#
sl_status_t sl_mqtt_client_connect (sl_mqtt_client_t * client, const sl_mqtt_broker_t * broker, const sl_mqtt_client_last_will_message_t * last_will_message, const sl_mqtt_client_configuration_t * configuration, uint32_t timeout)
Connect the client to MQTT broker.
[in] | client | Client which would be connected to the broker. |
[in] | broker | Broker configuration. |
[in] | last_will_message | Last will message of the client. |
[in] | configuration | Client configuration. |
[in] | timeout | Timeout for the API. If the value is zero, the API will be asynchronous. |
sl_mqtt_client_init should be called before this API.
Returns
sl_status_t. If called asynchronously, SL_STATUS_IN_PROGRESS will be returned as status.
Note
In subsequent calls to connect, it is optional to provide broker, last_will_message, and configuration parameters.
If broker and configuration parameters are given null, then value given in the first connect() call would be retained.
In case of last_will_message parameter, values given in each connect() call would be considered. If value of last_will_message parameter is given as null, then no will message would be sent to the broker parameter.
Only is_clean_session, credential_id, client_id, client_id_length of sl_mqtt_client_configuration_t are considered.
75
of file components/service/mqtt/inc/sl_mqtt_client.h
sl_mqtt_client_disconnect#
sl_status_t sl_mqtt_client_disconnect (sl_mqtt_client_t * client, uint32_t timeout)
Disconnect the client from MQTT broker.
[in] | client | Client which needs to be disconnected from the broker. |
[in] | timeout | Timeout for the API. If the value is zero, the API will be asynchronous. |
sl_mqtt_client_connect should be called before this API.
Returns
sl_status_t. If called asynchronously, SL_STATUS_IN_PROGRESS will be returned as status.
93
of file components/service/mqtt/inc/sl_mqtt_client.h
sl_mqtt_client_publish#
sl_status_t sl_mqtt_client_publish (sl_mqtt_client_t * client, const sl_mqtt_client_message_t * message, uint32_t timeout, void * context)
Publish a message.
[in] | client | Client which requires to publish the message. |
[in] | message | Message which needs to be published. |
[in] | timeout | Timeout for the API. If the value is zero, the API will be asynchronous. |
[in] | context | Context which would be returned in event handler if the API is called asynchronously. The caller must ensure that the lifecycle of context is retained until the callback is invoked. The deallocation of context is also the responsibility of the caller. |
sl_mqtt_client_connect should be called before this API.
Returns
sl_status_t. If called asynchronously, SL_STATUS_IN_PROGRESS will be returned as status.
111
of file components/service/mqtt/inc/sl_mqtt_client.h
sl_mqtt_client_subscribe#
sl_status_t sl_mqtt_client_subscribe (sl_mqtt_client_t * client, const uint8_t * topic, uint16_t topic_length, sl_mqtt_qos_t qos_level, uint32_t timeout, sl_mqtt_client_message_received message_handler, void * context)
Indicate which client can subscribe to a topic.
[in] | client | Client which needs to subscribe to the topic. |
[in] | topic | Topic of interest. |
[in] | topic_length | Length of the topic. |
[in] | qos_level | Quality of service using which client subscribes. |
[in] | timeout | Timeout for API. If the value is zero, the API will be asynchronous. |
[in] | message_handler | Message handler which invokes for messages published on the topic. |
[in] | context | Context that is sent back to the message handler. The caller must ensure that the lifecycle of the context is retained until the callback is invoked. The deallocation of context is also the responsibility of the caller. |
sl_mqtt_client_connect should be called before this API.
Returns
sl_status_t. If called asynchronously, SL_STATUS_IN_PROGRESS will be returned as status.
138
of file components/service/mqtt/inc/sl_mqtt_client.h
sl_mqtt_client_unsubscribe#
sl_status_t sl_mqtt_client_unsubscribe (sl_mqtt_client_t * client, const uint8_t * topic, uint16_t length, uint32_t timeout, void * context)
Indicate which client can unsubscribe a topic.
[in] | client | Client that unsubscribes the topic. |
[in] | topic | Topic from which client needs to unsubscribe. |
[in] | length | Length of the topic. |
[in] | timeout | Timeout for the API. If the value is zero, the API will be asynchronous. |
[in] | context | Context that returns in event handler if the API is called asynchronously. The caller must ensure that the lifecycle of the context is retained until the callback is invoked. The deallocation of context is also the responsibility of the caller. |
sl_mqtt_client_subscribe should be called before this API.
Returns
sl_status_t. If called asynchronously, SL_STATUS_IN_PROGRESS will be returned as status.
164
of file components/service/mqtt/inc/sl_mqtt_client.h