Hi, This is second time im using node-red so im still a rookie
Im having trouble getting my function to work. Need to sends out a 1 or 0 in debug node.
Im using rasberry pi 4b with PIR and ultra sonic sensor. I want to make a AND function:
if their is movement and sonic sensor is in a certain range the function will send a 1 else its a 0
im getting errors: "Cannot set property of non-object type: payload.uss,
same with payload.pir
Do I need to use a join node before a function or is their a better or smarter way?
-ultra sonic sensor sends a string (xxx in cm)and I change that to number
-pir sensor sends in numberic 1 or 0
Here is my code:
[{"id":"3111490beaa533a8","type":"tab","label":"Flow 3","disabled":true,"info":"","env":[]},{"id":"5866be3c574cc7ff","type":"rpi-gpio in","z":"3111490beaa533a8","name":"PIR_Sensor_GPIO26","pin":"26","intype":"tri","debounce":"25","read":false,"bcm":true,"x":200,"y":200,"wires":[["09c2e1dc101cfde2"]]},{"id":"181ad8db249dc7ac","type":"rpi-srf","z":"3111490beaa533a8","name":"","topic":"SRF","pulse":"2","pins":"38,40","precision":"0","x":150,"y":100,"wires":[["f0b6656bb04a1599"]]},{"id":"ed7471ed04b0e870","type":"change","z":"3111490beaa533a8","name":"","rules":[{"t":"set","p":"payload.uss","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":80,"wires":[["e6ab834867e6bbcb"]]},{"id":"09c2e1dc101cfde2","type":"change","z":"3111490beaa533a8","name":"","rules":[{"t":"set","p":"payload.pir","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":200,"wires":[["e6ab834867e6bbcb"]]},{"id":"e6ab834867e6bbcb","type":"function","z":"3111490beaa533a8","name":"","func":"//detection and correct distance\nif(msg.payload.pir === 1 & msg.payload.uss === 1) \n{\n msg.payload=1;\n}\n\n//No detection and wrong distance\nelse \n{\n msg.payload=0;\n}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1040,"y":80,"wires":[["a354b46e67748d63"]]},{"id":"a354b46e67748d63","type":"debug","z":"3111490beaa533a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1210,"y":80,"wires":[]},{"id":"f0b6656bb04a1599","type":"switch","z":"3111490beaa533a8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"15","vt":"str","v2":"20","v2t":"str"},{"t":"gt","v":"15","vt":"str"},{"t":"lt","v":"20","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":370,"y":80,"wires":[["2e398ab9a7348453"],["91f2c51ed301826b"],["d6009968df9dfc81"]]},{"id":"2e398ab9a7348453","type":"change","z":"3111490beaa533a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":60,"wires":[["ed7471ed04b0e870"]]},{"id":"91f2c51ed301826b","type":"change","z":"3111490beaa533a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":100,"wires":[["ed7471ed04b0e870"]]},{"id":"d6009968df9dfc81","type":"change","z":"3111490beaa533a8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":140,"wires":[["ed7471ed04b0e870"]]}]