本帖最后由 Duyuxuan 于 2024-4-18 17:53 编辑
这是c6测评的第二篇,今天我要来教大家用micropython使用mind+可视化面板,学会使用物联网
准备环境
首先先去siot的github下载siot的micropython库
https://github.com/vvlink/SIoT/tree/master
然后去mind+官网下载siotv2的服务端,并升级mind+版本
https://mindplus.dfrobot.com.cn/dashboard
micropython代码编写
- 准备一个wifi热点
- 打开siot服务端
具体siotv2使用方法可以看这里:https://mindplus.dfrobot.com.cn/dashboard
- 获取ip地址填入代码中
from machine import Pin
import time
import network
from siot import iot
ssid="wifi热点名称"
password="wifi密码"
#WiFi连接函数
def wifi_connect():
wlan=network.WLAN(network.STA_IF)
wlan.active(False)
wlan.active(True)
start_time=time.time()
if not wlan.isconnected():
print("connecting to network…")
wlan.connect(ssid,password)
while not wlan.isconnected():
if time.time()-start_time>30:
print("WiFi Connect TimeOut!")
break
if wlan.isconnected():
print("network information:",wlan.ifconfig())
def sub_cb(topic, msg):# 回调函数
print(topic,msg)
wifi_connect()
IOT_UserName = "siot" # 默认账号
IOT_PassWord = "dfrobot" # 默认密码
SERVER = "" # SIoT服务器地址
CLIENT_ID = ""# 设置客户端ID
siot = iot(CLIENT_ID, SERVER,user=IOT_UserName, password=IOT_PassWord)
siot.connect()
print('siot connected')
siot.set_callback(sub_cb)
siot.getsubscribe("siot/button") # 订阅主题
siot.loop()
while True:
siot.check_msg()
for i in range(10):
siot.publish("siot/number",str(i*i))
time.sleep(0.5)
time.sleep(2)
编辑可视化面板与siot的topic
创建siot的topic
编辑可视化面板
具体教程看这里:https://mindplus.dfrobot.com.cn/dashboard
运行试试吧
|