0

Background info:

I am trying to read data from my energy meter. I have connected a gprs modem to the meter(via rs485) port. This modem sends data via tcp-ip protocol to a specified server and port. On the server(aws ec2 instance) I can see a connection from the device.

Question:

When i try to connect to this device using PyModbus, i am unable to open connection.

from pymodbus.client.sync import ModbusTcpClient as Modbusclient
client= Modbusclient(host=<internal ip of the connection>, port=5025)
if client.connect():
    print("Connected")
else:
    print("Not Connected")

The response is always "Not Connected".

I have ensured that a) the port is open. b) ip address is whitelisted on the server

Why can't i connect? What am i missing here?

iamjoebloggs
  • 46
  • 1
  • 8
  • Are you sure the port being used is correct? Try reading a couple of registers and see what error it will throw. – Sanju May 28 '18 at 11:44
  • The port was correct. I tried reading registers and got the same error i.e. client not connected. The problem was somewhere else – iamjoebloggs Jun 05 '18 at 09:09

1 Answers1

0

In my particular case, the gprs modem was acting as a serial-over-tcp gateway.So i had to create a serial port and then connect to it. What i ended up doing was:

  1. Create a pair of serial ports (e.g. p1 and p2) on Linux using socat command
  2. Create a simple tcp listener (using sockets library in python)
  3. Forward all data from tcp port to p1
  4. Import ModbusSerialClient from pymodbus.client.sync
  5. connect to P2 using Modbus Serial Client.
iamjoebloggs
  • 46
  • 1
  • 8