Using the Arduino library ArduinoModbus.h I am able to read the Holding registers of a Hiking DDS238-2ZN/S power meter with a MKR1010 via TCP but somewhat slowly compared to using a direct Modbus RTU connection to the MKR

The MKR is connected by wifi (-53dbm) to my local router and running TCP Client code based on the example in

The Hiking power meter is connected by a RTU wire pair to a Max RS485 interface then via Serial1 to a Mega 2560 which has a Arduino Ethernet Shield. This is connected to my local router by ethernet cable. The Mega is running Modbus gateway RTU to TCP code from

Before the next read I get the following error message from the MKR

read fail lastError =Connection timed out.

I have tried varying the default TCP timeout in the Client MKR from 30sec to 1sec


The 'last Error' message occurs regardless of the reading frequency ie 2 sec reads, 5 sec reads, so a new attempt to make a TCP connection is made after nearly every read which is usually successful. The data being read is correct but the timing of the reads are not reliable due to the connection timeout delays.

What might be causing the Connection timeout? Can I make the TCP connection persistent? Is the problem in the Client MKR

using the goddland16 library from

This library is much superior to the ArduinoModbus.h library for this modbus device. I can read the Hiking power meter every 2secs.

It works just as well as on TCP/Ethernet or TCP/WiFi with the Master/Client running the goddland16 code on a MKR1010 board. The TCP connection is re-established for each register read cycle. The next issue is to improve the stability of the TCP/RTU gateway which has a tendency to crash at high data read rates.