Hi,
i would like to push data from one payload into a file only if an other payload from an other sensor is present or changes. How is this possible? I need something like an if clause i think but don't realy know how.
Please help me out.
Take a look at the cookbook there’s an example that should give you the structure you probably need
Thanks for your quick reply. I think the switch node isn't that what I'm looking for. I've tried it but doen't work.
I'm building a device to check binary in- and outputs of devices.
My problem is that I have two payloads which I want to log in a file. The first one is a voltage which is increased by 0,01 Volt per second. The second one is a temperature from a ptd sensor. This sensor changes the value much faster. Thats why the logfile for temerature has much more entries. At the end I want to know the voltagelevel and the current ambient temperature when the binary output of the device has become true.
So thats why I'm looking for a function which pushes the values i want to a log file only if one of 8 inputs a true. Is there someting like that in node red? Maybe i didn't get the function of switch right?
Thanks for your help
I am confused. You say you have two payloads. Are they available in one message or are they in separate messages?
Also you then go on to talk about one of 8 inputs being true. What are these 8 inputs?
These inputs are from a Siemens Logo. If one of them is true I want to log the input itself, the current voltagelevel and the ambient temperature.
Somehow I want to implement that in a flow like that. Here you can see the two payloads i mean. The first msg.payload.Spannung and the msg.payload.Temperature. i hope i could somehow clarify what i mean.
[{"id":"f5a842ed.940dc","type":"tab","label":"Flow 1"},{"id":"77edeaa3.1e5674","type":"s7 in","z":"f5a842ed.940dc","endpoint":"83e511e7.543f6","mode":"all","variable":"","diff":true,"name":"LOGO 8 Spannung","x":156,"y":174,"wires":[["d788fb57.9dee68","a9f3fe36.30893","77e67b70.716d24"]]},{"id":"d788fb57.9dee68","type":"debug","z":"f5a842ed.940dc","name":"","active":true,"console":"false","complete":"payload","x":531,"y":113,"wires":[ ]},{"id":"264f3a2a.a76656","type":"ui_gauge","z":"f5a842ed.940dc","name":"Spannung","group":"b5632bd2.d6b6e8","order":0,"width":0,"height":0,"gtype":"gage","title":"Spannung","label":"Volt","format":"{{value}}","min":0,"max":"20","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":634,"y":410,"wires":[ ]},{"id":"a5b27871.1a8a58","type":"debug","z":"f5a842ed.940dc","name":"","active":false,"console":"false","complete":"false","x":836,"y":110,"wires":[]},{"id":"a9f3fe36.30893","type":"function","z":"f5a842ed.940dc","name":"Spannung extrahieren","func":"\nreturn {payload: msg.payload.Spannung/100};","outputs":1,"noerr":0,"x":562,"y":172,"wires":[["a5b27871.1a8a58","9e5ae95b.6fbf88"]]},{"id":"6f455a2a.96dda4","type":"mqtt out","z":"f5a842ed.940dc","name":"","topic":"/Dashboard/Temperatur","qos":"","retain":"","broker":"407973b6.64beac","x":876,"y":234,"wires":[]},{"id":"77e67b70.716d24","type":"function","z":"f5a842ed.940dc","name":"Temperatur extrahieren","func":"\nreturn {payload : msg.payload.Temperatur/100};","outputs":1,"noerr":0,"x":552,"y":234,"wires":[["6f455a2a.96dda4"]]},{"id":"f3c5530f.0f298","type":"mqtt in","z":"f5a842ed.940dc","name":"","topic":"/Dashboard/Temperatur","qos":"2","broker":"407973b6.64beac","x":228,"y":471,"wires":[["4c88c349.9611dc"]]},{"id":"4c88c349.9611dc","type":"ui_gauge","z":"f5a842ed.940dc","name":"","group":"b5632bd2.d6b6e8","order":0,"width":0,"height":0,"gtype":"gage","title":"Temperatur Prüfling","label":"°C","format":"{{value}}","min":0,"max":"75","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":654,"y":470,"wires":[]},{"id":"9e5ae95b.6fbf88","type":"mqtt out","z":"f5a842ed.940dc","name":"","topic":"/Dashboard/Spannung","qos":"","retain":"","broker":"407973b6.64beac","x":866,"y":172,"wires":[]},{"id":"300723b8.36831c","type":"mqtt in","z":"f5a842ed.940dc","name":"","topic":"/Dashboard/Spannung","qos":"2","broker":"407973b6.64beac","x":230,"y":411,"wires":[["264f3a2a.a76656"]]},{"id":"83e511e7.543f6","type":"s7 endpoint","z":"","transport":"iso-on-tcp","address":"192.168.0.2","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapterauto":true,"adapterport":"","busaddr":"2","adapteraddr":"0","cycletime":"100","timeout":"1500","verbose":"on","name":"","vartable":[{"addr":"DB1,INT14","name":"Spannung"},{"addr":"DB1,INT28","name":"Temperatur"}]},{"id":"b5632bd2.d6b6e8","type":"ui_group","z":"","name":"Prüfparameter","tab":"9640e102.0cba1","order":null,"disp":true,"width":"6"},{"id":"407973b6.64beac","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"9640e102.0cba1","type":"ui_tab","name":"Tab","icon":"dashboard","order":0}]
Please export your flow again and follow this topic.
Oh I'm sorry. I'm new to that forum. It's very nice programmed btw. very overseeable. I like it.
[{"id":"f5a842ed.940dc","type":"tab","label":"Flow 1"},{"id":"77edeaa3.1e5674","type":"s7 in","z":"f5a842ed.940dc","endpoint":"83e511e7.543f6","mode":"all","variable":"","diff":true,"name":"LOGO 8 Spannung","x":156,"y":174,"wires":[["d788fb57.9dee68","a9f3fe36.30893","77e67b70.716d24"]]},{"id":"d788fb57.9dee68","type":"debug","z":"f5a842ed.940dc","name":"","active":true,"console":"false","complete":"payload","x":531,"y":113,"wires":[]},{"id":"264f3a2a.a76656","type":"ui_gauge","z":"f5a842ed.940dc","name":"Spannung","group":"b5632bd2.d6b6e8","order":0,"width":0,"height":0,"gtype":"gage","title":"Spannung","label":"Volt","format":"{{value}}","min":0,"max":"20","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":634,"y":410,"wires":[]},{"id":"a5b27871.1a8a58","type":"debug","z":"f5a842ed.940dc","name":"","active":false,"console":"false","complete":"false","x":836,"y":110,"wires":[]},{"id":"a9f3fe36.30893","type":"function","z":"f5a842ed.940dc","name":"Spannung extrahieren","func":"\nreturn {payload: msg.payload.Spannung/100};","outputs":1,"noerr":0,"x":562,"y":172,"wires":[["a5b27871.1a8a58","9e5ae95b.6fbf88"]]},{"id":"6f455a2a.96dda4","type":"mqtt out","z":"f5a842ed.940dc","name":"","topic":"/Dashboard/Temperatur","qos":"","retain":"","broker":"407973b6.64beac","x":876,"y":234,"wires":[]},{"id":"77e67b70.716d24","type":"function","z":"f5a842ed.940dc","name":"Temperatur extrahieren","func":"\nreturn {payload : msg.payload.Temperatur/100};","outputs":1,"noerr":0,"x":552,"y":234,"wires":[["6f455a2a.96dda4"]]},{"id":"f3c5530f.0f298","type":"mqtt in","z":"f5a842ed.940dc","name":"","topic":"/Dashboard/Temperatur","qos":"2","broker":"407973b6.64beac","x":228,"y":471,"wires":[["4c88c349.9611dc"]]},{"id":"4c88c349.9611dc","type":"ui_gauge","z":"f5a842ed.940dc","name":"","group":"b5632bd2.d6b6e8","order":0,"width":0,"height":0,"gtype":"gage","title":"Temperatur Prüfling","label":"°C","format":"{{value}}","min":0,"max":"75","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":654,"y":470,"wires":[]},{"id":"9e5ae95b.6fbf88","type":"mqtt out","z":"f5a842ed.940dc","name":"","topic":"/Dashboard/Spannung","qos":"","retain":"","broker":"407973b6.64beac","x":866,"y":172,"wires":[]},{"id":"300723b8.36831c","type":"mqtt in","z":"f5a842ed.940dc","name":"","topic":"/Dashboard/Spannung","qos":"2","broker":"407973b6.64beac","x":230,"y":411,"wires":[["264f3a2a.a76656"]]},{"id":"83e511e7.543f6","type":"s7 endpoint","z":"","transport":"iso-on-tcp","address":"192.168.0.2","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapterauto":true,"adapterport":"","busaddr":"2","adapteraddr":"0","cycletime":"100","timeout":"1500","verbose":"on","name":"","vartable":[{"addr":"DB1,INT14","name":"Spannung"},{"addr":"DB1,INT28","name":"Temperatur"}]},{"id":"b5632bd2.d6b6e8","type":"ui_group","z":"","name":"Prüfparameter","tab":"9640e102.0cba1","order":null,"disp":true,"width":"6"},{"id":"407973b6.64beac","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"9640e102.0cba1","type":"ui_tab","name":"Tab","icon":"dashboard","order":0}]
The inputs from the logo are missing until now. I wanted to understand the logging logic first.
You can combine them using the batch and join node.
[{"id":"8d4e610b.6f9a6","type":"change","z":"acbc2c98.94ee28","name":"spannung","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.Spannung/100","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"spannung","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":536,"y":504,"wires":[["100b0223.fac936"]]},{"id":"6009b252.eb73fc","type":"inject","z":"acbc2c98.94ee28","name":"","topic":"","payload":"{\"Spannung\":150}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":314,"y":504,"wires":[["8d4e610b.6f9a6"]]},{"id":"2e6381a1.ca11f6","type":"debug","z":"acbc2c98.94ee28","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":974,"y":476,"wires":[]},{"id":"cf6f113d.fffc5","type":"change","z":"acbc2c98.94ee28","name":"temperatur","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.Temperatur/100","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"temperatur","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":518,"y":448,"wires":[["100b0223.fac936"]]},{"id":"580fe985.7c2818","type":"inject","z":"acbc2c98.94ee28","name":"","topic":"","payload":"{\"Temperatur\":240}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":314,"y":448,"wires":[["cf6f113d.fffc5"]]},{"id":"100b0223.fac936","type":"batch","z":"acbc2c98.94ee28","name":"","mode":"count","count":"2","overlap":0,"interval":10,"allowEmptySequence":false,"topics":[{"topic":"spannung"},{"topic":"temperatur"}],"x":694,"y":476,"wires":[["4f3c3779.af505"]]},{"id":"4f3c3779.af505","type":"join","z":"acbc2c98.94ee28","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":834,"y":476,"wires":[["2e6381a1.ca11f6"]]}]
You can remove the msg.topic from the change nodes as you already get them from mqtt.
Instead you also rate limit (using a delay node) the temperature sensor and match it with the voltage sensor.
If I understand well: you want to log "spannung" and "temperatur" when a binary input goes to "true", am I right ?
Then you just have to implement a rising edge detection using flow context. Rising edge means the binary input goes from "false" to "true".
[{"id":"7bf4a3cf.84abbc","type":"s7 in","z":"134c75d0.b495aa","endpoint":"dab05dae.3a5cf","mode":"all","variable":"","diff":true,"name":"LOGO 8 Spannung","x":156,"y":174,"wires":[["b8bd09f.df308f8","aeeb03d3.57c5"]]},{"id":"b8bd09f.df308f8","type":"debug","z":"134c75d0.b495aa","name":"","active":true,"console":"false","complete":"payload","x":531,"y":113,"wires":[]},{"id":"58efa451.c8eecc","type":"ui_gauge","z":"134c75d0.b495aa","name":"Spannung","group":"1e3853b5.df4fdc","order":0,"width":0,"height":0,"gtype":"gage","title":"Spannung","label":"Volt","format":"{{value}}","min":0,"max":"20","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":634,"y":410,"wires":[]},{"id":"5cfc421f.d3429c","type":"debug","z":"134c75d0.b495aa","name":"","active":false,"console":"false","complete":"false","x":1130,"y":120,"wires":[]},{"id":"b04b43bc.77b29","type":"mqtt out","z":"134c75d0.b495aa","name":"","topic":"/Dashboard/Temperatur","qos":"","retain":"","broker":"a37eb2d0.4a3e7","x":1170,"y":244,"wires":[]},{"id":"88315bf5.19b638","type":"mqtt in","z":"134c75d0.b495aa","name":"","topic":"/Dashboard/Temperatur","qos":"2","broker":"a37eb2d0.4a3e7","x":228,"y":471,"wires":[["672fba5b.00fc44"]]},{"id":"672fba5b.00fc44","type":"ui_gauge","z":"134c75d0.b495aa","name":"","group":"1e3853b5.df4fdc","order":0,"width":0,"height":0,"gtype":"gage","title":"Temperatur Prüfling","label":"°C","format":"{{value}}","min":0,"max":"75","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":654,"y":470,"wires":[]},{"id":"bb5e0aa8.c5db18","type":"mqtt out","z":"134c75d0.b495aa","name":"","topic":"/Dashboard/Spannung","qos":"","retain":"","broker":"a37eb2d0.4a3e7","x":1160,"y":182,"wires":[]},{"id":"d6856c16.12e07","type":"mqtt in","z":"134c75d0.b495aa","name":"","topic":"/Dashboard/Spannung","qos":"2","broker":"a37eb2d0.4a3e7","x":230,"y":411,"wires":[["58efa451.c8eecc"]]},{"id":"aeeb03d3.57c5","type":"function","z":"134c75d0.b495aa","name":"binary input rising edge","func":"const previousBinaryInputValue = flow.get(\"previousBinaryInputValue\") || false;\nlet risingEdge = false;\n\n// detect rising edge on binary0\nrisingEdge = msg.payload.binaryInput0 && !previousBinaryInputValue;\n\n// backup previous value\nflow.set(\"previousBinaryInputValue\", msg.payload.binaryInput0);\n\n// if rising edge then return new msg\nif (risingEdge) return msg;\n","outputs":1,"noerr":0,"x":450,"y":200,"wires":[["32a4c86e.3bb3a8","c22ad281.c8054"]]},{"id":"32a4c86e.3bb3a8","type":"function","z":"134c75d0.b495aa","name":"Spannung extrahieren","func":"\nreturn {payload: msg.payload.Spannung/100};","outputs":1,"noerr":0,"x":800,"y":180,"wires":[["5cfc421f.d3429c","bb5e0aa8.c5db18"]]},{"id":"c22ad281.c8054","type":"function","z":"134c75d0.b495aa","name":"Temperatur extrahieren","func":"\nreturn {payload : msg.payload.Temperatur/100};","outputs":1,"noerr":0,"x":790,"y":240,"wires":[["b04b43bc.77b29"]]},{"id":"dab05dae.3a5cf","type":"s7 endpoint","z":"","transport":"iso-on-tcp","address":"192.168.0.2","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapterauto":true,"adapterport":"","busaddr":"2","adapteraddr":"0","cycletime":"100","timeout":"1500","verbose":"on","name":"","vartable":[{"addr":"DB1,INT14","name":"Spannung"},{"addr":"DB1,INT28","name":"Temperatur"}]},{"id":"1e3853b5.df4fdc","type":"ui_group","z":"","name":"Prüfparameter","tab":"3f0a0f05.5a57d","order":null,"disp":true,"width":"6"},{"id":"a37eb2d0.4a3e7","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"3f0a0f05.5a57d","type":"ui_tab","name":"Tab","icon":"dashboard","order":0}]
Hope it helps
Thank you very much that's the solution. Every time I get a rising edge I want to log the current data. This is exactly what I was looking for.
Thank you all for your help.
cheers!
Thanks for your approach,
I only can't open your file correct becaus of missing nodes. What kind of package I have to download if I want to see the batch node?
regards!
The Batch node is a core node that was added to Node-RED in version 0.18.
OK I don't have it. I will do an update later.
One question left. How can I filter the active Input out of the msg.?
By trying to filter it with: return {payload : msg.payload.Input*}; is an error. Without the * its undefined.
Can you pleas help an bloody beginner?
Thank you
[{"id":"ebbfc137.5b826","type":"ui_gauge","z":"f5a842ed.940dc","name":"Spannung","group":"b5632bd2.d6b6e8","order":0,"width":0,"height":0,"gtype":"gage","title":"Spannung","label":"Volt","format":"{{value}}","min":0,"max":"20","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1310,"y":140,"wires":[]},{"id":"c0dd4de4.aace","type":"mqtt out","z":"f5a842ed.940dc","name":"","topic":"/Dashboard/Temperatur","qos":"","retain":"","broker":"407973b6.64beac","x":690,"y":320,"wires":[]},{"id":"4a4510c3.04ce1","type":"mqtt in","z":"f5a842ed.940dc","name":"","topic":"/Dashboard/Temperatur","qos":"2","broker":"407973b6.64beac","x":920,"y":320,"wires":[["b370b874.1dcf58"]]},{"id":"b370b874.1dcf58","type":"ui_gauge","z":"f5a842ed.940dc","name":"","group":"b5632bd2.d6b6e8","order":0,"width":0,"height":0,"gtype":"gage","title":"Temperatur Prüfling","label":"°C","format":"{{value}}","min":0,"max":"75","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1330,"y":320,"wires":[]},{"id":"456b6b79.781384","type":"mqtt out","z":"f5a842ed.940dc","name":"","topic":"/Dashboard/Spannung","qos":"","retain":"","broker":"407973b6.64beac","x":680,"y":140,"wires":[]},{"id":"c021ff5.276da","type":"mqtt in","z":"f5a842ed.940dc","name":"","topic":"/Dashboard/Spannung","qos":"2","broker":"407973b6.64beac","x":920,"y":140,"wires":[["ebbfc137.5b826"]]},{"id":"82744c1f.758d6","type":"s7 in","z":"f5a842ed.940dc","endpoint":"83e511e7.543f6","mode":"single","variable":"Spannung","diff":true,"name":"Voltage from PLC","x":100,"y":140,"wires":[["41609084.fc309"]]},{"id":"41609084.fc309","type":"function","z":"f5a842ed.940dc","name":"Testspannung","func":"\nreturn {payload : msg.payload/100};","outputs":1,"noerr":0,"x":420,"y":140,"wires":[["76bde76b.dbf6e8","456b6b79.781384"]]},{"id":"76bde76b.dbf6e8","type":"debug","z":"f5a842ed.940dc","name":"","active":false,"console":"false","complete":"false","x":650,"y":80,"wires":[]},{"id":"be88c512.ecc948","type":"s7 in","z":"f5a842ed.940dc","endpoint":"83e511e7.543f6","mode":"single","variable":"Temperatur","diff":true,"name":"","x":110,"y":320,"wires":[["92dbfeb6.4a95f"]]},{"id":"92dbfeb6.4a95f","type":"function","z":"f5a842ed.940dc","name":"Temperatur Testumgebnung","func":"\nreturn {payload : msg.payload/100};","outputs":1,"noerr":0,"x":380,"y":320,"wires":[["c0dd4de4.aace","a318a91e.f3f0b8"]]},{"id":"a318a91e.f3f0b8","type":"debug","z":"f5a842ed.940dc","name":"","active":false,"console":"false","complete":"false","x":650,"y":260,"wires":[]},{"id":"4e377966.46c108","type":"debug","z":"f5a842ed.940dc","name":"","active":false,"console":"false","complete":"payload","x":330,"y":480,"wires":[]},{"id":"343d92d9.ecbf3e","type":"function","z":"f5a842ed.940dc","name":"binary input rising edge","func":"const previousBinaryInputValue = flow.get(\"previousBinaryInputValue\") || false;\nlet risingEdge = false;\n\n// detect rising edge on binary0\nrisingEdge = msg.payload.Input1 && !previousBinaryInputValue;\n\n// backup previous value\nflow.set(\"previousBinaryInputValue\", msg.payload.Input1);\n\n// if rising edge then return new msg\nif (risingEdge) return msg;\n","outputs":1,"noerr":0,"x":370,"y":540,"wires":[["81fbcbf8.603eb8","deb4e2d7.070d9","ead0e149.67bc9"]]},{"id":"81fbcbf8.603eb8","type":"function","z":"f5a842ed.940dc","name":"Spannung extrahieren","func":"\nreturn {payload: msg.payload.Spannung/100};","outputs":1,"noerr":0,"x":680,"y":460,"wires":[["3d14e2ec.c7323e"]]},{"id":"deb4e2d7.070d9","type":"function","z":"f5a842ed.940dc","name":"Temperatur extrahieren","func":"\nreturn {payload : msg.payload.Temperatur/100};","outputs":1,"noerr":0,"x":690,"y":540,"wires":[["9e12cbb2.ea1fa8"]]},{"id":"3d14e2ec.c7323e","type":"debug","z":"f5a842ed.940dc","name":"","active":false,"console":"false","complete":"false","x":890,"y":460,"wires":[]},{"id":"ead0e149.67bc9","type":"function","z":"f5a842ed.940dc","name":"Input Filter","func":"\nreturn {payload : msg.payload.Input}","outputs":1,"noerr":0,"x":650,"y":620,"wires":[["d5f2984b.3abd28"]]},{"id":"1fb0a336.b2847d","type":"s7 in","z":"f5a842ed.940dc","endpoint":"83e511e7.543f6","mode":"all","variable":"","diff":true,"name":"LOGO 8 B!OTest","x":100,"y":540,"wires":[["343d92d9.ecbf3e","4e377966.46c108"]]},{"id":"9e12cbb2.ea1fa8","type":"debug","z":"f5a842ed.940dc","name":"","active":false,"console":"false","complete":"false","x":890,"y":540,"wires":[]},{"id":"d5f2984b.3abd28","type":"debug","z":"f5a842ed.940dc","name":"","active":true,"console":"false","complete":"true","x":870,"y":620,"wires":[]},{"id":"b5632bd2.d6b6e8","type":"ui_group","z":"","name":"Prüfparameter","tab":"a41eccbd.7a1f6","order":null,"disp":true,"width":"6"},{"id":"407973b6.64beac","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"83e511e7.543f6","type":"s7 endpoint","z":"","transport":"iso-on-tcp","address":"192.168.0.2","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapterauto":true,"adapterport":"","busaddr":"2","adapteraddr":"0","cycletime":"100","timeout":"1500","verbose":"on","name":"","vartable":[{"addr":"DB1,INT14","name":"Spannung"},{"addr":"DB1,INT28","name":"Temperatur"},{"addr":"DB1,X1.0","name":"Input1"},{"addr":"DB1,X1.1","name":"Input2"},{"addr":"DB1,X1.2","name":"Input3"},{"addr":"DB1,X1.3","name":"Input4"},{"addr":"DB1,X1.4","name":"Input5"},{"addr":"DB1,X1.5","name":"Input6"},{"addr":"DB1,X1.6","name":"Input7"},{"addr":"DB1,X1.7","name":"Input8"}]},{"id":"a41eccbd.7a1f6","type":"ui_tab","z":"f5a842ed.940dc","name":"Home","icon":"dashboard"}]
Hey, can you show how msg.payload is formated at the output of your "LOGO 8 BIO Test" node ?
Hello,
the formatting of the LOGO Node is as follows. I hope you asked for that. Its an Object.
now I want to filter out which of the Inputs has triggered the loggingfunction.
Is it possiblie to filter that out even if one of the input is true already and an other one becomes true after that? I think therefore I need something like an impuls funtion or? So that the logging function gets triggered due to the rising edge of an input and gets triggered the second time if an other input becomes true although the first input stays true. And so on for all 8 inputs.
thanks for your help.
regards!
Hey,
You mean you want to record "Spannung" and "Temperatur" when you detect a rising edge on each "msg.payload.Input" ?
If I understand well, then you would like to do something like that:
[{"id":"1afe00a2.f1cc6f","type":"debug","z":"84bbe9a6.6ddfa8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":370,"y":480,"wires":[]},{"id":"4464ff08.88d8d","type":"function","z":"84bbe9a6.6ddfa8","name":"detect rising edge on each binary inputs","func":"// get last Input values\nconst previousInputs = flow.get(\"previousInputs\") || [false, false, false, false, false, false, false, false];\n\n// put last Input values in an array\nconst actualValues = Object.keys(msg.payload)\n // keep only keys containing \"Input\" in it's name\n .filter(key => key.indexOf(\"Input\") >= 0)\n // get the Input value\n .map(key => msg.payload[key]);\n\n// detect rising edge on each binary inputs\nconst risingEdge = actualValues.reduce((acc, value, index) => {\n return acc || (value && !previousInputs[index]);\n}, false);\n\n// backup previous value\nflow.set(\"previousInputs\", actualValues);\n\n// if rising edge then return msg\nif (risingEdge) return msg;\n","outputs":1,"noerr":0,"x":460,"y":560,"wires":[["d4d0aa8.a267a58","d89fb923.943068"]]},{"id":"d4d0aa8.a267a58","type":"function","z":"84bbe9a6.6ddfa8","name":"Spannung extrahieren","func":"\nreturn {payload: msg.payload.Spannung/100};","outputs":1,"noerr":0,"x":840,"y":480,"wires":[["be718ad7.883588"]]},{"id":"d89fb923.943068","type":"function","z":"84bbe9a6.6ddfa8","name":"Temperatur extrahieren","func":"\nreturn {payload : msg.payload.Temperatur/100};","outputs":1,"noerr":0,"x":850,"y":560,"wires":[["6399ff1b.2a193"]]},{"id":"be718ad7.883588","type":"debug","z":"84bbe9a6.6ddfa8","name":"","active":true,"console":"false","complete":"false","x":1050,"y":480,"wires":[]},{"id":"29ebf0a2.33e35","type":"s7 in","z":"84bbe9a6.6ddfa8","endpoint":"17c9c245.cd719e","mode":"all","variable":"","diff":true,"name":"LOGO 8 B!OTest","x":100,"y":560,"wires":[["4464ff08.88d8d","1afe00a2.f1cc6f"]]},{"id":"6399ff1b.2a193","type":"debug","z":"84bbe9a6.6ddfa8","name":"","active":true,"console":"false","complete":"false","x":1050,"y":560,"wires":[]},{"id":"9ba8ea20.abf728","type":"inject","z":"84bbe9a6.6ddfa8","name":"Logo simulator","topic":"","payload":"{\"Input1\":false,\"Input2\":true,\"Input3\":false,\"Input4\":false,\"Input5\":false,\"Input6\":false,\"Input7\":false,\"Input8\":true,\"Spannung\":0,\"Temperatur\":2350}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":620,"wires":[["4464ff08.88d8d","1afe00a2.f1cc6f"]]},{"id":"17c9c245.cd719e","type":"s7 endpoint","z":"","transport":"iso-on-tcp","address":"192.168.0.2","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapterauto":true,"adapterport":"","busaddr":"2","adapteraddr":"0","cycletime":"100","timeout":"1500","verbose":"on","name":"","vartable":[{"addr":"DB1,INT14","name":"Spannung"},{"addr":"DB1,INT28","name":"Temperatur"},{"addr":"DB1,X1.0","name":"Input1"},{"addr":"DB1,X1.1","name":"Input2"},{"addr":"DB1,X1.2","name":"Input3"},{"addr":"DB1,X1.3","name":"Input4"},{"addr":"DB1,X1.4","name":"Input5"},{"addr":"DB1,X1.5","name":"Input6"},{"addr":"DB1,X1.6","name":"Input7"},{"addr":"DB1,X1.7","name":"Input8"}]}]
I've modified the "rising edge detection" node by a node that detects a rising edge on each "msg.payload.Input".
Hope it answer your question
I'm overhelmed!
This is awesome.
Can't thank you enough.
But I also can't guarantee that this was the last question. I hope I can count on you for my next questions . You are amazing.
Thanks a lot.
I've added one extra Filter node to your flow. How do I have to edit it to get the Input number (index?) ? My goal is to know which input causes the logging or rising edge.
[{"id":"8b52914c.58b5d","type":"debug","z":"f5a842ed.940dc","name":"","active":true,"console":false,"complete":"payload","x":510.01953125,"y":902.00390625,"wires":[]},{"id":"88b13759.550bb8","type":"function","z":"f5a842ed.940dc","name":"detect rising edge on each binary inputs","func":"// get last Input values\nconst previousInputs = flow.get(\"previousInputs\") || [false, false, false, false, false, false, false, false];\n\n// put last Input values in an array\nconst actualValues = Object.keys(msg.payload)\n // keep only keys containing \"Input\" in it's name\n .filter(key => key.indexOf(\"Input\") >= 0)\n // get the Input value\n .map(key => msg.payload[key]);\n\n// detect rising edge on each binary inputs\nconst risingEdge = actualValues.reduce((acc, value, index) => {\n return acc || (value && !previousInputs[index]);\n}, false);\n\n// backup previous value\nflow.set(\"previousInputs\", actualValues);\n\n// if rising edge then return msg\nif (risingEdge) return msg;\n","outputs":1,"noerr":0,"x":600.01953125,"y":982.00390625,"wires":[["a8e7eb56.5fb138","1668606d.66f06","891767b6.32e9c8"]]},{"id":"a8e7eb56.5fb138","type":"function","z":"f5a842ed.940dc","name":"Spannung extrahieren","func":"\nreturn {payload: msg.payload.Spannung/100};","outputs":1,"noerr":0,"x":980.01953125,"y":902.00390625,"wires":[["fe6ae681.cbfb08"]]},{"id":"1668606d.66f06","type":"function","z":"f5a842ed.940dc","name":"Temperatur extrahieren","func":"\nreturn {payload : msg.payload.Temperatur/100};","outputs":1,"noerr":0,"x":990.01953125,"y":982.00390625,"wires":[["1db93a5c.aec7d6"]]},{"id":"fe6ae681.cbfb08","type":"debug","z":"f5a842ed.940dc","name":"","active":true,"console":"false","complete":"false","x":1190.01953125,"y":902.00390625,"wires":[]},{"id":"ce35844c.a0b7a8","type":"s7 in","z":"f5a842ed.940dc","endpoint":"1ebb149f.63ab8b","mode":"all","variable":"","diff":true,"name":"LOGO 8 B!OTest","x":240.01953125,"y":982.00390625,"wires":[["88b13759.550bb8","8b52914c.58b5d"]]},{"id":"1db93a5c.aec7d6","type":"debug","z":"f5a842ed.940dc","name":"","active":true,"console":"false","complete":"false","x":1190.01953125,"y":982.00390625,"wires":[]},{"id":"432bf322.0b1dec","type":"inject","z":"f5a842ed.940dc","name":"Logo simulator","topic":"","payload":"{\"Input1\":false,\"Input2\":true,\"Input3\":false,\"Input4\":false,\"Input5\":false,\"Input6\":false,\"Input7\":false,\"Input8\":true,\"Spannung\":0,\"Temperatur\":2350}","payloadType":"json","repeat":"","crontab":"","once":false,"x":280.01953125,"y":1042.00390625,"wires":[["88b13759.550bb8","8b52914c.58b5d"]]},{"id":"891767b6.32e9c8","type":"function","z":"f5a842ed.940dc","name":"Input Filter","func":"\nreturn {payload : msg.payload.Input}","outputs":1,"noerr":0,"x":950,"y":1060,"wires":[["ccb06265.c6d17"]]},{"id":"ccb06265.c6d17","type":"debug","z":"f5a842ed.940dc","name":"","active":true,"console":"false","complete":"payload[key]","x":1210,"y":1060,"wires":[]},{"id":"1ebb149f.63ab8b","type":"s7 endpoint","z":"","transport":"iso-on-tcp","address":"192.168.0.2","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapterauto":true,"adapterport":"","busaddr":"2","adapteraddr":"0","cycletime":"100","timeout":"1500","verbose":"on","name":"","vartable":[{"addr":"DB1,INT14","name":"Spannung"},{"addr":"DB1,INT28","name":"Temperatur"},{"addr":"DB1,X1.0","name":"Input1"},{"addr":"DB1,X1.1","name":"Input2"},{"addr":"DB1,X1.2","name":"Input3"},{"addr":"DB1,X1.3","name":"Input4"},{"addr":"DB1,X1.4","name":"Input5"},{"addr":"DB1,X1.5","name":"Input6"},{"addr":"DB1,X1.6","name":"Input7"},{"addr":"DB1,X1.7","name":"Input8"}]}]
And what is "=>" meaning? bigger equals? And what is "acc" doing ("return acc")?
You can do it like that:
[{"id":"8e5f13fb.9a24c","type":"debug","z":"84bbe9a6.6ddfa8","name":"","active":true,"console":false,"complete":"payload","x":450,"y":140,"wires":[]},{"id":"d81dc7a2.bdffc8","type":"function","z":"84bbe9a6.6ddfa8","name":"detect rising edge on each binary inputs","func":"// get last Input values\nconst previousInputs = flow.get(\"previousInputs\") || [false, false, false, false, false, false, false, false];\n\n// put last Input values in an array\nconst actualValues = Object.keys(msg.payload)\n // keep only keys containing \"Input\" in it's name\n .filter(key => key.indexOf(\"Input\") >= 0)\n // get the Input value\n .map(key => msg.payload[key]);\n \nlet inputNumber = [];\n\n// detect rising edge on each binary inputs\nconst risingEdge = actualValues.reduce((acc, value, index) => {\n if (value && !previousInputs[index]) inputNumber.push(index + 1);\n return acc || (value && !previousInputs[index]);\n}, false);\n\n// backup previous value\nflow.set(\"previousInputs\", actualValues);\n\n// if rising edge then return msg\nif (risingEdge) {\n return [\n msg,\n {payload: inputNumber}\n ];\n}\n","outputs":2,"noerr":0,"x":540,"y":220,"wires":[["c1d09b2f.62f828","bf837f4c.dcdaa"],["14e3d04c.bfd1b"]]},{"id":"c1d09b2f.62f828","type":"function","z":"84bbe9a6.6ddfa8","name":"Spannung extrahieren","func":"\nreturn {payload: msg.payload.Spannung/100};","outputs":1,"noerr":0,"x":920,"y":140,"wires":[["35f7a698.13043a"]]},{"id":"bf837f4c.dcdaa","type":"function","z":"84bbe9a6.6ddfa8","name":"Temperatur extrahieren","func":"\nreturn {payload : msg.payload.Temperatur/100};","outputs":1,"noerr":0,"x":930,"y":220,"wires":[["242c69a.4a4a396"]]},{"id":"35f7a698.13043a","type":"debug","z":"84bbe9a6.6ddfa8","name":"","active":true,"console":"false","complete":"false","x":1130,"y":140,"wires":[]},{"id":"7b1301e3.54271","type":"s7 in","z":"84bbe9a6.6ddfa8","endpoint":"8709de19.87e5f","mode":"all","variable":"","diff":true,"name":"LOGO 8 B!OTest","x":180,"y":220,"wires":[["d81dc7a2.bdffc8","8e5f13fb.9a24c"]]},{"id":"242c69a.4a4a396","type":"debug","z":"84bbe9a6.6ddfa8","name":"","active":true,"console":"false","complete":"false","x":1130,"y":220,"wires":[]},{"id":"43dc4c75.d792f4","type":"inject","z":"84bbe9a6.6ddfa8","name":"Logo simulator","topic":"","payload":"{\"Input1\":true,\"Input2\":false,\"Input3\":false,\"Input4\":false,\"Input5\":true,\"Input6\":false,\"Input7\":false,\"Input8\":false,\"Spannung\":0,\"Temperatur\":2350}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":"","x":220,"y":280,"wires":[["d81dc7a2.bdffc8","8e5f13fb.9a24c"]]},{"id":"14e3d04c.bfd1b","type":"debug","z":"84bbe9a6.6ddfa8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1129.98046875,"y":297.99609375,"wires":[]},{"id":"8709de19.87e5f","type":"s7 endpoint","z":"","transport":"iso-on-tcp","address":"192.168.0.2","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapterauto":true,"adapterport":"","busaddr":"2","adapteraddr":"0","cycletime":"100","timeout":"1500","verbose":"on","name":"","vartable":[{"addr":"DB1,INT14","name":"Spannung"},{"addr":"DB1,INT28","name":"Temperatur"},{"addr":"DB1,X1.0","name":"Input1"},{"addr":"DB1,X1.1","name":"Input2"},{"addr":"DB1,X1.2","name":"Input3"},{"addr":"DB1,X1.3","name":"Input4"},{"addr":"DB1,X1.4","name":"Input5"},{"addr":"DB1,X1.5","name":"Input6"},{"addr":"DB1,X1.6","name":"Input7"},{"addr":"DB1,X1.7","name":"Input8"}]}]
As a result, you get an array of indexes, each index is the index of an input where a rising edge have just occured.
I choosed to put a second output to the node to let you see how it works, but you can also leave the node with only one output and include the index list in msg.payload
.
acc
is an accumulator, see Array.reduce documentation for more informations.
=>
is arrow function, it's just a syntactically compact alternative to a regular function expression.
const test = function() {}
// and
const test = () => {}
// are the same
In ES5, I would have written:
var risingEdge = actualValues.reduce(function(acc, value, index) {
if (value && !previousInputs[index]) inputNumber.push(index + 1);
return acc || (value && !previousInputs[index]);
}, false);
Thank you once again.
Since I have no clue about the syntax of Java until now, I don't know how to include the Input list within the msg.payload
.?
Maybe you can recommend some literature for beginners to get a good overview of the syntax.