3.1.7.2 MQTT Service
The MQTT service provides an Application Programming Interface (API) to manage MQTT functionalities. These functionalities include, configuring the MQTT settings, connecting, disconnecting and reconnecting to the MQTT broker, publishing, subscribing and setting callbacks.
RNWF_RESULT_t RNWF_MQTT_SrvCtrl( RNWF_MQTT_SERVICE_t request, void *input)
It
handles following services and reports the result to application over the return code or
through the registered callback:Service | Input | Description |
---|---|---|
RNWF_MQTT_CONFIG | Broker URL, Port, Client ID, Username, TLS configuration | Configures the MQTT server details along with the corresponding TLS configurations |
RNWF_MQTT_CONNECT | None | Initiates the MQTT connection to the configured MQTT broker |
RNWF_MQTT_RECONNECT | None | Triggers the re-connection to the configured MQTT broker |
RNWF_MQTT_DISCONNECT | None | Disconnects from the connected MQTT broker |
RNWF_MQTT_SUBSCRIBE_QOS0 | Subscribe topic (String) | Subscribes to the given subscribe topic with QoS0 |
RNWF_MQTT_SUBSCRIBE_QOS1 | Subscribe topic (String) | Subscribes to the given subscribe topic with QoS1 |
RNWF_MQTT_SUBSCRIBE_QOS2 | Subscribe topic (String) | Subscribes to the given subscribe topic with QoS2 |
RNWF_MQTT_PUBLISH | New, QOS, Retain, topic, message | Publish the message on given publish topic and configuration |
RNWF_MQTT_SET_CALLBACK | Callback Function Handler | Registers the MQTT callback to report the status to user application |
Event | Response Components | Comments |
---|---|---|
RNWF_MQTT_CONNECTED | None | Reported once connected to MQTT broker |
RNWF_MQTT_DISCONNECTED | None | Event to report the MQTT broker disconnection |
RNWF_MQTT_SUBCRIBE_MSG | dup, QoS, retain, topic, payload | Reports the received payload for the subscribed topic |
RNWF_MQTT_SUBCRIBE_ACK | Integer string | Subscribe ack return code |
MQTT Publish
User application can publish to the MQTT broker by creating the MQTT frame and then sending the frame using the RNWF_MQTT_SrvCtrl(RNWF_MQTT_PUBLISH, (void *)&mqtt_pub) API. The sequence chart is shown below.
MQTT Subscribe
The sequence for subscribing to a topic from the MQTT Broker is shown below. The user application needs to use the RNWF_MQTT_SrvCtrl(RNWF_MQTT_SUBSCRIBE_QOS0, buffer) API to subscribe to the topic with the appropriate QoS value.