材料:掌控版
软件:mind+
实验开始需要到easy lot平台注册账号;
复制代码
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#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"); } // 事件回调函数 void obloqMqttEventT1(String& message) { display.setCursorLine(3); display.printLine(message); }
实验结果:
总结:这次实验操作难度不大,但应该理解这一种发送与接收的模式关系
最后
以上就是简单招牌最近收集整理的关于EASY 实现mqtt实验的全部内容,更多相关EASY内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复