Optimize Flex Getter

Hi, i need help again


is there a way to leave these 3 function nodes in one?, they are all the same id, different registers.

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;

Yes...


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

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

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

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...


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.

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.


Looking at that code, you look like you could benefit from using 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

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

fake data :slight_smile:

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.

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