Arduino - Node-red -sensoren - data convert/split

Hello,
Arduino gives data to node-red from sensoren
1 DHT11 for temp, hum, hic (heatindex)
2 CO- sensor for CO
Arduino with connection to Node-red gives with debug as follows:
"hum 38.00% ; temp 24.00°C ; hic 23.45°C ; CO 0.00"

Problem

  1. How do i get the values as data for inputs at gauge(hum), gauge(temp), text(hic) and text(CO).
  2. Is there any demoflow for this situation?

Dick

[{"id":"c764d410.f772f8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"69a3550f.9af85c","type":"ui_gauge","z":"c764d410.f772f8","name":"Temp","group":"5d104b94.30b3b4","order":0,"width":"4","height":"4","gtype":"gage","title":"temp","label":"units","format":"{{value}} °C","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":510,"y":200,"wires":[]},{"id":"46e683e1.ec93ec","type":"ui_gauge","z":"c764d410.f772f8","name":"Humidity","group":"5d104b94.30b3b4","order":1,"width":"4","height":"4","gtype":"gage","title":"Humidity","label":"units","format":"{{value}}%","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":520,"y":160,"wires":[]},{"id":"6038b69f.9ab6c8","type":"debug","z":"c764d410.f772f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":350,"y":120,"wires":[]},{"id":"2edcf810.d6df38","type":"serial in","z":"c764d410.f772f8","name":"","serial":"a5011f00.7ef5f","x":170,"y":240,"wires":[["6038b69f.9ab6c8"]]},{"id":"a2e3c715.9753d8","type":"ui_text","z":"c764d410.f772f8","group":"5d104b94.30b3b4","order":4,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":510,"y":240,"wires":[]},{"id":"b26abe1d.892fe","type":"ui_text","z":"c764d410.f772f8","group":"5d104b94.30b3b4","order":0,"width":0,"height":0,"name":"CO in PPM","label":"Arduino Reading","format":"{{msg.payload}}","layout":"col-center","x":530,"y":280,"wires":[]},{"id":"110e121b.97886e","type":"comment","z":"c764d410.f772f8","name":"{hum 38.00% ; temp 25.00°C ; hic 24.55°C ; CO 0.00}","info":"","x":480,"y":60,"wires":[]},{"id":"bafb4dfc.d1de8","type":"function","z":"c764d410.f772f8","name":"","func":"\nreturn msg;","outputs":4,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":240,"wires":[[],[],[],[]]},{"id":"70d68060.f16e3","type":"comment","z":"c764d410.f772f8","name":"com11:9600-8N1","info":"","x":160,"y":300,"wires":[]},{"id":"63c9da8c.e7d5b4","type":"comment","z":"c764d410.f772f8","name":"how to do that?","info":"","x":360,"y":300,"wires":[]},{"id":"5d104b94.30b3b4","type":"ui_group","name":"DHT11","tab":"784aac14.5c2404","order":2,"disp":true,"width":"6","collapse":false},{"id":"a5011f00.7ef5f","type":"serial-port","serialport":"COM11","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"},{"id":"784aac14.5c2404","type":"ui_tab","name":"Station","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

hi here is an example of matching the floats in the string and snding them to different outputs. Hope it helps

[{"id":"bafb4dfc.d1de8","type":"function","z":"c764d410.f772f8","name":"","func":"let temp=[];\nmsg.payload=msg.payload.match(/[\\.\\d]+/g);\nfor(const element of msg.payload){\n    temp.push({payload: element})\n}\nreturn temp;","outputs":4,"noerr":0,"initialize":"","finalize":"","x":340,"y":240,"wires":[["6038b69f.9ab6c8","46e683e1.ec93ec"],["69a3550f.9af85c"],["a2e3c715.9753d8"],["b26abe1d.892fe"]]},{"id":"cb0d0251.ede2d","type":"inject","z":"c764d410.f772f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"hum 38.00% ; temp 25.00°C ; hic 24.55°C ; CO 0.00","payloadType":"str","x":160,"y":220,"wires":[["bafb4dfc.d1de8"]]},{"id":"6038b69f.9ab6c8","type":"debug","z":"c764d410.f772f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":350,"y":120,"wires":[]},{"id":"46e683e1.ec93ec","type":"ui_gauge","z":"c764d410.f772f8","name":"Humidity","group":"5d104b94.30b3b4","order":1,"width":"4","height":"4","gtype":"gage","title":"Humidity","label":"units","format":"{{value}}%","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":520,"y":160,"wires":[]},{"id":"69a3550f.9af85c","type":"ui_gauge","z":"c764d410.f772f8","name":"Temp","group":"5d104b94.30b3b4","order":0,"width":"4","height":"4","gtype":"gage","title":"temp","label":"units","format":"{{value}} °C","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":510,"y":200,"wires":[]},{"id":"a2e3c715.9753d8","type":"ui_text","z":"c764d410.f772f8","group":"5d104b94.30b3b4","order":4,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":510,"y":240,"wires":[]},{"id":"b26abe1d.892fe","type":"ui_text","z":"c764d410.f772f8","group":"5d104b94.30b3b4","order":0,"width":0,"height":0,"name":"CO in PPM","label":"Arduino Reading","format":"{{msg.payload}}","layout":"col-center","x":530,"y":280,"wires":[]},{"id":"5d104b94.30b3b4","type":"ui_group","name":"DHT11","tab":"784aac14.5c2404","order":2,"disp":true,"width":"6","collapse":false},{"id":"784aac14.5c2404","type":"ui_tab","name":"Station","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
1 Like

Alternatively, if you instead modify the Arduino code to provide the data as JSON, so a string something like:
{"hum": 38.00, "temp": 24.00, "hic": 23.45, "CO": 0.00}
then you can feed that into a JSON node and it will convert it to a javascript object. Then you can feed that directly into the gauges and in the value format field put, for example, {{msg.payload.hum}} to display the humidity.

Thanks E1cid,

This item does it once

Then I become the error

This is not “iterable"

Is there a solution?

Dick

Verzonden vanuit Mail voor Windows

Thanks Colin,

But the problem for that is when iuse the function Json

Then i see : this is not a Json and it stops

Dick

Verzonden vanuit Mail voor Windows

Is this with the Arduino code modified to send JSON? You cannot feed the data as you currently have it into a JSON node because it is not currently valid JSON. That is why you have to modify the Arduino code to use this technique.

can you supply an exact copy of the string coming from the Arduino node, add a debug node and copy the value using the copy value button ( this appears when you hover mouse ove the payload object in the deug pane)

I give a copy

Arduino com

Msg payload

Msg

Dick

Verzonden vanuit Mail voor Windows

debug1.jpg

That is not what i asked for, i did not ask for a screenshot. I asked you to copy the value. I can not copy the value from an image.

Looking at the image I see no issue is there another wire in your flow, or does the payload change at all. run the flow again and monitor the debug node to see if any other payload appears. May be post your flow to as the issue may be coming from another node.

Is this what you mean?

Dick

Verzonden vanuit Mail voor Windows

No,
Export you flow selecting all nodes (press ctrl and select with mouse) Then pres ctrl e and copy to clipboard and past here as you did before

I see no errors in your image and you have not connected the com11 node to my function.

No one can help if you fail to give any vital/usable info.
You still have not supplied a copy of the string request several posts ago.

↑ That value is not valid JSON ↑

If (like Colin said) you simply update your Arduino code to output valid JSON there would be NO requirement to mess around with splitting strings or regex or anything else.

So instead of sending that non standard string, send

{ 
  "hum": 38.0,
  "temp": 24.0,
  "CO": 0.0
}

and then pass the serial data through a JSON node you will be able to access the values like this..

  • msg.payload.temp
  • msg.payload.hum
  • msg.payload.CO

and be able to use them directly.

SERIAL NODE --> JSON NODE --> Dashboard node (or whatever)

3 nodes - done!

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