跳到主要内容

How do I batch multiple Time Series Data points into a single MQTT message?

Build the JSON payload manually and publish it directly via MQTT. This avoids the overhead of multiple esp_rmaker_param_update_and_report calls.

Payload format (example: device EnergyTsData, parameters A, B, C, D, 3 records each at 60-second intervals):

{
"ts_data_version": "2021-09-13",
"ts_data": [
{
"name": "EnergyTsData.A",
"dt": "float",
"records": [
{"t": 1678782905, "v": 768.0},
{"t": 1678782965, "v": 768.0},
{"t": 1678783025, "v": 768.0}
]
}
]
}
  • name: <DeviceName>.<ParameterName>
  • dt: data type ("float", "int", "string", etc.)
  • t: Unix timestamp when the data was generated
  • v: data value

Publish to cloud:

esp_err_t esp_rainmaker_report_ts_data(char *buf, size_t buf_size)
{
char publish_topic[150] = {0};
esp_rmaker_create_mqtt_topic(publish_topic, sizeof(publish_topic),
"tsdata", "esp_ts_ingest");
return esp_rmaker_mqtt_publish(publish_topic, buf, buf_size, RMAKER_MQTT_QOS1, NULL);
}

When using this method, the parameter does not need PROP_FLAG_TIME_SERIES — the application controls all reporting.