RainMaker MQTT

Functions

esp_rmaker_mqtt_conn_params_t *esp_rmaker_mqtt_get_conn_params(void)
esp_err_t esp_rmaker_mqtt_init(esp_rmaker_mqtt_conn_params_t *conn_params)

Initialize ESP RainMaker MQTT

Return

ESP_OK on success.

Return

error in case of any error.

Parameters
  • [in] conn_params: The MQTT configuration data

void esp_rmaker_mqtt_deinit(void)
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, uint8_t qos, int *msg_id)

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

  • [in] qos: Quality of Service for the Publish. Can be 0, 1 or 2. Also depends on what the MQTT broker supports.

  • [out] msg_id: msg_id for tracking if message is queued

esp_err_t esp_rmaker_mqtt_subscribe(const char *topic, esp_rmaker_mqtt_subscribe_cb_t cb, uint8_t qos, 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

  • [in] qos: Quality of Service for the Subscription. Can be 0, 1 or 2. Also depends on what the MQTT broker supports.

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.

esp_err_t esp_rmaker_mqtt_setup(esp_rmaker_mqtt_config_t mqtt_config)
void esp_rmaker_create_mqtt_topic(char *buf, size_t buf_size, const char *topic_suffix, const char *rule)

Creates appropriate MQTT Topic String based on CONFIG_ESP_RMAKER_MQTT_USE_BASIC_INGEST_TOPICS

Parameters
  • [out] buf: Buffer to hold topic string

  • [in] buf_size: Size of buffer

  • [in] topic_suffix: MQTT Topic suffix

  • [in] rule: Basic Ingests Rule Name

bool esp_rmaker_mqtt_is_budget_available(void)

Check if budget is available to publish an mqtt message.

Return

true if budget is available

Return

false if budget is exhausted

Note

esp_rmaker_mqtt_publish API already does this check. In addition to that, some use-cases might still need to check for this.

bool esp_rmaker_is_mqtt_connected()

Check if device is connected to MQTT Server.

Return

true if device is connected

Return

false if device is not connected