Hi
i am looking for an funktion that does the following:
on my Raspberry when i push an button (GPIO in 7), than i want to send out udp1, if i push the same button a second time i want to send out udp2, and than if i push the button another time i want to sent out udp1....so now i have tried it with the toggle note, but i have no result which is working. any ideas for an beginner to solve the problem
thanks
You need to save the last state in a context which can be remembered when the next msg arrives. Either you take a flow variable or a context variable in a function node.
thanks, but for me as an beginner this is too compicated, is there no other way. over a node witch i can install?
Did you try searching flows.nodered.org for Toggle. I found this very quickly there. I haven't tried it but it looks close to what you want. Toggle Switch Subflow (flow) - Node-RED
Import this function node:
[
{
"id": "db823e37fd839077",
"type": "function",
"z": "f87aa05e3297dcd1",
"name": "",
"func": "var output = !(context.get(\"toogle\")||false);\ncontext.set(\"toogle\",output);\nmsg.payload = output ? \"udp1\" : \"udp2\";\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 720,
"y": 1040,
"wires": [
[
"6d935a3dcad3e665"
]
]
}
]
toogles your output.
thank you, that works perfect
No code version
[
{
"id": "db823e37fd839077",
"type": "function",
"z": "f87aa05e3297dcd1",
"name": "",
"func": "var output = !(context.get(\"toogle\")||false);\ncontext.set(\"toogle\",output);\nmsg.payload = output ? \"udp1\" : \"udp2\";\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 720,
"y": 1040,
"wires": [
[
"6d935a3dcad3e665"
]
]
}
]
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.