Reputation: 661
I'm trying to connect with Teltonika device (FMB1xx) with this code:
import socket
port = 12050
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', port))
s.listen(1)
conn, addr = s.accept()
print('Connected by ', addr)
imei = conn.recv(1024)
conn.send('\x01')
while True:
try:
data = conn.recv(1024)
if not data: break
print (data)
except socket.error:
print ("Error Occured.")
break
So far I've figured out that conn.send('\x01')
doesn't work as it should, and device don't send the rest of data. There were a few questions like this, but none has a good answer. Here you can find documentation of this device.
Upvotes: 1
Views: 2769
Reputation: 61
like @uglymaxweber mentioned you have pack it as integer(four bytes) and on python3 you can use the built in to_bytes.
byteorder is little or big endian and the first parameter is the bytesize.
response = 5
conn.send(response.to_bytes(4, byteorder = 'big'))
Upvotes: 0
Reputation: 26
It must be encoded and ordered (little-/big-endian) if you sending more then one byte. Use something like this:
conn.send(struct.pack('!L', 1))
About connecting to teltonika gps: https://github.com/Kein1945/GPS_Teltonika_Server/
Upvotes: 1