# DHT11 flow problem

**URL:** <https://discourse.nodered.org/t/dht11-flow-problem/65157>\
**Category:** General\
**Created:** [15 July 2022 17:40 UTC](https://discourse.nodered.org/t/dht11-flow-problem/65157 "2022-07-15T17:40:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mynodered](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mynodered](https://discourse.nodered.org/u/mynodered)\
**Post date:** [15 July 2022 17:40 UTC](https://discourse.nodered.org/t/dht11-flow-problem/65157/1 "2022-07-15T17:40:41Z")

</div>

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:

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

return [H,T];

```

flow diagram:

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/8/6843c944f9373b161fa8eb076307183a5b0a8bbf.jpeg)

So how can I solve this?  
thank you all

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [15 July 2022 17:56 UTC](https://discourse.nodered.org/t/dht11-flow-problem/65157/2 "2022-07-15T17:56:04Z")

</div>

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

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

return msg;

```

change the`function` 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.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [15 July 2022 18:02 UTC](https://discourse.nodered.org/t/dht11-flow-problem/65157/3 "2022-07-15T18:02:15Z")

</div>

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

```auto
[{"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":[]}]

```

```auto
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 .

```auto
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.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [15 July 2022 18:11 UTC](https://discourse.nodered.org/t/dht11-flow-problem/65157/4 "2022-07-15T18:11:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 July 2022 18:11 UTC](https://discourse.nodered.org/t/dht11-flow-problem/65157/5 "2022-07-29T18:11:57Z")

</div>

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