2020-10-12
实现sIoT配置并实现sIoT上mqtt消息的通讯
-
先下载slot,下载便可直接使用.exe(会出现防火墙提示,请允许)
-
到浏览器打开127.0.0.1:端口(这个端口号可在下载slot的config.josn文件有,包括用户和密码,请查看config.josn文件)然后到下图界面
-
登录并创建Topic
-
回到mind+写代码,代码如下:
注意在连接WiFi是需要2.4G频率的(由于控制板版本的原因),并让设备在同一局域网中,在连接WiF连接成功后可以在掌控板显示“WiFi is OK!”确认WiFi已经连接成功。
注意注意在初始化MQTT时,物联网平台选项选slot,服务器地址是本电脑的IP地址…在MQTT初始化并发起连接成功时,也可以在掌控板显示“MQTT连接成功!”确认MQTT连接成功。 -
实验结果截图:.
所发送的信息也可在slot查看
-
代码:
/*!
* MindPlus
* mpython
*
*/
#include <MPython.h>
#include <DFRobot_Iot.h>
// 静态常量
const String topics[5] = {"2018764120/罗威","2018764128/李汉源","","",""};
// 创建对象
DFRobot_Iot myIot;
// 主程序开始
void setup() {
mPython.begin();
myIot.wifiConnect("ach3", "09876543210");
while (!myIot.wifiStatus()) {yield();}
display.setCursorLine(2);
display.printLine("连接成功");
display.setCursorLine(1);
display.printLine(myIot.getWiFiLocalIP());
myIot.init("192.168.137.228","602","","iot", topics, 1883);
myIot.connect();
while (!myIot.connected()) {yield();}
display.setCursorLine(3);
display.printLine("mqtt连接成功");
}
void loop() {
if ((buttonA.isPressed())) {
myIot.publish(topic_1, "2018764120罗威");
display.setCursorLine(4);
display.printLine("发送成功");
}
}