当前位置:   article > 正文

Easy IoT实现mqtt实验_esp32 连接 easyiot

esp32 连接 easyiot

Easy IoT实现mqtt实验(该博客主要记录本人物联网课程的实验报告)

一、实验目的及要求

【实验一】实现Easy IoT配置。
【实验二】实现Easy IoT上mqtt消息的通讯。

二、实验原理与内容

实现mind+下Easy IoT上mqtt消息的通讯。

三、实验软硬件环境

硬件:掌控板
软件:Mind+

四、实验过程(实验步骤、记录、数据、分析)

1.在Easy loT平台上注册账号

2.登录Easy loT平台,点击工作间并创建两个设备

在这里插入图片描述

3.打开Mind+软件,切换到上传模式,并在扩展中选择ESP32主控板,MQTT,WIFI网络服务。将电脑与ESP32掌控板连接后,选择合适的模块进行操作

在这里插入图片描述
代码:

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


// 主程序开始
void setup() {
	mPython.begin();
	myIot.setMqttCallback(msgHandles);
	myIot.wifiConnect("602iot", "18wulian");
	while (!myIot.wifiStatus()) {yield();}
	display.setCursorLine(1);
	display.printLine("wifi连接成功");
	myIot.init("iot.dfrobot.com.cn","wO6DlslGR","","QOeD_slGRz",topics,1883);
	myIot.connect();
	while (!myIot.connected()) {yield();}
	display.setCursorLine(2);
	display.printLine("MQTT连接成功");
}
void loop() {
	if ((buttonA.isPressed())) {
		display.setCursorLine(3);
		display.printLine("按下A键");
		myIot.publish(topic_0, "A");
	}
	if ((buttonB.isPressed())) {
		display.setCursorLine(3);
		display.printLine("按下B键");
		myIot.publish(topic_1, "B");
	}
}


// 事件回调函数
void obloqMqttEventT0(String& message) {
	display.setCursorLine(4);
	display.printLine(message);
	rgb.write(-1, 0xFFFF00);
}
void obloqMqttEventT1(String& message) {
	display.setCursorLine(4);
	display.printLine(message);
	rgb.write(-1, 0xFF0000);
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57

4.在MTQQ初始化参数中添加Easy lot中自己的账号密码以及设备

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

5.对掌控板进行测试

1.等待掌控板WIFI连接、和MQTT连接

在这里插入图片描述

2.连接成功后,按下掌控板的A键,将在掌控板显示“发”,并将消息“A”发送给Easy loT的topic0;topic0接收到消息后,将该消息内容显示在掌控板上,同时将掌控板的所有灯的颜色变为黄色。(按下B键与按下A键的功能相似)

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

五、测试/调试及实验结果分析

登录Easy loT平台,点击查看topic0和topic1的消息详情,验证是否接收到Mind+发送的消息。
在这里插入图片描述
在这里插入图片描述
实验结果无误。

六、实验结论与体会

通过这次实验,我初次体会到了通过掌控板和云平台的连接互动,初步体会到互联网的魅力。在实验过程中,需要特别主要的地方是MQTT的连接,填写的参数必须要和自己Easy loT平台的一样。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/正经夜光杯/article/detail/897767
推荐阅读
相关标签
  

闽ICP备14008679号