Search code examples
functionnode-red

Is there a way to make a function node override another function node?


I have a function node comparing to values in my node-red and outputting the greater one. I want it to:

  1. Compare the 2 values and output the greater one.
  2. Recompare the 2 values again after 5 seconds.
  3. If the first value is greater, carry on outputting it else enter another function node.
  4. It should ignore the first function node and carry on with the second function node.

Note: The 2 values are being constantly fed by a serial input. My problem is that it keeps passing into the first function then to the second. I want it to skip the first function node when the requirements are met and go to the second function node directly.

Thank you.


Solution

  • You can set a variable in the flow or global context in the first function node and then you can check that value in a switch node to determine what branch to follow.

    -------------      -----------      --------------     --------------
    |   serial  |----->| switch  |----->| function 1 |---->| function 2 |
    -------------      |         |---|  --------------  |  --------------
                       -----------   |                  | 
                                     |------------------|