Trouble splitting serial in data (Strings)

Hello all

I am new to node red and can't seem to find a fix for my issue.

Node red is being run on my pi 3 model b that is connected to ardunio uno via usb serial link. I am able to get the data from the serial.print from the ardunio to show in node red using the serial in node.

Connected to Ardunio UNO:

1x Temperature sensor

1x water flow sensor

1X RTC (Not updated with correct time yet)

1x PH sensor ( ignore this one for now )

For reference please see below:

image

** connecting debug node to Serial in log**

What I am trying to do is display the readings (values) coming in from the serial in onto separate dashboard gauges.

The advice I find online says to use a switch to filter the strings However on the debug log for the outputs on the switch I either get no readings or the same reading as the serial in

For reference below

image

As you can see from the screen shoot above the readings are the same as the serial in and pulse though all the readings shown in the debug at the top of the post.

Any advice will be appreciated to get this working

Thanks for reading

Example flow:

[{"id":"eb87884f.3f892","type":"inject","z":"a5ad0b9b.9014e","name":"temperature","topic":"","payload":"Temperature for the device 1 (index 0) is: 23.37","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":275,"wires":[["e5874145.01e688"]]},{"id":"2d8b4350.3a4ad4","type":"debug","z":"a5ad0b9b.9014e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":595,"y":350,"wires":[]},{"id":"e5874145.01e688","type":"change","z":"a5ad0b9b.9014e","name":"Extract number","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number($trim($split(payload,':')[1]))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":405,"y":325,"wires":[["2d8b4350.3a4ad4"]]},{"id":"1617f1c5.a780c6","type":"inject","z":"a5ad0b9b.9014e","name":"","topic":"","payload":"L/hour: 0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":325,"wires":[["e5874145.01e688"]]},{"id":"ae8fb725.bc1028","type":"change","z":"a5ad0b9b.9014e","name":"Extract string","rules":[{"t":"set","p":"payload","pt":"msg","to":"$trim($split(payload,':')[1])","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":395,"y":375,"wires":[["2d8b4350.3a4ad4"]]},{"id":"b05f4b05.164b2","type":"inject","z":"a5ad0b9b.9014e","name":"Date","topic":"","payload":"Date: 19.05.2000","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":375,"wires":[["ae8fb725.bc1028"]]},{"id":"e2b1111a.33e82","type":"inject","z":"a5ad0b9b.9014e","name":"time","topic":"","payload":"Time: 14:50:06","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":425,"wires":[["ae8fb725.bc1028"]]}]

A suggestion.
Construct JSON strings in the Arduino then send that to node red.

Then it's a simple case of using the JSON node to convert your string data to useable object.

No need to split your data whatsoever.

You could also include a topic on the JSON string to simplify routing MSG's through the switch node.

Thank you for the reply

So the example flow looks like this

image

Question:
How does the data from the serial link get into this flow ?

Sorry I am new

Like this.

[{"id":"eb87884f.3f892","type":"inject","z":"a5ad0b9b.9014e","name":"temperature","topic":"","payload":"Temperature for the device 1 (index 0) is: 23.37","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":275,"wires":[["79bab735.7e7aa8"]]},{"id":"2d8b4350.3a4ad4","type":"debug","z":"a5ad0b9b.9014e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":350,"wires":[]},{"id":"1617f1c5.a780c6","type":"inject","z":"a5ad0b9b.9014e","name":"","topic":"","payload":"L/hour: 0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":325,"wires":[["79bab735.7e7aa8"]]},{"id":"b05f4b05.164b2","type":"inject","z":"a5ad0b9b.9014e","name":"Date","topic":"","payload":"Date: 19.05.2000","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":375,"wires":[["79bab735.7e7aa8"]]},{"id":"e2b1111a.33e82","type":"inject","z":"a5ad0b9b.9014e","name":"time","topic":"","payload":"Time: 14:50:06","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":425,"wires":[["79bab735.7e7aa8"]]},{"id":"79bab735.7e7aa8","type":"function","z":"a5ad0b9b.9014e","name":"","func":"i = msg.payload\n\ns = i.split(':')\no = s[1].trim()\n\nif(!isNaN(o) && s[0]!= 'Date' && s[0]!='Time'){\n return {payload:Number(o)};   \n}\n","outputs":1,"noerr":0,"x":475,"y":350,"wires":[["2d8b4350.3a4ad4"]]}]

But like @Steve-Mcl mentioned, why sending text from arduino, create a json object instead.

Thanks

Sorry @Steve-Mcl your reply didn't show until I refreshed the page

I will give the JSON strings in the Arduino ago now

1 Like