I am a student and need some 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.
- 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
 
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
try:
    s.bind((HOST, PORT))
except socket.error as msg:
    print ('Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1])
    sys.exit()
print ('Socket bind complete')
#Start listening on socket
s.listen(10)
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)
        print(data)
        #print('\x01\x02\x00\x00\x00\x06\x01\x01\x00\x00\x00\x02'))
        #000100000006010300010001
        #000500000006010400000002
        conn.sendall('\x00\x01\x00\x00\x00\x06\x01\x04\x00\x00\x00\x01')
        while True:
            data = conn.recv(100)
            print(data)
            conn.sendall('\x00\x01\x00\x00\x00\x06\x01\x04\x00\x00\x00\x01')
        
        if not data:
            break
        
    #came out of loop
    conn.close()
#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,))
s.close()
after establishing:
<IMEI>
?
?
?
?
req