Modbus flex-server ECONNREFUSE

I have a server with a modbus-contrib-flex-getter that reads from another server Modbus-contrib-flex-server.

Regularly (once or twice a day, cant see a pattern to it) I get an error "ECONNREFUSED" from the server that hosts the getter.

Sometimes it is enough to redeploy the flex-server node-red, but sometimes I have to disable the flex-server node and enable it again.

The inject for inserting buffer into flex-server is set 100ms apart.I don't know if that matters anything though.

Node-red V4.0.2 (flex-server host)
Flex-server V1.0.1


This looks awfully complex - and possibly not necessary. The loops are certainly not recommended. What is this doing? Perhaps you could share this part of the flow?

I forgot to include the inject node that starts the flow. It is set to every 10sec.

Function 300:
First the flow sets up a request object and prepares some influx data.

const fields = context.get("Input")

msg.payload = {
    'fc': 4,
    'unitid': 1,
    'address': 0,
    'quantity': fields.length
}

msg.influxObj = {
    Temperature: {},
    SetValues: {},
    Status: {},
    Alarms: {},
    PointAlarms: {}
}

msg.fields = fields

msg.trip = 1

return msg;

The flow then goes to the getter.
The switch node receives the payload from the getter and sends the flow on where msg.trip is equal to 1.
The next function node then process the data and makes another request object.

const obj = {}
const fields = msg.fields

msg.payload.data.forEach((data, index) => {
    if(fields[index].field == "PID effect") {
        obj[fields[index].field] = data
        return
    }
    obj[fields[index].field] = Number(calculateFromRawValueMA(data).toFixed(1))
})

msg.influxObj.Temperature = obj

msg.fields = context.get("Holding")

msg.payload = {
    'fc': 3,
    'unitid': 1,
    'address': 0,
    'quantity': msg.fields.length
}

msg.trip = 2

return msg;

function calculateFromRawValueMA(mA) {
    // 4-20mA signal
    // -50 to 150 range
    const PvHigh = 150 // Process value high
    const PvLow = -50 // Process value low
    const Ihigh = 20000 // mA high
    const Ilow = 4000 // mA low
    const I = parseInt(mA) // Amp/Process value

    const Pv = (PvHigh - PvLow)/(Ihigh - Ilow)*(I-Ilow)+PvLow // Process value
    return Pv
}

Then the flow goes to a 100ms delay to the getter.
This repeats itself until the end, where all the data is formatted pr influxdb standard and sent to influx.

The reason for the number of loops is requesting between different modbus functions and some of them because of several thousands difference in modbus addresses in the same modbus function...
if that makes any sense.

Best regards
Steffen

Hi Steve.

How would you divide the differences in modbus function(coil, register etc) if not like this?

Best regards
Steffen

Before I can suggest any architectural change, I need to ask, are you using modbus as a means of sharing data between different node-red instances?

Based on your opening statement:

I have a server with a modbus-contrib-flex-getter that reads from another server Modbus-contrib-flex-server

It looks like that is the case. And if this is purely for node-red to node-red communication, there are far better ways to achieve this. Please appreciate that I don't have all of your details or end goal so it might be totally necessary. Please clarify.

I am using node-red as a modbus client in this example. But that's for testing purposes only.

My device uses node-red, flex-server.
As a communication protocol the requirement is modbus TCP/IP.
In a production environment some form of modbus client is used. Not Node-red.

Best regards
Steffen

As far as I know, it is not normal (or possible) to make requests across different function codes in one request.

I could make multiple requests at the same time. That is, not waiting for one request to finish before I make another one. In that way I would not need a loop like I'm using now.
I thought that a loop was the way to go. Would you rather make request at the same time?
Like requesting a data block in the holding register from address 1000 - 1080.
And at the same time request some coils from 500 - 550.
And some Input register from 0 - 60.

The modbus contrib flex getter takes care of this for me?

Best regards
Steffen

I had my Node-red editor open when the error occurred today.
The error is:
"Error: read ECONNRESET". This is outputed by the flex-server node.
I have an error Catch node attached to the flex-server, but the error was not catched by the Catch node.

For the client node-red to be able to get responses from modbus requests I had to redeploy the node-red where the flex-server resides.

Everything else works. Just the flex-server that doesn't respond.

Best regards
Steffen