Srijan
4 September 2018 05:40
1
hello everyone
i m very much confused how to split the string into saparate values .
as i have 4 values in a string
temperature
2.humidity
3.pir
ldr
but the values are in the form of string and i want to saparate it into
temperature
humidity
pir
ldr
how can i do it .
plzz help
In the last screenshot you posted the debug panel shows every message as a string of comma separated values, NOT an array.
So do you want to convert an array or split the string into separate values?
You also posted this in a category for creating nodes, for general how-to question in existing nodes please use a more appropriate category.
Hopefully on of the super-users can move it…
Srijan
4 September 2018 06:01
3
split the string into separate values
If you want them as separate messages take a look at the split
node
Srijan
4 September 2018 07:05
5
i have used some codes
can u tell me that these codes will work for me or not??
Values in your string are comma separated. So splitting has to be done with separator comma.
var output = msg.payload.split(",");
1 Like
Srijan
4 September 2018 07:18
7
still i am not getting what i wanted
the string had not changed to saparate values as:
temperature
humidity
pir
ldr
First element of array has index 0 (zero)
You probably get an error now as you are looking last element from index 4, but it appears to be out of range.
Srijan
4 September 2018 07:26
9
this is the error what i m facing
can u give me the complete code i am a bit confused in my code
You are returning the numbers [temp,humidity.....]
You should return those objects you a created [msg1,msg2, ....]
having created the msgs you need to return them not temp etc
so
return [ msg1, msg2, msg3, msg4 ];
Srijan
4 September 2018 07:32
12
but i want
temperature
humidity
pir
ldr
to be displayed saparately. not in a string
Srijan
4 September 2018 07:33
13
[quote="Srijan, post:12, topic:2818"]
but i want
temperature
humidity
pir
ldr
to be displayed saparately. not in a string
where are your debug nodes attached ? - looks like you are only showing us the one on the input - not 4 on the outputs of your function...
Is your debug is still attached to your MQTT node?
Take a look at the outputs from your function node.
Srijan
4 September 2018 08:10
17
yes my debug is still attach to mqtt node
Srijan
4 September 2018 08:14
18
i am new to node red
plzz help me
So your debug will only ever show the MQTT message. You need to look at the outputs of your function node.