Добрый день, почему то перестал работать elif, не переходит хотя по условию должно
#!/usr/bin/python3
#coding: utf-8
import paho.mqtt.client as mqtt
import time
import serial
def on_connect(client, userdata, flags, rc):
print("Start controller")
client.subscribe("office/garage_door/state")
client.subscribe("checkout/pass")
client.publish("office/garage_door/state", "C")
def on_message(client, userdata, msg):
print(str(msg.payload))
if (msg.topic) == "office/garage_door/state":
if str(msg.payload) == "b'O'":
port = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=1)
port.write(b'AT\r')
time.sleep(0.5)
print(msg.topic)
port.write(b'ATD0000000000;\r')
time.sleep(10)
port.write(b'AT+CHUP\r')
port.close()
time.sleep(5)
client.publish("office/garage_door/state", "C")
elif (msg.topic) == "checkout/pass":
print(str(msg.payload))
numer = str(msg.payload)[2:14]
print(numer)
pas = str(msg.payload)[15:-1]
print(pas)
pasm = " parol: "
port = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=1)
port.write(b'AT\r')
time.sleep(0.5)
port.write(b'ATZ\r')
time.sleep(0.5)
port.write(b'AT+CMGF=1\r')
time.sleep(0.5)
port.write(b'AT+CMGS="' + numer.encode() + b'"\r')
time.sleep(0.5)
port.write((pasm + pas).encode() + b"\r")
time.sleep(0.5)
port.write(bytes([26]))
time.sleep(0.5)
port.close()
client = mqtt.Client("digi_mqtt_test")
client.on_connect = on_connect
client.on_message = on_message
client.connect('127.0.0.1', 1883)
client.loop_forever()