diff --git a/MQTT.py b/MQTT.py index fde5136..75d0fb0 100644 --- a/MQTT.py +++ b/MQTT.py @@ -26,6 +26,7 @@ class MQTTClient: self.client = mqtt.Client(client_id=subscribe_topic) self.client.username_pw_set(self.username, self.password) self.client.on_connect = self.on_connect + self.client.on_disconnect = self.on_disconnect self.client.on_message = self.on_message def on_connect(self, client, userdata, flags, rc): @@ -33,8 +34,13 @@ class MQTTClient: self.client.subscribe(self.topic) client.publish(info_topic, payload=publish_payload(code=200, msg='成功订阅' + self.topic), qos=0) + print("连接") subprocess.Popen(['/bin/bash /home/pi/agri_xumu/bash/start_push_stream.sh'], shell=True) + def on_disconnect(self, client, userdata, flags, rc): + print("断开") + subprocess.Popen(['/bin/bash /home/pi/agri_xumu/bash/stop_push_stream.sh'], shell=True) + def on_message(self, client, userdata, msg): if not valid(msg, client): return