Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
提取SMS正文并在条件中传递(Python)_Python_Serialization_Serial Port - Fatal编程技术网

提取SMS正文并在条件中传递(Python)

提取SMS正文并在条件中传递(Python),python,serialization,serial-port,Python,Serialization,Serial Port,这是我用来检查未读邮件的类 def CheckUnreadMsgs(ser) print "Check for new messages...\n" ser.write("AT\r") time.sleep(3) line = ser.read(size = 64) print line sen.write('AT+CMGL="REC UNREAD"\r') time.sleep(3) response = ser.read(size =200) prin

这是我用来检查未读邮件的类

 def CheckUnreadMsgs(ser)
  print "Check for new messages...\n"
  ser.write("AT\r")
  time.sleep(3)
  line =  ser.read(size = 64)
  print line
  sen.write('AT+CMGL="REC UNREAD"\r')
  time.sleep(3)
  response = ser.read(size =200)
  print response
  return response
这是主要节目

print "Opening communications serial...\n"
ser = serial.Serial('/dev/ttyUSB1',115200,timeout=1)
ser.open()
#check continous loop
print "Starting main loop\n"

while True:
  message = CheckUnreadMsgs(ser)
  a = message.find('\n') + 63
  b = len(message)
  msg = message[a:b]
  print msg
  if (msg == "on")
    print "Power ON Commanded!\n"
我已经提取了SMS的主体,但是如果msg==on,变量似乎没有通过条件。你能帮我解决这个问题吗?

这是我用正则表达式给出的答案


这是菲律宾的电话国家代码。
print "Opening communications serial...\n"
ser = serial.Serial('/dev/ttyUSB1',115200,timeout=1)
ser.open()
#check continous loop
print "Starting main loop\n"

while True:
  message = CheckUnreadMsgs(ser)
  a = message.find('\n') + 63
  b = len(message)
  msg = message[a:b]
  m = re.search("(pow.*)",msg)
  if m:
      mm = (m.group(1))
      if "on" in mm:
         print "Power On"
      elif "off" in mm:
         print "Power Off"