Node-Red Function Node for Beginners

Поделиться
HTML-код
  • Опубликовано: 16 июл 2018
  • In this video tutorial we take a closer look at the very versatile node-red function node.
    The function node allows you to insert your own JavaScript code into a flow and is probably used in almost all flows.
    We look at inputs and outputs and how to work with the message object.
    Using some basic demo flows we look at how you return messages to multiple outputs and how to return multiple messages using a message loop.
    Tutorial on Site
    stevesnoderedguide.com/node-r...
    Related videos and resources
    -----------------------
    Republish HTTP Data Over MQTT with Node-Red
    • Republish HTTP Data Ov...
    ---------------
    The Node-Red Message Object for Beginners
    • The Node-Red Message O...
    ------------
    How to Store Data In Node Red Variables
    • How to Store Data In N...
    If you find these videos useful then you might want to consider buying me a coffee
    www.paypal.me/StepenCope
  • ХоббиХобби

Комментарии • 21

  • @BoneyardHauntedHouse
    @BoneyardHauntedHouse 4 года назад

    Thank you very much for this video, it helped me out a great deal, well done Sir.

  • @mbunds
    @mbunds 5 лет назад +3

    To have your messages in the "Message Array" example display the payloads "test message0", "test message1", and "test message2", instead of
    "test message0", "test message01", and "test message012":
    var m_out=[]; //array for message objects
    var message; //variable to contain the message payload for concatenation of "i"
    for (i=0;i

  • @Zhaymoor
    @Zhaymoor 2 года назад

    Thank you so much.

  • @chozairitu6975
    @chozairitu6975 6 лет назад

    in former node-red for loop is a mess, is this function has multiple output gonna change that ?

  • @quaternion-pi
    @quaternion-pi 6 лет назад

    Love your videos. At 7:46 I noticed you did not declare i as a var in the 'for' loop, and did not end the var newmsg statement with a ';'. I know the latter is optional in javascript, but sometimes its absence can cause side effects. Since I am learning javascript it;s nice to see how experienced programmers code. Your website is a great learning tool for me. Thanks.

    • @stevecope
      @stevecope  6 лет назад +1

      Tks for the comment. I'll try to make sure I check the code syntax . At the moment II am back and forth between Python and JavaScript.which is why I keep forgetting.

  • @cpyandy
    @cpyandy 5 лет назад

    I'd like to do something slightly similar to the fourth example "topic splitter" but i can't figure how to make it work. Is it possible for a function node to output a single payload of "1" when the payload of both input node both equal to "1", else output a "0" payload. Pretty much just an AND logic gate with function node.

    • @stevecope
      @stevecope  5 лет назад

      Yes but you will need to remember the input values and you only get one input at one time. I did a video her
      How to Store Data In Node Red Variables
      ruclips.net/video/kNfP1vw2Img/видео.html
      If you use the ask steve page on the website I'll help you with the flow
      rgds
      steve

  • @FisVii77
    @FisVii77 5 лет назад

    Steve have you ever tried the custom node from the pallette installer for python, I was wondering if you could do a video or two on using those, python function nodes, I played with them a little but seems either I am coding wrong, or the nodes have bugs. would you consider doing a thourough video on them python is a much simpler and intuitive programming language itleast for me :)

    • @stevecope
      @stevecope  5 лет назад +1

      Do you mean the python3 function node? I installed this node a little while ago to run some python scripts but never got around to using it.

    • @FisVii77
      @FisVii77 5 лет назад

      Yes steve haven't seen anyone post any videos on this python3 function or its capabilities yet, I think that would be a great video to add to your collection considering many new programmers use python and do not know the syntax of javascript I know I fall into this category myself as well. Great vids/content keep em up.

  • @TheUnofficialMaker
    @TheUnofficialMaker Год назад

    Nicely done, how would I return only the topic from email? (get the subject line) Thanks.

    • @stevecope
      @stevecope  Год назад

      If the subject is the message topic then you just extract it using
      var subject=msg.topic

  • @dmitryponyatov2158
    @dmitryponyatov2158 Год назад

    Do you know some reason not having multiple inputs in function blocks (with multiple dispatch) and inputs that remembers the last message?
    In case I'm writing some error computation function block (closed loop control), it will be great to have two inputs visually, and logically available for direct reading in a function code.

    • @dmitryponyatov2158
      @dmitryponyatov2158 Год назад

      I know about _context._ tricks, but it looks like assembly programming

    • @stevecope
      @stevecope  Год назад

      There is no real need for multiple inputs as you can filter input by a message property usually topic. To remember use a context or flow variable.
      stevesnoderedguide.com/node-red-variables
      Rgds
      Steve

  • @mrsamsupersam
    @mrsamsupersam 2 года назад

    Hi,
    I installed a radar tide gauge and the output is a number eg 103.
    103 is the distance from the sensor to the waterline.
    I want to know the waterlevel.
    103 is corresponding a water level of 20cm.
    How can I convert every message with the formula below?
    value*(-1)+123
    Thanks for the help!

    • @stevecope
      @stevecope  2 года назад

      Use a function node with
      msg.payload=(msg.payload *-1) +123

    • @sdc7918
      @sdc7918 2 года назад

      @@stevecope this is working fine. Thanks a lot!

  • @SA-oj3bo
    @SA-oj3bo 2 года назад

    Why return [m_out] and not return m_out ?

    • @stevecope
      @stevecope  2 года назад

      It is because we are returning a message array and so x messages will be sent and not a single message.