DHT11 flow problem

I have the following flow where I am receiving DHT11 data from serial port. I build a function to split the incoming data and output the humidity and temperature data on two outputs but I am not able to do. Looks like the first output or payload is ok but not the other. Following is the function code and the flow diagram.
Arduino sends eg from serial monitor : 70.00,23.00
data split function:

m = msg.payload.split(',');
H = {payload:m[0]};
T = {payload:m[1]};

return [H,T];

flow diagram:

So how can I solve this?
thank you all

You need to return a msg not just the value, try this

m = msg.payload.split(',');
msg.H = {payload:m[0]};
msg.T = {payload:m[1]};

return msg;

change thefunction node to have one output, connect that one output to two change nodes. Connect the change nodes, each to one the two gauges. In the change node going to the temperature gauge, set msg.payload to msg.T and do the equilivant in the second change node.

You need to trim the whitespace off the items. as there is a newline.
e.g.

[{"id":"ac7cd00f.633df8","type":"inject","z":"9da7dd49afa1d6a5","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":100,"wires":[["8b9a252a.d2ab18"]]},{"id":"8b9a252a.d2ab18","type":"template","z":"9da7dd49afa1d6a5","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"24.00,23.00\n","output":"str","x":280,"y":100,"wires":[["12d3adf.e975e52"]]},{"id":"12d3adf.e975e52","type":"function","z":"9da7dd49afa1d6a5","name":"","func":"m = msg.payload.split(',');\nH = {payload:m[0].trim()};\nT = {payload:m[1].trim()};\n\nreturn [H,T];","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":80,"wires":[["c0568744.a2dcb8"],["c3f1d5fed9ba2bc8"]]},{"id":"c0568744.a2dcb8","type":"debug","z":"9da7dd49afa1d6a5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":790,"y":80,"wires":[]},{"id":"c3f1d5fed9ba2bc8","type":"debug","z":"9da7dd49afa1d6a5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":220,"wires":[]}]
const m = msg.payload.split(',');
const H = {payload:m[0].trim()};
const T = {payload:m[1].trim()};

return [H,T];

You could also parse the floats .

const T = {payload:parseFloat(m[1])};

p.s. you also need to start declaring variables.

@zenofmud you are mistaken H and T are msg objects.

1 Like

Oops, @E1cid you are right! I should have read it more carefully :grimacing:

1 Like

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