Skip to content

Modbus ERROR: GatewayPathUnavailable #75

@XavegX367

Description

@XavegX367

Hello, I am having an issue. I am retrieving a value from modbus, with an interval set to a few seconds, but after a few times it randomly returns the error: write EPIPE and after that it returns read: ECONNRESET or: GatewayPathUnavailable. Is there a way to reset the Node server once this happens, because after a restart the function inmediately runs fine again. I don't really know what I am doing wrong, since I am new to Node servers. Here is the code:

const modbus = require('modbus-stream');

module.exports.getClicks = async (req, res, next) => {
    // TODO: readHoldingRegisters
    try {
        modbus.tcp.connect(502, "192.168.250.50", { debug: null }, (err, connection) => {
            if(err) return next(err);

            connection.on("error", (err) => {
                console.log(err.message);
                if(err){
                    return next();
                }

                return JSON.stringify({msg: "Error"});
            })
            connection.readHoldingRegisters({ address: 0, quantity: 124, extra: { unitId: 0 } }, (err, data) => {

                if(data) return res.json(data);
                return JSON.stringify({msg: "Error"});
            })
        });

    } catch(ex) {
        on('error', [ex])
    }

}

Here is the error I am getting, this is over 3 requests:
image

Any help would be appreciated, thanks in advance! :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions