Rather than splitting the message, have you thought about accessing the parts directly? Once split, each of those is a different message, and if you insert those parts into influx, they get inserted as different measurements, rather than one single measurement. Again, go back to the link Steve gave you, working with messages. From the original message you get out of MQTT, you have an object with the following payload:
{
"Time": "2020-04-24T19:59:42",
"Gas": {
"Count": 4624.38
},
"Wasser": {
"Count": 771.473
},
"gas_day": 0.87,
"gas_month": 59.65,
"gas_year": 1.84,
"water_day": 0.32,
"water_month": 12.7,
"water_year": 0.9
}
From a function node directly behind that mqtt-in node, you can access the values as msg.payload.gas_day
, msg.payload.gas_month
, and so on. To get the object you have described in msg7.payload
in your original post, you can try the following:
msg.payload = [
{
"gas_day": msg.payload.gas_day,
"gas_month": msg.payload.gas_month,
"gas_year": msg.payload.gas_year,
"water_day": msg.payload.water_day,
"water_month": msg.payload.water_month,
"water_year": msg.payload.water_year
}
];
return msg;
What's going wrong in the above image is that once you've split the object, the keys turn into topics, and the payload differs per type. For the Time
key, your payload is a string. For Gas
, it's an object, gas_year
for example, is a number. If you did split it, then pass all those messages to a function node and have it operate on msg.payload.???
, the contents of msg.payload, and especially the type of each payload, is different.
Can you explain what the format is that you need?
What is for your use case the format of your messages that you need? See the influx node's builtin documentation for a description, and work it out for your use case. If you pass us back that information, we can give more detailed information on how to continue.
Edit: this topic is worth a read too, and might allow you to figure it out as well: Help needed with MQTT to influx