This commit is contained in:
xyj 2024-01-02 11:37:17 +08:00
parent f64b804a7d
commit 9883fff26a
1 changed files with 3 additions and 5 deletions

View File

@ -20,17 +20,15 @@ class MQTTClient:
self.client = mqtt.Client() self.client = mqtt.Client()
self.client.username_pw_set(self.username, self.password) self.client.username_pw_set(self.username, self.password)
async def push(self): def push(self):
self.client.publish(self.topic, payload=json.dumps({"msg": "open_led"}, ensure_ascii=False), self.client.publish(self.topic, payload=json.dumps({"msg": "open_led"}, ensure_ascii=False),
qos=0) qos=0)
await asyncio.sleep(10)
self.client.publish(self.topic, payload=json.dumps({"msg": "push_stream"}, ensure_ascii=False), self.client.publish(self.topic, payload=json.dumps({"msg": "push_stream"}, ensure_ascii=False),
qos=0) qos=0)
async def close(self): def close(self):
self.client.publish(self.topic, payload=json.dumps({"msg": "close_stream"}, ensure_ascii=False), self.client.publish(self.topic, payload=json.dumps({"msg": "close_stream"}, ensure_ascii=False),
qos=0) qos=0)
await asyncio.sleep(10)
self.client.publish(self.topic, payload=json.dumps({"msg": "close_led"}, ensure_ascii=False), self.client.publish(self.topic, payload=json.dumps({"msg": "close_led"}, ensure_ascii=False),
qos=0) qos=0)
@ -93,4 +91,4 @@ def close_stream(username, device):
if __name__ == '__main__': if __name__ == '__main__':
broker = 'mqtt.lihaink.cn' broker = 'mqtt.lihaink.cn'
port = 1883 port = 1883
uvicorn.run(app, host="127.0.0.1", port=8001) uvicorn.run(app, host="127.0.0.1", port=8002)