材料:掌控版
软件:mind+
实验开始需要到easy lot平台注册账号;
#include <MPython.h>
#include <DFRobot_Iot.h>
// 函数声明
void obloqMqttEventT1(String& message);
// 静态常量
const String topics[5] = {"A6PTslOMg","yWjyw_dGR","","",""};
const MsgHandleCb msgHandles[5] = {NULL,obloqMqttEventT1,NULL,NULL,NULL};
// 创建对象
DFRobot_Iot myIot;
// 主程序开始
void setup() {
mPython.begin();
myIot.setMqttCallback(msgHandles);
myIot.wifiConnect("lzx", "lzx.123456");
while (!myIot.wifiStatus()) {yield();}
display.setCursorLine(1);
display.printLine(myIot.getWiFiLocalIP());
myIot.init("iot.dfrobot.com.cn","W1w5y_dGg","","ZJw5y_dGgz",topics,1883);
myIot.connect();
while (!myIot.connected()) {yield();}
display.setCursorLine(2);
display.printLine("MQTT连接成功");
}
void loop() {
myIot.publish(topic_0, "qqqq");
}
//