提交 5eaa27f0 authored 作者: 郑晓兵's avatar 郑晓兵

更新数据

上级 4cc16d1b
# -*- coding: utf-8 -*-
# cython: language_level=3
import json
import paho.mqtt.client as mqtt
# 创建MQTT客户端
client = mqtt.Client(protocol=mqtt.MQTTv311)
# 连接服务器
broker_address = "192.168.5.215"
port = 1883
client.connect(broker_address, port)
# 发布消息
topic = "/maintain/room/master/client/"
cliet_udid = '79ac2430-6a98-5509-9e99-65b974eb70a1'
message = {
"action": "_updatemaster",
"client_udid": cliet_udid,
"data": [
{
"item": "environmental",
"pm25": 0,
"co2": 0,
"temp": 0,
"tvoc": 0,
"humi": 0,
"hcho": 0
},
{
"item": "conference",
"power": 0,
"exist": 1,
"run": "hello world"
}]
}
client.publish(topic, json.dumps(message), qos=0)
# 断开连接
client.disconnect()
# -*- coding: utf-8 -*-
# cython: language_level=3
import json
import paho.mqtt.client as mqtt
# 创建MQTT客户端
client = mqtt.Client(protocol=mqtt.MQTTv311)
# 连接服务器
broker_address = "192.168.5.215"
port = 1883
client.connect(broker_address, port)
# 发布消息
cliet_udid = '3d53149e-408f-56c6-99ef-29fae67f8efc'
topic = "/maintain/room/online/" + cliet_udid + "/"
message = {
"udid": cliet_udid,
"action": "online",
"value": 1
}
client.publish(topic, json.dumps(message), qos=0)
# 断开连接
client.disconnect()
# -*- coding: utf-8 -*-
# cython: language_level=3
import json
import paho.mqtt.client as mqtt
# 创建MQTT客户端
client = mqtt.Client(protocol=mqtt.MQTTv311)
# 连接服务器
broker_address = "192.168.5.215"
port = 1883
client.connect(broker_address, port)
# 发布消息
topic = "/maintain/room/master/client/"
cliet_udid = '3d53149e-408f-56c6-99ef-29fae67f8efc'
device_udid = '03283caf-e6fd-5866-b39d-917fe16bb713'
message = {
"action": "_updatestatus",
"client_udid": cliet_udid,
"data": [
{
"device_udid": device_udid,
"power": 1,
"online": 1,
"run": "run test",
"watt": 100,
"bulbtime": 9
}]
}
client.publish(topic, json.dumps(message), qos=0)
# 断开连接
client.disconnect()
# -*- coding: utf-8 -*-
# cython: language_level=3
import paho.mqtt.client as mqtt
cliet_udid = '3d53149e-408f-56c6-99ef-29fae67f8efc'
topic = "/maintain/room/master/" + cliet_udid + "/"
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe(topic)
def on_message(client, userdata, msg):
print(f"Received message '{msg.payload.decode()}' on topic '{msg.topic}'")
mqtt_client = mqtt.Client()
mqtt_client.on_connect = on_connect
mqtt_client.on_message = on_message
mqtt_client.connect("192.168.5.215", 1883, 60)
mqtt_client.loop_forever()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论