Splitting a msg line with Split or Function?


Okey, so, i'm very new to programming at all. I am an Amateur Astronomer with building an automated equipment station. Now i'm also trying to use node-RED and dashboard to use it for many control situations, like the wheater, controlling relays etc etc.

Okay: my question: I have a file on the computer witch contains only one line like this and will updated every 10 seconds:
2019-03-24 21:41:57.00 C K -26.4 7.6 7.6 3.0 59 0.1 54 0 0 00000 043548.90413 1 1 1 1 0 0

As you can see, the readings are separated by a space. The numbers are on fixed places, so they will not move in an other row. Now i want to separate the readings in to each value as an output, so i can put a dashboard tool to it, like a graph, gauge, charts, a temperature reading, wind speed etc etc.

I managed to use the split function and let it split on a "space", and this works, i can get every reading in separated messages in the debug folder. But how can i use the separated messages? Or should i do it in an other way

this is the code i use now:

[{"id":"67191ebb.438f9","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"3fc0f848.0f0178","type":"inject","z":"67191ebb.438f9","name":"","topic":"test","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":147,"y":98,"wires":[["ba790031.6b9f1"]]},{"id":"a181722c.fefd4","type":"debug","z":"67191ebb.438f9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1057,"y":125,"wires":},{"id":"ba790031.6b9f1","type":"file in","z":"67191ebb.438f9","name":"","filename":"/home/pi/Documents/test","format":"lines","chunk":false,"sendError":false,"encoding":"none","x":515,"y":99,"wires":[["b005500c.28398"]]},{"id":"b005500c.28398","type":"split","z":"67191ebb.438f9","name":"","splt":" ","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":773,"y":106,"wires":[["a181722c.fefd4"]]}]

Any help is welcome. Thank you.

If you put a join node after the split node set to array you will have an array of individual values so you can reference them by index.

[{"id":"6e423ebd.a6bbc","type":"inject","z":"1d66267b.4c5caa","name":"","topic":"","payload":"2019-03-24 21:41:57.00 C K -26.4 7.6 7.6 3.0 59 0.1 54 0 0 00000 043548.90413 1 1 1 1 0 0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":60,"wires":[["cb42b469.b403d8"]]},{"id":"cb42b469.b403d8","type":"split","z":"1d66267b.4c5caa","name":"","splt":" ","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":270,"y":100,"wires":[["b8dc29d2.24faf8"]]},{"id":"623e7c19.713154","type":"debug","z":"1d66267b.4c5caa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":650,"y":160,"wires":[]},{"id":"b8dc29d2.24faf8","type":"join","z":"1d66267b.4c5caa","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":450,"y":120,"wires":[["623e7c19.713154"]]}]
1 Like

Wow, this is a great answer! Indeed what i was looking for! Now, how do i do the reference by index? :slight_smile: , As you can see, i'm no programmer at all unfortunately...

payload[0] is the date
payload[1] is the time
You get the idea?

1 Like

Also read the page in the docs about working with messages which will show you how to use tool tips in the debug to find out the correct path

1 Like

The CSV node may be a better choice in the first place. It can be set to split on space, instead of the default comma, and the "template" line lets you assign the property names to each column so the resulting object is easier to work with.... eg msg.payload.date and so on.


Was only thinking of this yesterday. :grin:

Are you going to attempt to interface with the ASCOM api? (https://ascom-standards.org/)

Maybe in the future. But like said, no programming skills, so just need to learn that first... :smile:

Reason why I asked is that if you just developed a "bridge" (node or set of nodes) between NR and ASCOM then bingo :cowboy_hat_face: You would then have access to all the ASCOM developed interfaces, as opposed to inventing what would effectively be a new "api".

Just a thought.


Thank you for your thoughts. Well , like said, i'm really no programmer at all. My equipment itself would be run through ASCOM with build software. But for learning i thought: Node-RED should not be that hard... :slight_smile:, any way.

I now use the CSV node, and indeed i get it by Col1 - 19. So then inserting a template node, and in the command line rename the payloads? right?
Can someone maybe please show me one line for instance col 1, witch is the date, how i assign a property name to it? I will also read the manuals like "ukmoose" said.

Have a nice day!

Would any participant in this conversation please, help us with this?

Best regards

@crativ2000 why are you posting on this 3 year old thread when you have not replied to my message posted 5 hours ago?