-
看到这样一篇新闻 easyIot
-
在网站注册申请id,连接不上
image.png
-
使用微信小程序,尝试了一下,居然很顺利地实现了数据的上传和受控
image.png

- 说明:
- 每个设备都有id
- iot_id
- iot_password
- topic,根据topic可以将数据上传,数值显示
- 绑定了ID,平台不能支持多用户接入
- 需要一个host:使用的是 iot.dfrobot.com.cn
-
大致的结构为
arch
- 每个设备都有id
测试 client + publisher
#! coding:utf-8
# import paho.mqtt.client as mqtt
# import paho.mqtt.publish as publish
# import time
# HOST = "iot.dfrobot.com.cn"
# PORT = 1883
# def on_connect(client, userdata, flags, rc):
# print("Connected with result code "+str(rc))
# client.subscribe("S1A6izaV7")
# def on_message(client, userdata, msg):
# print(msg.topic+" "+msg.payload.decode("utf-8"))
# if __name__ == '__main__':
# client_id = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
# # client_id = "0a7be3efd36c4b89"
# client = mqtt.Client(client_id) # ClientId不能重复,所以使用当前时间
# client.username_pw_set("S1bkfDf6E7", "ryGkzvfTEX") # 必须设置,否则会返回「Connected with result code 4」
# client.on_connect = on_connect
# client.on_message = on_message
# client.connect(HOST, PORT, 60)
# client.publish("S1m7vf6VQ", "你好 sdfasf", qos=1, retain=False) # 发布消息
# publish.single("S1A6izaV7",
# "你好 MQTT",
# qos = 1,
# hostname=HOST,
# port=PORT,
# client_id=client_id,
# auth = {'username':"Hy1xemaNX", 'password':"BJxJgxmTE7"})
# publish.single("S1m7vf6VQ",
# "你好 MQTT",
# qos = 1,
# hostname=HOST,
# port=PORT,
# client_id=client_id,
# auth = {'username':"S1bkfDf6E7", 'password':"ryGkzvfTEX"})
import paho.mqtt.client as mqtt
import time
# from import mrq.MRQ import *
from mrq.sinanju import *
HOST = "iot.dfrobot.com.cn"
PORT = 1883
def client_loop():
client_id = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
# client_id = "0a7be3efd36c4b89"
client = mqtt.Client(client_id) # ClientId不能重复,所以使用当前时间
client.username_pw_set("S1bkfDf6E7", "ryGkzvfTEX") # 必须设置,否则会返回「Connected with result code 4」
client.on_connect = on_connect
client.on_message = on_message
client.connect(HOST, PORT, 60)
client.loop_forever()
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe("S1m7vf6VQ")
def on_message(client, userdata, msg):
print(msg.topic+" "+msg.payload.decode("utf-8"))
robo = Sinanju("mrx-t4")
robo.send( msg.payload.decode("utf-8") )
robo.close()
if __name__ == '__main__':
client_loop()
网友评论