RainMaker MQTT

Functions

esp_err_t esp_rmaker_mqtt_init(esp_rmaker_mqtt_config_t *config)

Initialize ESP RainMaker MQTT

Return

ESP_OK on success.

Return

error in case of any error.

Parameters
  • [in] config: The MQTT configuration data

esp_err_t esp_rmaker_mqtt_connect(void)

MQTT Connect

Starts the connection attempts to the MQTT broker as per the configuration provided during initializing. This should ideally be called after successful network connection.

Return

ESP_OK on success.

Return

error in case of any error.

esp_err_t esp_rmaker_mqtt_disconnect(void)

MQTT Disconnect

Disconnects from the MQTT broker.

Return

ESP_OK on success.

Return

error in case of any error.

esp_err_t esp_rmaker_mqtt_publish(const char *topic, void *data, size_t data_len)

Publish MQTT Message

Return

ESP_OK on success.

Return

error in case of any error.

Parameters
  • [in] topic: The MQTT topic on which the message should be published.

  • [in] data: Data to be published

  • [in] data_len: Length of the data

esp_err_t esp_rmaker_mqtt_subscribe(const char *topic, esp_rmaker_mqtt_subscribe_cb_t cb, void *priv_data)

Subscribe to MQTT topic

Return

ESP_OK on success.

Return

error in case of any error.

Parameters
  • [in] topic: The topic to be subscribed to.

  • [in] cb: The callback to be invoked when a message is received on the given topic.

  • [in] priv_data: Optional private data to be passed to the callback

esp_err_t esp_rmaker_mqtt_unsubscribe(const char *topic)

Unsubscribe from MQTT topic

Return

ESP_OK on success.

Return

error in case of any error.

Parameters
  • [in] topic: Topic from which to unsubscribe.

Structures

struct esp_rmaker_mqtt_config_t

ESP RainMaker MQTT Configuration

Public Members

char *mqtt_host

MQTT Host

char *client_id

Client ID

char *client_cert

Client Certificate in NULL terminate PEM format

char *client_key

Client Key in NULL terminate PEM format

char *server_cert

Server Certificate in NULL terminate PEM format

Type Definitions

typedef void (*esp_rmaker_mqtt_subscribe_cb_t)(const char *topic, void *payload, size_t payload_len, void *priv_data)

ESP RainMaker MQTT Subscribe callback prototype

Parameters
  • [in] topic: Topic on which the message was received

  • [in] payload: Data received in the message

  • [in] payload_len: Length of the data

  • [in] priv_data: The private data passed during subscription