Cloud-Automation / node-modbus

Modbus TCP Client/Server implementation for Node.JS
467 stars 174 forks source link

TEST CONNECTION ON MY RASPBERRY PI #274

Closed libanj closed 3 years ago

libanj commented 3 years ago

I have a Modbus server running on my raspberry pi. I would like to connect to my server running on my raspberry pi device while making my laptop act as the gateway(client). I simply just want to establish a connection. Currently, my raspberry pi is running Modbus on node-red.

libanj commented 3 years ago

I managed to get the client listening to my server. I still have one issue.

My register is not being read in real-time

socket.on('connect', () => {
    console.log("CONNECTED");
    client.readHoldingRegisters(3000, 1).then( (resp) => { console.log(resp.response.body.values); }, console.error);

});

I have to keep restarting the app in order to read the next value from the register.

stefanpoeter commented 3 years ago

Well, you only made one request on connect, what do you expect should happen? If you want to read data periodically wrap your request in a setInterval call.

libanj commented 3 years ago

to be honest, I just simply assumed that the .readHoldingRegister() would do the update for me in real-time and that there was some established "best practice" way of going about it with this library. I was thinking too simplistic.