我尝试通过GSM在Raspberry pi上学习家庭自动化系统,但不幸的是,我的python编码出现错误。
问题是,当我想打印收到的消息时,我得到这种响应b'b \ xf1 \ xe2 \ xe2 \ xe2',
因此,我无法解码该消息,如果我解码该python,则会给我一个错误,如无序类型:int() 所以,我对此感到很困惑,有人可以帮助我解决这个问题,我该如何匹配我的实际信息并打印? 这是我的代码及其输出。 ``import serial
import time
import os
print('Welcome to Test GSM SIM900')
ser = serial.Serial ("/dev/ttyS0", 19200, timeout=1) #9600 is the default for SIM900A modem
print('Waiting for Response')
ser.write(('AT+CMGF=1' + '\r').encode('utf-8'))
time.sleep(1)
print('Connection Establish')
ser.write(('AT+CMGDA="DEL ALL"'+'\r').encode('utf-8'))
time.sleep(1)
print('All messages has been Deleted')
message = ser.read(1000) # inWaiting- get the number of bytes in the inout buffer
print(message)
while True:
if message == 'LED1':
print ("LED 1 is on")
elif message == 'LED2':
print ("LED 2 is on")
elif message == 'EXIT':
print ("shuting down")
ser.close ()
break
else:
print ("Try again")
break
ser.close() #close the serial port
>>> %Run GSMTRY.py
Welcome to Test GSM SIM900
Waiting for Response
Connection Establish
All messages has been Deleted
b'b\xf1\xe2\xe2\xe2'
Try again
>>>