Store serial data to influx

Hi,

im new to Nodered as I think it can do what Im trying to accomplish: process incoming serial data into influx. The serial port input and the influx output is working fine. I can't seem to figure out how to process the incoming data.
Hopefully somebody can tell me how to do this:

$DL799,Air_Volume_Flow,35.7*1D

I would like to strip of the first part of the sentence: $DL799,
then, the Air_Volume_Flow I would like to get outputted to Influx as an individual tag, with the value 35,7.
strip of the *1D part.
there is a continuous stream of serial data in this format, with multiple different tag names.
Ive tried, split, function, change and filter, but I can't work it out.

This should be very easy right?
can somebody please tell me how to do this?

thank you very much

Martijn

Here is a demo flow using a Function node to split() based on the comma seperated values and prepare the msg for influx .. im not sure about the end structure of your db so the msg may need some corrections but at least it'll give you some ideas for what you are trying to do.

[{"id":"7d3363de65139b00","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"$DL799,Air_Volume_Flow,35.7*1D","payloadType":"str","x":390,"y":1260,"wires":[["1badcd7e92724e51","d75fa0d4e0283599"]]},{"id":"1badcd7e92724e51","type":"function","z":"54efb553244c241f","name":"prepare msg","func":"let arr = msg.payload.split(\",\")\n\nlet device = arr[0]\nlet measurement = arr[1]\nlet value = parseFloat(arr[2])\n\n// prepare msg for influx Batch Output Node\nmsg.payload = [\n    {\n        measurement: measurement,\n        fields: {\n            device: device,\n            value: value,\n        },\n        tags: {\n            tag: device\n        },\n        timestamp: new Date()\n    }\n];\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":1260,"wires":[["a8e0829c4bac856d"]]},{"id":"a8e0829c4bac856d","type":"debug","z":"54efb553244c241f","name":"to db","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":1260,"wires":[]},{"id":"d75fa0d4e0283599","type":"debug","z":"54efb553244c241f","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":520,"y":1180,"wires":[]}]

Do you mean an individual measurement rather than tag?

You can also use this node-red-contrib-string which allows you to manipulate a string in all directions without knowing the programming.
For example:

  • separate a string with a comma as a delimiter.
  • Remove one or more characters at the beginning or at the end.
  • Change a string into a number. Useful for your database.
  • There are many more possibilities in this node

This node is just great for people like me who are not programmers
The link to the explanation of this node

Hi, yes, I meant an individual measurement stored with their value that comes after the comma

interesting, just installed this node and see what I can make it do

So,

ive tried to play around a bit, the simple code from UnborN seems to be quite effective. Im almost there. Influx is expecting me to output msg.measurement with the measurement name.

let arr = msg.payload.split(",")

let device = arr[0]
let measurement = arr[1]
let value = parseFloat(arr[2])

// prepare msg for influx Batch Output Node
msg.payload = [
    {
        value: value,
        
            }
];

return msg;


In my first post I mentioned tags, that should have been, measurements.
Influx. The influx node is showing: Tip: If no measurement is specified, ensure msg.measurement contains the measurement name.

so, the separated part of the string, that is Air_Volume_Flow is already named: measurement and now the influx node is expecting this name back.

can you please tell me to pass the measurement name, in this case: Air_Volume_Flow back to msg.measurement?

thanks!

let arr = msg.payload.split(",")

let device = arr[0]
let measurement = arr[1]
let value = parseFloat(arr[2])

// prepare msg for influx Batch Output Node
msg.payload = [
    {
        value: value,
        
            }
];

msg.measurement = measurement;

return msg;


this does the trick, easy. thanks Unborn... really clean, short and effective code

1 Like