How to sum multiple inputs?How do JavaScript closures work?node-red node with multiple outputs but send msgs asynchronReturning multiple messages in node-red functionNode-red switch node not working in IBM BluemixConcurrent access to msg/payload on split flows in node-red?How to use onKeypress event in a textboxHow can I run parallel flows in node-red and then join the data?update a file in node-red through context-storagenode-red Schedex nodeHowto merge two hex buffer values in node-red

Why is this integration method not valid?

Managing heat dissipation in a magic wand

What is the winged creature on the back of the Mordenkainen's Tome of Foes book?

Writing "hahaha" versus describing the laugh

Was murdering a slave illegal in American slavery, and if so, what punishments were given for it?

Why is 'additive' EQ more difficult to use than 'subtractive'?

Real Analysis: Proof of the equivalent definitions of the derivative.

Can a bard grant bardic inspiration to an unconscious creature?

Download app bundles from App Store to run on iOS Emulator on Mac

Make the `diff` command look only for differences from a specified range of lines

How to safely discharge oneself

Can someone get a spouse off a deed that never lived together and was incarcerated?

How would a physicist explain this starship engine?

Is it normal to "extract a paper" from a master thesis?

Why did Nick Fury not hesitate in blowing up the plane he thought was carrying a nuke?

Singular Integration

How to tease a romance without a cat and mouse chase?

What is this dime sized black bug with white on the segments near Loveland Colorodao?

Is being an extrovert a necessary condition to be a manager?

If change in free energy (G) is positive, how do those reactions still occur?

What defines a person who is circumcised "of the heart"?

Computing elements of a 1000x60 matrix exhausts RAM

How many wires should be in a new thermostat cable?

Team member is vehemently against code formatting



How to sum multiple inputs?


How do JavaScript closures work?node-red node with multiple outputs but send msgs asynchronReturning multiple messages in node-red functionNode-red switch node not working in IBM BluemixConcurrent access to msg/payload on split flows in node-red?How to use onKeypress event in a textboxHow can I run parallel flows in node-red and then join the data?update a file in node-red through context-storagenode-red Schedex nodeHowto merge two hex buffer values in node-red






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm trying to read out 5 microswitches in LuvitRED (other form of node-red). To be useful in the rest of the program, the 5 sensors should come together into 1 integer.



enter image description here



The image above is the layout for the node-RED. At first, I was going to convert each input in a separate function. The bottom part shows the second idea, where all microswitches are read and summed in 1 function.



The idea is:



  • Microswitch 1 = 1 (when active)

  • Microswitch 2 = 10

  • Microswitch 3 = 100 and so on.

This way, when I summed them all, the eventual number would be between 00000 and 11111 depending on which ones are active and make for easy recognition of which microswitches are active.



The bottom part of the image is using simple buttons, which all send a msg.payload = 1 when pressed for quick testing. The code for the function is mentioned below here.



I Googled about this problem, and a lot of the forums stated that using the change function (to change 1 to 10 and more), combined with the join function would work. Sadly however, in LuvitRED, there is no join function, because it is an altered version of Node-RED.



if not msg then
-- called on startup
return
end

flow.microswitch1 = 0;
flow.microswitch2 = 0;
flow.microswitch3 = 0;
flow.microswitch4 = 0;
flow.microswitch5 = 0;

if (msg.topic == 'microswitch1') then
flow.microswitch1 = msg.payload;
elseif (msg.topic == 'microswitch2') then
flow.microswitch2 = msg.payload * 10;
elseif (msg.topic == 'microswitch3') then
flow.microswitch3 = msg.payload * 100;
elseif (msg.topic == 'microswitch4') then
flow.microswitch4 = msg.payload * 1000;
elseif (msg.topic == 'microswitch5') then
flow.microswitch5 = msg.payload * 10000;
end

global.availableSpaces = flow.microswitch1 + flow.microswitch2 +
flow.microswitch3 + flow.microswitch4 + flow.microswitch5
msg.payload = global.availableSpaces

return msg


I expected this to work, since I'm only working with buttons for now, which always send a 1 msg.payload when pressed. For some reason however, I'm getting an input error when pressing the buttons without any result in the debugger. Do you all have any ideas as to how I can fix this issue?










