Hello,
I’m trying to parse a json string from an MQTT feed - following the guides from github i can plot the three pressures but i can’t seem to loop through the array and plot against the timestamp - is there something obvious I’m missing?
For these types of data, what would be best -use the default tag names or split these up into new tags and fields?
telegraf.conf
[[inputs.mqtt_consumer]]
servers = ["tcp://mosquitto:1883"]
topics = ["device/manufacturer/model/serial_number/pressures"]
data_format = "json_v2"
[[inputs.mqtt_consumer.json_v2]]
[[inputs.mqtt_consumer.json_v2.object]]
path = "pressures"
timestamp_path = "timestamp"
timestamp_format = "UTC"
[[inputs.mqtt_consumer.json_v2.object]]
path = "pressures"
JSON
{ "pressures": [
{
"timestamp": "2022-07-28 02:43:33:667",
"pump 1": -5.0,
"pump 2": 27.0,
"system": -5.0
},
{
"timestamp": "2022-07-28 02:43:33:767",
"pump 1": -5.0,
"pump 2": 27.0,
"system": -6.0
},
{
"timestamp": "2022-07-28 02:43:33:867",
"pump 1": -5.0,
"pump 2": 27.0,
"system": -5.0
},
{
"timestamp": "2022-07-28 02:43:33:967",
"pump 1": -5.0,
"pump 2": 27.0,
"system": -5.0
},
{
"timestamp": "2022-07-28 02:43:34:067",
"pump 1": -6.0,
"pump 2": 26.0,
"system": -6.0
},
{
"timestamp": "2022-07-28 02:43:34:167",
"pump 1": -5.0,
"pump 2": 28.0,
"system": -5.0
},
{
"timestamp": "2022-07-28 02:43:34:267",
"pump 1": -5.0,
"pump 2": 27.0,
"system": -6.0
},
{
"timestamp": "2022-07-28 02:43:34:367",
"pump 1": -4.0,
"pump 2": 27.0,
"system": -6.0
},
{
"timestamp": "2022-07-28 02:43:34:467",
"pump 1": -6.0,
"pump 2": 27.0,
"system": -5.0
},
{
"timestamp": "2022-07-28 02:43:34:567",
"pump 1": -6.0,
"pump 2": 28.0,
"system": -5.0
},
{
"timestamp": "2022-07-28 02:43:34:667",
"pump 1": -5.0,
"pump 2": 27.0,
"system": -5.0
},
{
"timestamp": "2022-07-28 02:43:34:767",
"pump 1": -5.0,
"pump 2": 27.0,
"system": -6.0
},
{
"timestamp": "2022-07-28 02:43:34:867",
"pump 1": -5.0,
"pump 2": 28.0,
"system": -5.0
}
],}
The JSON file is produced roughly every second and contains between 8-12 pressure points each iteration. I can change the format of the JSON string if necessary as its been produced by a python client. As I’m new to JSON and LP this is my first attempt so this may not be the best JSON structure. The timestamp is currently set to UTC but can bechanged to unix_ms if this is better?
A quick follow on question - is it better to break out the JSON data into single values and instead use multiple MQTT topics to pass data to influx? Are multiple MQTT feeds with a single value more efficient than one MQTT feed with a complex JSON/array object coating all the values?
Many thanks!