https://blog.csdn.net/armcsdn/article/details/103131048
流程代码:
[{
"id": "798c173.51be2e8",
"type": "tab",
"label": "流程4",
"disabled": false,
"info": ""
}, {
"id": "60445af9.e992e4",
"type": "mqtt in",
"z": "798c173.51be2e8",
"name": "",
"topic": "Sensor/Temperature/Room1",
"qos": "2",
"datatype": "auto",
"broker": "42208823.88ab68",
"x": 260,
"y": 200,
"wires": [
["ff327446.361ce8"]
]
}, {
"id": "ff327446.361ce8",
"type": "debug",
"z": "798c173.51be2e8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 290,
"y": 300,
"wires": []
}, {
"id": "42208823.88ab68",
"type": "mqtt-broker",
"z": "",
"name": "",
"broker": "127.0.0.1",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
}]
sudo apt-get install mosquitto mosquitto-clients
https://blog.csdn.net/qq_38211852/article/details/80466605
mosquitto_sub -t m -d
mosquitto_pub -t m -m "This is a message from pi."
mosquitto_pub -t Sensor/Temperature/Room1 -m "on"
pip install paho-mqtt
import paho.mqtt.client as mqtt #import the client1
import time
strTime=time.strftime("%H:%M:%S")
#broker_address="127.0.0.1" #在树莓派本机上做试验,请取消本句注释
broker_address="armxu.zicp.vip"#本句是远程试验,需要有花生棒配合
port=39751 #无此条件,请注释这两句
#broker_address="iot.eclipse.org" #use external broker
#connect(host, port=1883, keepalive=60, bind_address="")
client = mqtt.Client("P1") #create new instance
client.connect(broker_address,port) #connect to broker
client.publish("Sensor/Temperature/Room1",strTime)#publish
python3 mqtt_test.py