Influx DB data insertion

I want to parse the tag value=tag key pair and field value=field key pair from the payload and insert it influxdb measurement. Can anyone help me.

Well, you haven't told us what your input data looks like. Please try a debug msg and share the actual data. You probably need a JSON node to de-serialise the data but without more info, we can't provide better help.

-----overall scheme
image---------json node settings
please find the screenshots

same data is getting logged in to influx db. But in the value column, I am getting the full payload. I need to parse the data and make separate column for each tag.


Have you tried putting a change node in between JSON and influx? And in that change node modify the payload to the format you need. Beyond that, there’s still a lot we don’t know. Please read @TotallyInformation’s message above again and supply that if you’re looking for more detailed help.

In particular show us what is coming out of the data collector function node and the json node.

json data

Ahhh, so the data was deserialised already and adding a JSON node caused it to be serialised instead.

and this is the data after collecting the raw data.....

my target is to put this data into influxdb with tag key and tag value pair

Have you got the mqtt node set to parse the input as JSON? If not then I suggest you do that and then look at what is coming out of the mqtt. It should give you a javascript object rather than a string, then the rest should be much easier.
By the way if you you want to write data at the current timestamp you don't need to add a timestamp, the influx node will do that for you.

It took a few minutes, but now I understand what I'm looking at. Take a really close look at the msg.payload object in that photo. Your payload is an object containing 3 properties: time, which holds a timestamp, topicwhich holds the same topic as msg.topic and according to the image is adc/ecu/site1, and payload, which is a JSON string. So you have a mixture of serialised and unserialised data that is being passed to the JSON node, and since the outer part is unserialised the total gets serialised. Resulting in a single JSON string coming out of that node.

What you need to do is parse the contents of msg.payload.payload. Either by following Colin's instructions if you haven't done so yet, or by changing the code in the data collector function node. Next, your object should look like an actual object with nested properties. You can then use a change node to format the payload the way you want it to for inserting it to influxdb. However, keep in mind that passing it towards the JSON node will turn it into a JSON string if it was an object before, or from a JSON string to an object if it was a string already. You have to work out what/how it is yourself.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.