3
Hy,在這裏我是... 我正在寫一個tcp listner在python中閱讀和與teltonika設備進行通信,但我在收到imei代碼後遇到問題,我嘗試發送akcnowledgment到設備,所以它不會向我發送AVL數據。 這裏是一個簡單的代碼:Teltonika FM1100和TCP列表
#!/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...')
嘿,你知道了嗎?我有同樣的問題,下面的答案('\ x01')不適合我。它只是繼續發送IMEI。 – 2016-03-14 02:26:49