I have InfluxDB 1.8.10 running on a Pi4 Bookworm along with mosquito, nodeRED and Grafana.
Data from an Arduino-basd sensor which includes two tags (location, sensor_type) and multiple data fields (temp, humidity, pressure) is being sent by MQTT to mosquito, nodeRED to InfluxDB. All working fine.
Now, I need to add a second sensor at another location which generates similar data (different location and sensor_type but same field keys) whose data will be sent from the same Arduino hardware. If InfluxDB cannot handle nested JSON, how do I structure the two sets of data so that it will all end in the db with the appropriate tags and with the same timestamp?
Hello @PhilGoody,
You’re going to want to include location and sensor tags in your JSON
{
"location": "location_1",
"sensor_type": "sensor_1",
"temp": 23.5,
"humidity": 60,
"pressure": 1012,
"timestamp": 1696972942000000000
}
Or you could do something like:
msg.payload.location = "location_1";
msg.payload.sensor_type = "sensor_1";
return msg;
I am already sending the first of your suggestions without timestamp. Timestamp is added by Influxdb. So how do I add the second sensor, like this?
{
{
“location”: “location_1”,
“sensor_type”: “sensor_1”,
“temp”: 23.5,
“humidity”: 60,
“pressure”: 1012,
}
{
“location”: “location_2”,
“sensor_type”: “sensor_2”,
“temp”: 15.5,
“humidity”: 35,
}
}
That’s a nested object.