share|improve this question






























    0















    I'm trying to read out 5 microswitches in LuvitRED (other form of node-red). To be useful in the rest of the program, the 5 sensors should come together into 1 integer.



    enter image description here



    The image above is the layout for the node-RED. At first, I was going to convert each input in a separate function. The bottom part shows the second idea, where all microswitches are read and summed in 1 function.



    The idea is:



    • Microswitch 1 = 1 (when active)

    • Microswitch 2 = 10

    • Microswitch 3 = 100 and so on.

    This way, when I summed them all, the eventual number would be between 00000 and 11111 depending on which ones are active and make for easy recognition of which microswitches are active.



    The bottom part of the image is using simple buttons, which all send a msg.payload = 1 when pressed for quick testing. The code for the function is mentioned below here.



    I Googled about this problem, and a lot of the forums stated that using the change function (to change 1 to 10 and more), combined with the join function would work. Sadly however, in LuvitRED, there is no join function, because it is an altered version of Node-RED.



    if not msg then
    -- called on startup
    return
    end

    flow.microswitch1 = 0;
    flow.microswitch2 = 0;
    flow.microswitch3 = 0;
    flow.microswitch4 = 0;
    flow.microswitch5 = 0;

    if (msg.topic == 'microswitch1') then
    flow.microswitch1 = msg.payload;
    elseif (msg.topic == 'microswitch2') then
    flow.microswitch2 = msg.payload * 10;
    elseif (msg.topic == 'microswitch3') then
    flow.microswitch3 = msg.payload * 100;
    elseif (msg.topic == 'microswitch4') then
    flow.microswitch4 = msg.payload * 1000;
    elseif (msg.topic == 'microswitch5') then
    flow.microswitch5 = msg.payload * 10000;
    end

    global.availableSpaces = flow.microswitch1 + flow.microswitch2 +
    flow.microswitch3 + flow.microswitch4 + flow.microswitch5
    msg.payload = global.availableSpaces

    return msg


    I expected this to work, since I'm only working with buttons for now, which always send a 1 msg.payload when pressed. For some reason however, I'm getting an input error when pressing the buttons without any result in the debugger. Do you all have any ideas as to how I can fix this issue?










    share|improve this question


























      0












      0








      0








      I'm trying to read out 5 microswitches in LuvitRED (other form of node-red). To be useful in the rest of the program, the 5 sensors should come together into 1 integer.



      enter image description here



      The image above is the layout for the node-RED. At first, I was going to convert each input in a separate function. The bottom part shows the second idea, where all microswitches are read and summed in 1 function.



      The idea is:



      • Microswitch 1 = 1 (when active)

      • Microswitch 2 = 10

      • Microswitch 3 = 100 and so on.

      This way, when I summed them all, the eventual number would be between 00000 and 11111 depending on which ones are active and make for easy recognition of which microswitches are active.



      The bottom part of the image is using simple buttons, which all send a msg.payload = 1 when pressed for quick testing. The code for the function is mentioned below here.



      I Googled about this problem, and a lot of the forums stated that using the change function (to change 1 to 10 and more), combined with the join function would work. Sadly however, in LuvitRED, there is no join function, because it is an altered version of Node-RED.



      if not msg then
      -- called on startup
      return
      end

      flow.microswitch1 = 0;
      flow.microswitch2 = 0;
      flow.microswitch3 = 0;
      flow.microswitch4 = 0;
      flow.microswitch5 = 0;

      if (msg.topic == 'microswitch1') then
      flow.microswitch1 = msg.payload;
      elseif (msg.topic == 'microswitch2') then
      flow.microswitch2 = msg.payload * 10;
      elseif (msg.topic == 'microswitch3') then
      flow.microswitch3 = msg.payload * 100;
      elseif (msg.topic == 'microswitch4') then
      flow.microswitch4 = msg.payload * 1000;
      elseif (msg.topic == 'microswitch5') then
      flow.microswitch5 = msg.payload * 10000;
      end

      global.availableSpaces = flow.microswitch1 + flow.microswitch2 +
      flow.microswitch3 + flow.microswitch4 + flow.microswitch5
      msg.payload = global.availableSpaces

      return msg


      I expected this to work, since I'm only working with buttons for now, which always send a 1 msg.payload when pressed. For some reason however, I'm getting an input error when pressing the buttons without any result in the debugger. Do you all have any ideas as to how I can fix this issue?










      share|improve this question
















      I'm trying to read out 5 microswitches in LuvitRED (other form of node-red). To be useful in the rest of the program, the 5 sensors should come together into 1 integer.



      enter image description here



      The image above is the layout for the node-RED. At first, I was going to convert each input in a separate function. The bottom part shows the second idea, where all microswitches are read and summed in 1 function.



      The idea is:



      • Microswitch 1 = 1 (when active)

      • Microswitch 2 = 10

      • Microswitch 3 = 100 and so on.

      This way, when I summed them all, the eventual number would be between 00000 and 11111 depending on which ones are active and make for easy recognition of which microswitches are active.



      The bottom part of the image is using simple buttons, which all send a msg.payload = 1 when pressed for quick testing. The code for the function is mentioned below here.



      I Googled about this problem, and a lot of the forums stated that using the change function (to change 1 to 10 and more), combined with the join function would work. Sadly however, in LuvitRED, there is no join function, because it is an altered version of Node-RED.



      if not msg then
      -- called on startup
      return
      end

      flow.microswitch1 = 0;
      flow.microswitch2 = 0;
      flow.microswitch3 = 0;
      flow.microswitch4 = 0;
      flow.microswitch5 = 0;

      if (msg.topic == 'microswitch1') then
      flow.microswitch1 = msg.payload;
      elseif (msg.topic == 'microswitch2') then
      flow.microswitch2 = msg.payload * 10;
      elseif (msg.topic == 'microswitch3') then
      flow.microswitch3 = msg.payload * 100;
      elseif (msg.topic == 'microswitch4') then
      flow.microswitch4 = msg.payload * 1000;
      elseif (msg.topic == 'microswitch5') then
      flow.microswitch5 = msg.payload * 10000;
      end

      global.availableSpaces = flow.microswitch1 + flow.microswitch2 +
      flow.microswitch3 + flow.microswitch4 + flow.microswitch5
      msg.payload = global.availableSpaces

      return msg


      I expected this to work, since I'm only working with buttons for now, which always send a 1 msg.payload when pressed. For some reason however, I'm getting an input error when pressing the buttons without any result in the debugger. Do you all have any ideas as to how I can fix this issue?







      function node-red






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 3:58









      Michael

      7,69922338




      7,69922338










      asked Mar 23 at 20:22









      JasperRJasperR

      32




      32






















          1 Answer
          1






          active

          oldest

          votes


















          0














          On the assumption you cannot use a join node (which would be the normal way to do it), you might be able to use flow variables. Although you would need to check if LuvitRed supported flow.get and flow.set and if it has persistent storage between restarts.



          When reading the microswitch you would then just save it to a flow variable:



          flow.set('microswitch1', msg.payload); // or however you're getting the value


          Then each line in the func would be along the lines of:



          var microswitch1 = flow.get('microswitch1') || 0;
          // etc


          This way, if microswitch2 hasn't changed yet, it will use 0 instead.



          But the upshot is you need to cater for the final func being run on every individual message it receives. The only way to wait for all messages is to use a join.






          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55318015%2fhow-to-sum-multiple-inputs%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            On the assumption you cannot use a join node (which would be the normal way to do it), you might be able to use flow variables. Although you would need to check if LuvitRed supported flow.get and flow.set and if it has persistent storage between restarts.



            When reading the microswitch you would then just save it to a flow variable:



            flow.set('microswitch1', msg.payload); // or however you're getting the value


            Then each line in the func would be along the lines of:



            var microswitch1 = flow.get('microswitch1') || 0;
            // etc


            This way, if microswitch2 hasn't changed yet, it will use 0 instead.



            But the upshot is you need to cater for the final func being run on every individual message it receives. The only way to wait for all messages is to use a join.






            share|improve this answer





























              0














              On the assumption you cannot use a join node (which would be the normal way to do it), you might be able to use flow variables. Although you would need to check if LuvitRed supported flow.get and flow.set and if it has persistent storage between restarts.



              When reading the microswitch you would then just save it to a flow variable:



              flow.set('microswitch1', msg.payload); // or however you're getting the value


              Then each line in the func would be along the lines of:



              var microswitch1 = flow.get('microswitch1') || 0;
              // etc


              This way, if microswitch2 hasn't changed yet, it will use 0 instead.



              But the upshot is you need to cater for the final func being run on every individual message it receives. The only way to wait for all messages is to use a join.






              share|improve this answer



























                0












                0








                0







                On the assumption you cannot use a join node (which would be the normal way to do it), you might be able to use flow variables. Although you would need to check if LuvitRed supported flow.get and flow.set and if it has persistent storage between restarts.



                When reading the microswitch you would then just save it to a flow variable:



                flow.set('microswitch1', msg.payload); // or however you're getting the value


                Then each line in the func would be along the lines of:



                var microswitch1 = flow.get('microswitch1') || 0;
                // etc


                This way, if microswitch2 hasn't changed yet, it will use 0 instead.



                But the upshot is you need to cater for the final func being run on every individual message it receives. The only way to wait for all messages is to use a join.






                share|improve this answer















                On the assumption you cannot use a join node (which would be the normal way to do it), you might be able to use flow variables. Although you would need to check if LuvitRed supported flow.get and flow.set and if it has persistent storage between restarts.



                When reading the microswitch you would then just save it to a flow variable:



                flow.set('microswitch1', msg.payload); // or however you're getting the value


                Then each line in the func would be along the lines of:



                var microswitch1 = flow.get('microswitch1') || 0;
                // etc


                This way, if microswitch2 hasn't changed yet, it will use 0 instead.



                But the upshot is you need to cater for the final func being run on every individual message it receives. The only way to wait for all messages is to use a join.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 25 at 4:20

























                answered Mar 25 at 4:06









                MichaelMichael

                7,69922338




                7,69922338





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55318015%2fhow-to-sum-multiple-inputs%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현