This commit is contained in:
xyj 2024-03-05 11:19:15 +08:00
parent 82db1cb13b
commit 9069783f8b
1 changed files with 6 additions and 0 deletions

View File

@ -26,6 +26,7 @@ class MQTTClient:
self.client = mqtt.Client(client_id=subscribe_topic) self.client = mqtt.Client(client_id=subscribe_topic)
self.client.username_pw_set(self.username, self.password) self.client.username_pw_set(self.username, self.password)
self.client.on_connect = self.on_connect self.client.on_connect = self.on_connect
self.client.on_disconnect = self.on_disconnect
self.client.on_message = self.on_message self.client.on_message = self.on_message
def on_connect(self, client, userdata, flags, rc): def on_connect(self, client, userdata, flags, rc):
@ -33,8 +34,13 @@ class MQTTClient:
self.client.subscribe(self.topic) self.client.subscribe(self.topic)
client.publish(info_topic, payload=publish_payload(code=200, msg='成功订阅' + self.topic), client.publish(info_topic, payload=publish_payload(code=200, msg='成功订阅' + self.topic),
qos=0) qos=0)
print("连接")
subprocess.Popen(['/bin/bash /home/pi/agri_xumu/bash/start_push_stream.sh'], shell=True) 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): def on_message(self, client, userdata, msg):
if not valid(msg, client): if not valid(msg, client):
return return