# Write data frome sensor in file

**URL:** <https://discourse.nodered.org/t/write-data-frome-sensor-in-file/49998>\
**Category:** General\
**Created:** [21 August 2021 22:38 UTC](https://discourse.nodered.org/t/write-data-frome-sensor-in-file/49998 "2021-08-21T22:38:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![abdosml](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@abdosml](https://discourse.nodered.org/u/abdosml)\
**Post date:** [21 August 2021 22:38 UTC](https://discourse.nodered.org/t/write-data-frome-sensor-in-file/49998/1 "2021-08-21T22:38:40Z")

</div>

im begineer with node red ,iwant to write like a small report with this content the maximum and minimum of tempurature and humidity but i found this proble when i debug 1 time the value of max and minimu tme was undefined andthe valu of ax min hum was exist , after that the dubag show the humidioty is undefin and the tempurature had some value ,

this image sow the probleme i had

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d37762fee546e940d3cfbe0b2467b7fcb4a8bac2.png)

i want after that this message to be write in file and i can download theme from the dashbord

---

<div class="post-metadata">

**Author:** ![abdosml](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@abdosml](https://discourse.nodered.org/u/abdosml)\
**Post date:** [21 August 2021 22:39 UTC](https://discourse.nodered.org/t/write-data-frome-sensor-in-file/49998/2 "2021-08-21T22:39:59Z")

</div>

```auto
[{"id":"3132a3bf41b5720f","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"5b52ddbd9e57fa84","type":"mqtt in","z":"3132a3bf41b5720f","name":"","topic":"esp/dht/temperature","qos":"1","datatype":"auto","broker":"8db3fac0.99dd48","nl":false,"rap":false,"x":270,"y":180,"wires":[["ea4a205ba4456db4"]]},{"id":"ea4a205ba4456db4","type":"function","z":"3132a3bf41b5720f","name":"","func":"m = parseFloat(msg.payload)\n\nmin = flow.get(\"min\") || 6 // minimum value \nmax = flow.get(\"max\") || 7 // maximum value \n\nif(m<min && m <=max){\n flow.set(\"min\",m)\n min = flow.get(\"min\")\n}\nif(m>max){\n \n flow.set(\"max\",m)\n max = flow.get(\"max\")\n \n}\n\n\nreturn {payload:{min:min,max:max}};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":100,"wires":[["9d354bfc05ee4a33"]]},{"id":"8e58ee268c33b682","type":"function","z":"3132a3bf41b5720f","name":"","func":"mh = parseFloat(msg.payload)\nminh = flow.get(\"minh\") || 20 // minimum value \nmaxh = flow.get(\"maxh\") || 7 // maximum value \n\nif(mh<minh && mh <=maxh){\n flow.set(\"minh\",mh)\n minh = flow.get(\"minh\")\n}\nif(mh>maxh){\n \n flow.set(\"maxh\",mh)\n maxh = flow.get(\"maxh\")\n \n}\n\n\nreturn {payload:{minh:minh,maxh:maxh}};","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":320,"wires":[["9d354bfc05ee4a33"]]},{"id":"3d121c8b56e12614","type":"mqtt in","z":"3132a3bf41b5720f","name":"","topic":"esp/dht/humidity","qos":"1","datatype":"auto","broker":"8db3fac0.99dd48","x":260,"y":400,"wires":[["8e58ee268c33b682"]]},{"id":"9d354bfc05ee4a33","type":"function","z":"3132a3bf41b5720f","name":"function ","func":"\n titel=\"a brief report of this mission:\";\n string1=\"-the minimum tempurature it was:\"\n tempurature_min= msg.payload.min;\n string2=\",the maximum tempurature it was:\"\n tempurature_max=msg.payload.max;\n string3=\",the minimum humidity it was:\"\n humidity_min=msg.payload.minh;\n string4=\",the maximum humidity it was:\"\n humidity_max=msg.payload.maxh;\nmsg.payload=titel+string1+tempurature_min+string2+tempurature_max+string3+humidity_min+string4+humidity_max;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":860,"wires":[["14b7fd13ebdd8a5c"]]},{"id":"14b7fd13ebdd8a5c","type":"debug","z":"3132a3bf41b5720f","name":"do_Something","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1000,"y":960,"wires":[]},{"id":"8db3fac0.99dd48","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<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:** [21 August 2021 22:49 UTC](https://discourse.nodered.org/t/write-data-frome-sensor-in-file/49998/3 "2021-08-21T22:49:41Z")

</div>

Put a `debug` Node (set to display the complete msg object) on the output of the mqtt nodes and show us what it displats

---

<div class="post-metadata">

**Author:** ![abdosml](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@abdosml](https://discourse.nodered.org/u/abdosml)\
**Post date:** [21 August 2021 22:52 UTC](https://discourse.nodered.org/t/write-data-frome-sensor-in-file/49998/4 "2021-08-21T22:52:53Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/a/2a1917766a28314953e16c023a509a19a60c815c.png)

---

<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:** [21 August 2021 22:59 UTC](https://discourse.nodered.org/t/write-data-frome-sensor-in-file/49998/5 "2021-08-21T22:59:13Z")

</div>

In the first flow you display, the last ` function` node is trying to get data from the other two ` function` nodes but the data will never arrive at the same time. To do that, you would need to use a `join` node to combine the two msgs into one msg. Then the ` function` node will have access to both the temperature and humidity values.

---

<div class="post-metadata">

**Author:** ![abdosml](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@abdosml](https://discourse.nodered.org/u/abdosml)\
**Post date:** [21 August 2021 23:06 UTC](https://discourse.nodered.org/t/write-data-frome-sensor-in-file/49998/6 "2021-08-21T23:06:08Z")

</div>

i try it now but i had this error :  
Message missing key property 'msg.topic' - cannot add to object

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/4/7459540add77bbdeec40b8b69c2031d55728db89.png)

---

<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:** [22 August 2021 00:31 UTC](https://discourse.nodered.org/t/write-data-frome-sensor-in-file/49998/7 "2021-08-22T00:31:55Z")

</div>

Where are you trying to do the join?  
It looks like you want to join 3 msgs. What are the three msgs?  
What is the toipc of each of the three messages,

Take a look at this entry in the CookBook which might help you understand how to do a join:  
[Create a single message from separate streams of messages : Node-RED](https://cookbook.nodered.org/basic/join-streams)

---

<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:** [21 October 2021 00:32 UTC](https://discourse.nodered.org/t/write-data-frome-sensor-in-file/49998/8 "2021-10-21T00:32:53Z")

</div>

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