赞
踩
【实验一】实现Easy IoT配置。
【实验二】实现Easy IoT上mqtt消息的通讯。
实现mind+下Easy IoT上mqtt消息的通讯。
硬件:掌控板
软件:Mind+
代码:
/*! * 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); }
登录Easy loT平台,点击查看topic0和topic1的消息详情,验证是否接收到Mind+发送的消息。
实验结果无误。
通过这次实验,我初次体会到了通过掌控板和云平台的连接互动,初步体会到互联网的魅力。在实验过程中,需要特别主要的地方是MQTT的连接,填写的参数必须要和自己Easy loT平台的一样。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。