Write data frome sensor in file

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

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

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

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

1 Like

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.

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

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

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