如何使用 python Paho-MQTT lib 在使用 RGB 值的谨慎 Tasmota Tuya 灯泡上设置颜色。我尝试将灯泡设置为订阅者,将我的计算机设置为发布者。
import paho.mqtt.client as mqtt
import time
#broker info
broker_address="driver.cloudmqtt.com"
port=18773
user="jpwcqbpz"
password="hlgPE3uvAND9"
# This is Tasmota Tuya bulbs color comands
acolor = (255,0,0)
bcolor = (0, 255 , 0)
ccolor = (0,0,255)
violet = (128, 0, 128)
connected=False
Messagerecieved=False
client=mqttclient.Client("MQTT")
client.username_pw_set(user,password=password)
client.on_connect=on_connect
client.connect(broker_address,port=port)
client.loop_start()
client.subscribed("mqtt/secondcode")
while True:
client.publish("LEDTEST", violet)
#print("Just published " + str(violet) + " to Topic LEDTEST")
time.sleep(1)
while Messagerecieved!=True:
time.sleep(0.2)
client.loop_stop()