2018年11月7日12:22:13
环境:
Ubuntu 18.04
Python 3.6
1、安装第三方库
pip install paho-mqtt
2、代码如下
参考资料: https://www.cnblogs.com/nulige/p/8993719.html
server_study.py
import paho.mqtt.client as mqtt
import paho.mqtt.publish as publish
import time
idx = 0 # 往paho/temperature 一直发送内容
while True:
print("send success")
publish.single("paho/temperature",
payload="this is message:%s" % idx,
hostname="localhost",
client_id="lora1",
# qos = 0,
# tls=tls,
port=1883,
protocol=mqtt.MQTTv311)
idx = 1
time.s