Easy IoT实现mqtt实验

实验项目:

##实验目的及要求:实现Easy IoT配置、实现Easy IoT上mqtt消息的通讯。
##实验原理:实现mind+下Easy IoT上mqtt消息的通讯。
mind+中程序截图
c++代码

#include <MPython.h>
#include <DFRobot_Iot.h>
// 函数声明
void obloqMqttEventT1(String& message);
// 静态常量
const String topics[5] = {"nYPociKGR","LIsx5mKGR","","",""};
const MsgHandleCb msgHandles[5] = {NULL,obloqMqttEventT1,NULL,NULL,NULL};
// 创建对象
DFRobot_Iot myIot;

// 主程序开始
void setup() {
	mPython.begin();
	myIot.setMqttCallback(msgHandles);
	display.setCursorLine(1);
	display.printLine("连接网络中");
	myIot.wifiConnect("Chuang2", "hc666666");
	while (!myIot.wifiStatus()) {yield();}
	display.setCursorLine(1);
	display.printLine("连接成功");
	myIot.init("iot.dfrobot.com.cn","yVgocmKGg","","sVRociKGgz",topics,1883);
	myIot.connect();
	while (!myIot.connected()) {yield();}
}
void loop() {
	if ((buttonA.isPressed())) {
		myIot.publish(topic_0, "hello");
		display.setCursorLine(2);
		display.printLine("发送成功");
	}
}

// 事件回调函数
void obloqMqttEventT1(String& message) {
	rgb.write(-1, 0x0000FF);
	delay(2000);
	rgb.write(-1, 0x000000);
	display.setCursorLine(3);
	display.printLine(message);
}

实验效果图:

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值