Mind+ Eas_IoT
图形化
Arduino C代码
#include <MPython.h>
#include <DFRobot_Iot.h>
void obloqMqttEventT0(String& message);
void DF_WiFiZhongLianJiZhi();
void DF_MQTTZhongLianJiZhi();
void DF_JieMian();
const MsgHandleCb msgHandles[5] = {obloqMqttEventT0,NULL,NULL,NULL,NULL};
const String topics[5] = {"Qq_qcBjZR","l0NalW7GR","","",""};
DFRobot_Iot myIot;
void setup() {
myIot.setMqttCallback(msgHandles);
mPython.begin();
myIot.wifiConnect("DESKTOP-RS229GR 3737", "19990327");
display.setCursorLine(1);
display.printLine("正在连接网络...");
while (!myIot.wifiStatus()) {yield();}
display.fillInLine(1, 0);
display.setCursorLine(1);
display.printLine("网络已连接");
display.setCursorLine(2);
display.printLine("IP:");
display.setCursorLine(3);
display.printLine(myIot.getWiFiLocalIP());
myIot.init("iot.dfrobot.com.cn","US5XFBCWg","","UI5uFBCZRz",topics,1883);
display.setCursorLine(4);
display.printLine("正在连接MQTT...");
myIot.connect();
while (!myIot.connected()) {yield();}
display.fillInLine(4, 0);
display.setCursorLine(4);
display.printLine("MQTT已连接");
}
void loop() {
DF_WiFiZhongLianJiZhi();
DF_MQTTZhongLianJiZhi();
if ((buttonA.isPressed())) {
while (!(!buttonA.isPressed())) {yield();}
myIot.publish(topic_1, "黄雯 2018A14102");
}
else if ((buttonB.isPressed())) {
while (!(!buttonB.isPressed())) {yield();}
DF_JieMian();
}
}
void DF_WiFiZhongLianJiZhi() {
if ((!myIot.wifiStatus())) {
myIot.wifiConnect("DESKTOP-RS229GR 3737", "19990327");
while (!myIot.wifiStatus()) {yield();}
}
}
void DF_MQTTZhongLianJiZhi() {
if ((!myIot.connected())) {
myIot.connect();
while (!myIot.connected()) {yield();}
}
}
void DF_JieMian() {
display.fillScreen(0);
if (myIot.wifiStatus()) {
display.setCursorLine(1);
display.printLine("网络已连接");
}
else {
display.setCursorLine(1);
display.printLine("网络已断开");
}
display.setCursorLine(2);
display.printLine("IP:");
display.setCursorLine(3);
display.printLine(myIot.getWiFiLocalIP());
if (myIot.connected()) {
display.setCursorLine(4);
display.printLine("MQTT已连接");
}
else {
display.setCursorLine(4);
display.printLine("MQTT已断开");
}
}
void obloqMqttEventT0(String& message) {
display.fillScreen(0);
display.setCursorLine(1);
display.printLine("收到新的MQTT消息:");
display.setCursorLine(2);
display.printLine(message);
}