Hi. I wrote a function to compare temperature values. This function was connected to a trigger, and trigger was connected to a button. I learned that this part must be running at all times, without the button press. So, I put a timestamp before it. Now, I sometimes read values like these:
{ payload: 1595856943673, topic: "", _msgid: "661b8566.10c17c" }
7/27/2020, 4:35:47 PMnode: 7be3371.28d15c8
msg : Object
{ payload: 29, topic: "", _msgid: "8dfcb019.41d8a" }
7/27/2020, 4:35:51 PMnode: 7be3371.28d15c8
msg : Object
{ payload: 29, topic: "",
Now, it kept repeating reading that huge value for 10+ times. This is making the system use PID in a wrong way. How can I solve this? Should I just add a if statement where the value is below 50 or something, or is there a better way to run something all the time without any interaction from the user?
Here is the inject node in timestamp mode, and the function I wrote:
[{"id":"f27ba700.882368","type":"inject","z":"4cdd06f6.faf528","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"4","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":490,"y":380,"wires":[["ed704f4c.f27a5"]]},{"id":"ed704f4c.f27a5","type":"function","z":"4cdd06f6.faf528","name":"","func":"var k1 = global.get('k1');\nvar k2 = global.get('k2');\nvar k3 = global.get('k3');\n\nif(k1>k2 && k1>k3)\n{\n msg.payload = k1;\n}\nif(k2>k1 && k2>k3)\n{\n msg.payload = k2;\n}\nif(k3>k1 && k3>k2)\n{\n msg.payload = k3;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":660,"y":380,"wires":[["e5102467.06b418","7be3371.28d15c8"]]}]
Those k1, k2, k3 values are from temperature sensors.