こんにちは、私は... teltonikaデバイスを読み取って通信するためにPythonでtcpリストナーを書いていますが、imeiコードを受信した後、デバイスに確認を送信しようとすると問題が発生するため、送信されません私のAVLデータ。ここに単純なコードがあります:
#!/usr/bin/env python
import socket
import time
import binascii
#Variables______________________________________#
imei_known = 'XXXXXXXXXXXXXXX'
COM = 0
TCP_IP = '192.168.1.115'
TCP_PORT = 55001
BUFFER_SIZE = 5024
MESSAGE_NO_OK = '00'
MESSAGE_OK = '01'
msg_ok = MESSAGE_OK.encode('utf-8')
msg_no_ok = MESSAGE_NO_OK.encode('utf-8')
#gps elememts (to be review)
long = [0] * 8
lat = [0] * 8
angle = [0] * 4
speed = [0] * 4
sat = [0] * 2
#_____________________________________________________________#
print ('Server listening on port:',TCP_PORT)
print ('\nWaiting for data input from FM1100...')
#socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((TCP_IP, TCP_PORT))
server_socket.listen(5)
client_socket, addr = server_socket.accept()
print ('\nConnection address:', addr)
#infinite loop
while 1:
if COM == 0:
print ('\nCOM num = ',COM)
data = client_socket.recv(BUFFER_SIZE)
imei = data.decode("iso-8859-1")
lista = list(imei)
#vector of 15 elements for IMEI code
lista_2 = [0] * 15
for n in range (0,15):
lista_2 [n] = lista[n+2]
imei=''.join(lista_2)
print ('\nDevice\'s IMEI:', imei)
print ('\nComparing IMEI...')
if imei_known == imei:
print('\nDevice Recognized ')
print('\nSending data to client...')
client_socket.send(b'0x01')
data = ''
else:
client_socket.send(msg_no_ok)
print('\nDevice NOT Recognized')
break
print('\nWaiting for AVL data...')