4

嗨,我在这里......我正在用 python 编写一个 tcp 侦听器来读取和与 teltonika 设备通信,但是在收到 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...')
4

1 回答 1

3

您必须以十六进制回复 FM1100。像这样:

client_socket.send('\x01')
于 2013-12-28T11:57:14.737 回答