Mind+ Easy_IoT

Mind+ Eas_IoT

图形化

在这里插入图片描述

Arduino C代码

/*!
 * MindPlus
 * mpython
 *
 */
#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);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Simply myself

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值