# Optimize Flex Getter

**URL:** <https://discourse.nodered.org/t/optimize-flex-getter/41116>\
**Category:** General\
**Created:** [16 February 2021 19:04 UTC](https://discourse.nodered.org/t/optimize-flex-getter/41116 "2021-02-16T19:04:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benja](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@Benja](https://discourse.nodered.org/u/Benja)\
**Post date:** [16 February 2021 19:04 UTC](https://discourse.nodered.org/t/optimize-flex-getter/41116/1 "2021-02-16T19:04:54Z")

</div>

Hi, i need help again

 ![Captura](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/e/8eb40ea2410b313fe712e53f7bb0fed5d8451be5.jpeg)  
is there a way to leave these 3 function nodes in one?, they are all the same id, different registers.

```auto
msg.payload = { value: msg.payload, 
'fc': 3, 
'unitid': 3, 
'address': 6003,
'quantity': 1 } 
return msg;

msg.payload = { value: msg.payload, 
'fc': 3, 
'unitid': 3, 
'address': 200 ,
'quantity': 10 } 
return msg;

msg.payload = { value: msg.payload, 
'fc': 3, 
'unitid': 3, 
'address': 0 ,
'quantity': 53 } 
return msg;

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 February 2021 19:13 UTC](https://discourse.nodered.org/t/optimize-flex-getter/41116/2 "2021-02-16T19:13:06Z")

</div>

> [@Benja](#):
>
> is there a way to leave these 3 function nodes in one?, they are all the same id, different registers.

Yes...

```auto

node.send({
    payload: {
        'fc': 3,
        'unitid': 3,
        'address': 6003,
        'quantity': 1
    }
});

node.send({
    payload: {
        'fc': 3,
        'unitid': 3,
        'address': 200,
        'quantity': 10
    }
});

node.send({
    payload: {
        'fc': 3,
        'unitid': 3,
        'address': 0,
        'quantity': 53
    }
});

```

HOWEVER - I have seen issues when requesting too much data in quick succession - you might want to put a rate limiter after the function / before the modbus getter

---

<div class="post-metadata">

**Author:** ![Benja](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@Benja](https://discourse.nodered.org/u/Benja)\
**Post date:** [16 February 2021 19:37 UTC](https://discourse.nodered.org/t/optimize-flex-getter/41116/3 "2021-02-16T19:37:09Z")

</div>

```auto
var msg1 = (
    {payload:
    {  
'fc': 3, 
'unitid': 3, 
'address': 0,
'quantity': 1 }
});

var msg2 = ({
    payload:
    {  
'fc': 3, 
'unitid': 3, 
'address': 200 ,
'quantity': 10 }
});

var msg3 = ({
    payload:
    {
'fc': 3, 
'unitid': 3, 
'address': 0 ,
'quantity': 53 }
});

return [msg1, msg2, msg3];

```

I meant something like this,  
finally its working  
thx

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 February 2021 20:43 UTC](https://discourse.nodered.org/t/optimize-flex-getter/41116/4 "2021-02-16T20:43:05Z")

</div>

> [@Benja](#):
>
> I meant something like this,

This code I posted earlier (lets call it VERSION 1)...

```auto
node.send({
    payload: {
        'fc': 3,
        'unitid': 3,
        'address': 6003,
        'quantity': 1
    }
});

node.send({
    payload: {
        'fc': 3,
        'unitid': 3,
        'address': 200,
        'quantity': 10
    }
});

node.send({
    payload: {
        'fc': 3,
        'unitid': 3,
        'address': 0,
        'quantity': 53
    }
});

```

is exactly the same as what you are asking for...

```auto

var msg1 = {
    payload: {
        'fc': 3,
        'unitid': 3,
        'address': 0,
        'quantity': 53
    }
};

var msg2 = {
    payload: {
        'fc': 3,
        'unitid': 3,
        'address': 200,
        'quantity': 10
    }
};

var msg3 = {
    payload: {
        'fc': 3,
        'unitid': 3,
        'address': 0,
        'quantity': 53
    }
};

return [[msg1,msg2,msg3]]

```

**All 3 messages are sent out one after the other.**

If you want a function node with 3 outputs then change the return to `return [msg1,msg2,msg3];`

BUT since you send the outputs of your functions to the same place - there is literally zero point in sending separate outputs. In fact the first version (VERSION 1) that I first posted will guarantee the order of events.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/ab02bb4544a271442bbc0d927ee1dc2ff2fd4818.png)

---

<div class="post-metadata">

**Author:** ![Benja](https://avatars.discourse-cdn.com/v4/letter/b/fbc32d/32.png) [@Benja](https://discourse.nodered.org/u/Benja)\
**Post date:** [16 February 2021 21:15 UTC](https://discourse.nodered.org/t/optimize-flex-getter/41116/5 "2021-02-16T21:15:08Z")

</div>

thax for the explanation, the problem is that I don't know how to separate the arrays after reading the data, that's why I occupy 3 flex nodes.

 ![Captura1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/1/7141567c1c789fc2a6ee2c7f2b5747d67553d0ff.jpeg)  
 ![sub01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/04d934846fc1a3a429f6b8cacad7e55c08cbbc62.jpeg)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 February 2021 21:19 UTC](https://discourse.nodered.org/t/optimize-flex-getter/41116/6 "2021-02-16T21:19:21Z")

</div>

Looking at that code, you look like you could benefit from using [buffer-parser](https://flows.nodered.org/node/node-red-contrib-buffer-parser) (it was designed for taking PLC/Modbus data and making sense of it)

e.g. it turns [2,5,12,55,123,6,1,234,6,3] into

```auto
{
  "temperature": 12.5,
  "humidity": 47.4,
  "speed": 123
}

```

fake data 🙂

---

<div class="post-metadata">

**Author:** ![aderici](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aderici/32/37279_2.png) [@aderici](https://discourse.nodered.org/u/aderici)\
**Post date:** [17 February 2021 00:12 UTC](https://discourse.nodered.org/t/optimize-flex-getter/41116/7 "2021-02-17T00:12:57Z")

</div>

I will suggest something different. I guess you just want to read the registers on a time based interval. For that purose i used cronplus node. Can define different json to be sent on different intervals. Used it for reading modbus tcp.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 April 2021 00:13 UTC](https://discourse.nodered.org/t/optimize-flex-getter/41116/8 "2021-04-18T00:13:08Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
