# Function with a lot of output?

**URL:** <https://discourse.nodered.org/t/function-with-a-lot-of-output/7752>\
**Category:** General\
**Created:** [8 February 2019 19:59 UTC](https://discourse.nodered.org/t/function-with-a-lot-of-output/7752 "2019-02-08T19:59:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![maccoa](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@maccoa](https://discourse.nodered.org/u/maccoa)\
**Post date:** [8 February 2019 19:59 UTC](https://discourse.nodered.org/t/function-with-a-lot-of-output/7752/1 "2019-02-08T19:59:56Z")

</div>

Hello everyone .  
I have a function with 88 outputs.

the source comes from a modbus output as an array.  
in the function I insert a topic on each value.

is there a simpler way to do this?

```
var x1 = { payload: msg.payload.data[0]/2}; /*var x = { payload: msg.payload.data[]};*/
var x2 = { payload: msg.payload.data[1]};
var x3 = { payload: msg.payload.data[2]/2};
var x4 = { payload: msg.payload.data[3]/10};
var x5 = { payload: msg.payload.data[4]};
var x6 = { payload: msg.payload.data[5]/2};
var x7 = { payload: msg.payload.data[6]};
var x8 = { payload: msg.payload.data[7]};
var x9 = { payload: msg.payload.data[8]};
var x10 = { payload: msg.payload.data[9]};
var x11 ={ payload: msg.payload.data[10]};
var x12 = { payload: msg.payload.data[11]};
var x13 = { payload: msg.payload.data[12]};
var x14 = { payload: msg.payload.data[13]};
var x15 = { payload: msg.payload.data[14]};
var x16 = { payload: msg.payload.data[15]};
var x17 = { payload: msg.payload.data[16]};
var x18 = { payload: msg.payload.data[17]};
var x19 = { payload: msg.payload.data[18]};
var x20 = { payload: msg.payload.data[19]};
var x21 = { payload: msg.payload.data[20]};
var x22 = { payload: msg.payload.data[21]};
var x23 = { payload: msg.payload.data[22]};
var x24 = { payload: msg.payload.data[23]};
var x25 = { payload: msg.payload.data[24]};
var x26 = { payload: msg.payload.data[25]};
var x27 = { payload: msg.payload.data[26]};
var x28 = { payload: msg.payload.data[27]};
var x29 = { payload: msg.payload.data[28]};
var x30 = { payload: msg.payload.data[29]};
var x31 = { payload: msg.payload.data[30]};
var x32 = { payload: msg.payload.data[31]};
var x33 = { payload: msg.payload.data[32]};
var x34 = { payload: msg.payload.data[33]};
var x35 = { payload: msg.payload.data[34]};
var x36 = { payload: msg.payload.data[35]};
var x37 = { payload: msg.payload.data[36]};
var x38 = { payload: msg.payload.data[37]};
var x39 = { payload: msg.payload.data[38]};
var x40 = { payload: msg.payload.data[39]};
var x41 = { payload: msg.payload.data[40]};
var x42 = { payload: msg.payload.data[41]};
var x43 = { payload: msg.payload.data[42]};
var x44 = { payload: msg.payload.data[43]};
var x45 = { payload: msg.payload.data[44]};
var x46 = { payload: msg.payload.data[45]};
var x47 = { payload: msg.payload.data[46]};
var x48 = { payload: msg.payload.data[47]};
var x49 = { payload: msg.payload.data[48]};
var x50 = { payload: msg.payload.data[49]};
var x51 = { payload: msg.payload.data[50]};
var x52 = { payload: msg.payload.data[51]};
var x53 = { payload: msg.payload.data[52]};
var x54 = { payload: msg.payload.data[53]};
var x55 = { payload: msg.payload.data[54]};
var x56 = { payload: msg.payload.data[55]};
var x57 = { payload: msg.payload.data[56]};
var x58 = { payload: msg.payload.data[57]};
var x59 = { payload: msg.payload.data[58]};
var x60 = { payload: msg.payload.data[59]};
var x61 = { payload: msg.payload.data[60]};
var x62 = { payload: msg.payload.data[61]};
var x63 = { payload: msg.payload.data[62]};
var x64 = { payload: msg.payload.data[63]};
var x65 = { payload: msg.payload.data[64]};
var x66 = { payload: msg.payload.data[65]};
var x67 = { payload: msg.payload.data[66]};
var x68 = { payload: msg.payload.data[67]};
var x69 = { payload: msg.payload.data[68]};
var x70 = { payload: msg.payload.data[69]};
var x71 = { payload: msg.payload.data[70]};
var x72 = { payload: msg.payload.data[71]};
var x73 = { payload: msg.payload.data[72]};
var x74 = { payload: msg.payload.data[73]};
var x75 = { payload: msg.payload.data[74]};
var x76 = { payload: msg.payload.data[75]};
var x77 = { payload: msg.payload.data[76]};
var x78 = { payload: msg.payload.data[77]};
var x79 = { payload: msg.payload.data[78]};
var x80 = { payload: msg.payload.data[79]};
var x81 = { payload: msg.payload.data[80]};
var x82 = { payload: msg.payload.data[81]};
var x83 = { payload: msg.payload.data[82]};
var x84 = { payload: msg.payload.data[83]};
var x85 = { payload: msg.payload.data[84]};
var x86 = { payload: msg.payload.data[85]};
var x87 = { payload: msg.payload.data[86]};
var x88 = { payload: msg.payload.data[87]};
var x89 = { payload: msg.payload.data[88]};

x1.topic = "Tp4"; /* x.topic = " ";*/
x2.topic = "Tfumé";
x3.topic = "Tconsol";
x4.topic = "O2r"; 
x5.topic = "posclapO2P";
x6.topic = "posclapO2S";
x7.topic = " vitesse ventilateur";
x8.topic = "sonde1 ";
x9.topic = " temp de fumée conden";
x10.topic = " sonde retour";
x11.topic = " m/s ouverture aspi";
x12.topic = " air primaire";
x13.topic = " commande du tirage";
x14.topic = " air secondaire";
x15.topic = " reglage P chaudière";
x16.topic = " consigne fumée";
x17.topic = " regulateur O2";
x18.topic = " temp module pellets";
x19.topic = " temp O2 aspiration";
x20.topic = " A vis extraction";
x21.topic = " heures de fonctionement";
x22.topic = " reserve journaliere pellets";
x23.topic = " nbs demarage bruleur";
x24.topic = " s4 demarage bruleur";
x25.topic = " H de fonctionement maintien du feu";
x26.topic = " alimentation";
x27.topic = " regul d alimentation";
x28.topic = " consigne chaudière";
x29.topic = " sonde accu bas solaire";
x30.topic = " A vis alimentation";
x31.topic = " A ecluse a roue cellulaire";
x32.topic = " stroker";
x33.topic = " dépression du foyer";
x34.topic = " pos moteur tiroir";
x35.topic = "pos moteur grille ";
x36.topic = "regul corection alim ";
x37.topic = " commande des pompes de retour";
x38.topic = " ventil air de combustion";
x39.topic = " ventil air de combustion 2";
x40.topic = " h fonc stroker";
x41.topic = " h fonc vis alim";
x42.topic = " h fonc roue celulaire";
x43.topic = " h fonc vibreur";
x44.topic = " cycles de fonc grille basculante";
x45.topic = " h fonc WOS";
x46.topic = " h vis descendrage";
x47.topic = " h fonc allumage";
x48.topic = " h fonc sonde lambda";
x49.topic = " h fonc turbine aspi";
x50.topic = " h fonc vis extraction";
x51.topic = " cycle aeration secu";
x52.topic = " h fonc tirage";
x53.topic = " cycle fonc clapet coupe feu";
x54.topic = " deplacement du clapet tiroir";
x55.topic = " V sonde lambda";
x56.topic = " h depuis derniere maintenance";
x57.topic = " requet via ecs hk";
x58.topic = " refroidissement foyer par air secondaire";
x59.topic = " alim limiter sur maxi";
x60.topic = " augmentation P par regul foyer";
x61.topic = " pompe prélévement";
x62.topic = " V sonde lambda coriger";
x63.topic = " h fonc pellets";
x64.topic = " h en mode chauffer";
x65.topic = " sonde de la derivation superieur";
x66.topic = " sonde de la derivation inf";
x67.topic = " val consigne retour atteinte";
x68.topic = " vitesse pompe de chargement chaudiére";
x69.topic = " sonde large bande A de chauffage";
x70.topic = " sonde large bande V de chauffage";
x71.topic = " sonde large bande V rendue";
x72.topic = " sonde large bande A pompe";
x73.topic = " slb resistance interne";
x74.topic = " consigne depression";
x75.topic = " h fonc reduit";
x76.topic = "commande du tirage ";
x77.topic = " h fonc buche";
x78.topic = " WOS etat de fonc";
x79.topic = " depression reelle";
x80.topic = " A de la vis1";
x81.topic = " A de la vis2";
x82.topic = " compteur kg a reset";
x83.topic = " compteur T a reset";
x84.topic = " conso totale pellets ";
x85.topic = " rendement quotidien kw";
x86.topic = " rendement totale kw";
x87.topic = " h avant vider cendrier";
x88.topic = " gestion modbus ";

return [x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,
x11,x12,x13,x14,x15,x16,x17,x18,x19,x20,
x21,x22,x23,x24,x25,x26,x27,x28,x29,x30,
x31,x32,x33,x34,x35,x36,x37,x38,x39,x40,
x41,x42,x43,x44,x45,x46,x47,x48,x49,x50,
x51,x52,x53,x54,x55,x56,x57,x58,x59,x60,
x61,x62,x63,x64,x65,x66,x67,x68,x69,x70,
x71,x72,x73,x74,x75,x76,x77,x78,x79,x80,
x81,x82,x83,x84,x85,x86,x87,x88
];

```

in the absolute I would like to log about 2500 values

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [8 February 2019 20:34 UTC](https://discourse.nodered.org/t/function-with-a-lot-of-output/7752/2 "2019-02-08T20:34:00Z")

</div>

Gulp!

Well, you might find it easier to put everything together in an array of objects and then use node.send() inside a loop.

[https://nodered.org/docs/writing-functions](https://nodered.org/docs/writing-functions)

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [10 February 2019 23:04 UTC](https://discourse.nodered.org/t/function-with-a-lot-of-output/7752/3 "2019-02-10T23:04:23Z")

</div>

What do you do with the messages that leave the function node? Log to a file ? or perhaps display in a dashboard, or maybe build an HTML page, or send to an MQTT node?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 February 2019 08:26 UTC](https://discourse.nodered.org/t/function-with-a-lot-of-output/7752/4 "2019-02-11T08:26:12Z")

</div>

Do you really need to send to 88 outputs rather than a sequence of messages on the one output?  
If you were to declare a const array containing all the fixed topic strings then you could do the rest in a loop sending a message each time round the loop (or if you _do_ need lots of outputs then push them to the output array then send at the end).

---

<div class="post-metadata">

**Author:** ![maccoa](https://avatars.discourse-cdn.com/v4/letter/m/a88e57/32.png) [@maccoa](https://discourse.nodered.org/u/maccoa)\
**Post date:** [11 February 2019 10:55 UTC](https://discourse.nodered.org/t/function-with-a-lot-of-output/7752/5 "2019-02-11T10:55:30Z")

</div>

Thank you for your answers.  
@ TotallyInformation: thanks for "node.send ()" I'm starting to search on it.

@Andrei: you have found, dashboard, log to a base influx and topic mqtt.

here is a screenshot

 ![Capture%20du%202019-02-11%2011-43-43](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7edb390546fff212d90aec974386fb4d96745d09.png)

the 1st function: request to modbus flex getter node

> msg.payload = { value: msg.payload, 'fc': 04, 'unitid': 1, 'address':0, "quantity":100}  
> return msg;

I am a beginner, and it is not always easy to understand the answers for lack of vocabulary

@ Colin : I will also look in this direction.

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [11 February 2019 14:02 UTC](https://discourse.nodered.org/t/function-with-a-lot-of-output/7752/6 "2019-02-11T14:02:04Z")

</div>

Combining what @TotallyInformation and @Colin proposed you will end up with a flow like this one.

The function node would be as simple as they stated:

```auto
for (const [index, element] of msg.payload.data.entries()) {
    node.send({"payload" : element, "topic" : msg.toplist[index]})
}
return msg;

```

Testing flow:

```auto
[{"id":"b25351df.63f5","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"37aa5802.71abd8","type":"debug","z":"b25351df.63f5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":710,"y":100,"wires":[]},{"id":"1c38cd4e.87b5f3","type":"inject","z":"b25351df.63f5","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":100,"wires":[["e94c1d18.09381"]]},{"id":"1a17f4a1.b2f12b","type":"change","z":"b25351df.63f5","name":"Topic List","rules":[{"t":"set","p":"toplist","pt":"msg","to":"[\"Tp4\",\"Tfumé\",\"Tconsol\",\"O2r\",\"posclapO2P\",\"posclapO2S\",\" vitesse ventilateur\",\"sonde1 \",\" temp de fumée conden\",\" sonde retour\",\" m/s ouverture aspi\",\" air primaire\",\" commande du tirage\",\" air secondaire\",\" reglage P chaudière\",\" consigne fumée\",\" regulateur O2\",\" temp module pellets\",\" temp O2 aspiration\",\" A vis extraction\",\" heures de fonctionement\",\" reserve journaliere pellets\",\" nbs demarage bruleur\",\" s4 demarage bruleur\",\" H de fonctionement maintien du feu\",\" alimentation\",\" regul d alimentation\",\" consigne chaudière\",\" sonde accu bas solaire\",\" A vis alimentation\",\" A ecluse a roue cellulaire\",\" stroker\",\" dépression du foyer\",\" pos moteur tiroir\",\"pos moteur grille \",\"regul corection alim \",\" commande des pompes de retour\",\" ventil air de combustion\",\" ventil air de combustion 2\",\" h fonc stroker\",\" h fonc vis alim\",\" h fonc roue celulaire\",\" h fonc vibreur\",\" cycles de fonc grille basculante\",\" h fonc WOS\",\" h vis descendrage\",\" h fonc allumage\",\" h fonc sonde lambda\",\" h fonc turbine aspi\",\" h fonc vis extraction\",\" cycle aeration secu\",\" h fonc tirage\",\" cycle fonc clapet coupe feu\",\" deplacement du clapet tiroir\",\" V sonde lambda\",\" h depuis derniere maintenance\",\" requet via ecs hk\",\" refroidissement foyer par air secondaire\",\" alim limiter sur maxi\",\" augmentation P par regul foyer\",\" pompe prélévement\",\" V sonde lambda coriger\",\" h fonc pellets\",\" h en mode chauffer\",\" sonde de la derivation superieur\",\" sonde de la derivation inf\",\" val consigne retour atteinte\",\" vitesse pompe de chargement chaudiére\",\" sonde large bande A de chauffage\",\" sonde large bande V de chauffage\",\" sonde large bande V rendue\",\" sonde large bande A pompe\",\" slb resistance interne\",\" consigne depression\",\" h fonc reduit\",\"commande du tirage \",\" h fonc buche\",\" WOS etat de fonc\",\" depression reelle\",\" A de la vis1\",\" A de la vis2\",\" compteur kg a reset\",\" compteur T a reset\",\" conso totale pellets \",\" rendement quotidien kw\",\" rendement totale kw\",\" h avant vider cendrier\",\" gestion modbus \"]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":100,"wires":[["54497386.50e0ec"]]},{"id":"e94c1d18.09381","type":"function","z":"b25351df.63f5","name":"mbus","func":"const randomArray = (length, max) => \n Array(length).fill().map(() => Math.round(Math.random() * max))\n\nmsg.payload = {};\nmsg.payload.data = randomArray(88,100);\nreturn msg;","outputs":1,"noerr":0,"x":250,"y":100,"wires":[["1a17f4a1.b2f12b"]]},{"id":"54497386.50e0ec","type":"function","z":"b25351df.63f5","name":"node.send","func":"for (const [index, element] of msg.payload.data.entries()) {\n node.send({\"payload\" : element, \"topic\" : msg.toplist[index]})\n}\nreturn msg;","outputs":1,"noerr":0,"x":570,"y":100,"wires":[["37aa5802.71abd8"]]}]

```
