modbus tcp with king pigeon RTU5026

hi and regards from germany,

iam a student and need thome help for programming a simplest modbus tcp server to get values from a GSM/gprs device like RTU5026 or RTU5023 from king pigeon. This device supports communication with modbus RTU over tcp or modbus tcp. I think modbus tcp is that, what I need.

With this product is a small manual manual. I think I found the most important information:
- modbus tcp is supported (and I enabled it with my own connection details to get a connection with the tcp server)
- register address: 0 (holds temperature)
- data type: 16 bit
- function code: 4

With the following python script, I get an established and holding registration, but I cant ask or poll the register address with the temperature. I think I need help for communcation AND modbus request. Thanks a lot !!!

- at first I got the Welcome Message after establishing, that is the IMEI - perfect
- second step is the request and reading, but the answer is still "?"
- every minute I get a heartbeat message "req" - perfect

Anybody some ideas?


import socket
import sys
from thread import *

HOST = ''    # Symbolic name meaning all available interfaces
PORT = 6655    # Arbitrary non-privileged port

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print ('Socket created')

#Bind socket to local host and port
    s.bind((HOST, PORT))
except socket.error as msg:
    print ('Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1])
print ('Socket bind complete')

#Start listening on socket
print ('Socket now listening')

#Function for handling connections. This will be used to create threads
def clientthread(conn):
    #Sending message to connected client
    conn.send('Welcome to the server. Type something and hit enter\n') #send only takes string
    #infinite loop so that function do not terminate and thread do not end.
    while True:
        #Receiving from client
        data = conn.recv(15)
        while True:
            data = conn.recv(100)
        if not data:
    #came out of loop

#now keep talking with the client
while 1:
    #wait to accept a connection - blocking call
    conn, addr = s.accept()
    print ('Connected with ' + addr[0] + ':' + str(addr[1]))
    #start new thread takes 1st argument as a function name to be run, second is the tuple of arguments to the function.
    start_new_thread(clientthread ,(conn,))

The King Pigeon device is a Modbus/TCP server. You need to develop a Modbus/TCP client to read registers from the King Pigeon device.

I suggest taking a look at this python library:

Note that some Modbus devices use 1-based register addressing, and others (like the King Pigeon) use 0-based register addressing. Therefore, you may need to add 1 to the register address.

As a first test, you can try using one of the following Modbus client simulators on your computer to confirm you can communicate with the King Pigeon device via Modbus/TCP:


Simply Modbus

Modbus Poll