2019-10-28 19:00:48 [显示全部楼层]
3625浏览
查看: 3625|回复: 3

[高级教程] 【百度物联】物接入 IoT Hub+App inventor2+掌控板

[复制链接]
本帖最后由 云天 于 2019-10-28 19:00 编辑

物接入 IoT Hub    物接入(IoT Hub)是一个全托管的云服务,帮助建立设备与云端之间安全可靠的双向连接及设备管理,以支撑海量设备的数据收集、控制、故障预测等各种物联网场景。

一、打通百度物联与App inventor2
    1、注册百度云帐号https://cloud.baidu.com/
【百度物联】物接入 IoT Hub+App inventor2+掌控板图1

  现在的验证方式真是让人感觉越来越好玩了,以后可能要先玩个游戏,过关了才能通过验证。

【百度物联】物接入 IoT Hub+App inventor2+掌控板图2

以前感觉在看不清的图里找验证码,隔着屏幕想骂人。

2、进入“物接入 IoT Hub”

【百度物联】物接入 IoT Hub+App inventor2+掌控板图4

    进入项目列表,创建项目

【百度物联】物接入 IoT Hub+App inventor2+掌控板图3

   一定要选数据型

【百度物联】物接入 IoT Hub+App inventor2+掌控板图5

建好的项目中“地址”的第一个,我们要填到App inventor2(WxBit 汉化增强版) MQtt客户端中

【百度物联】物接入 IoT Hub+App inventor2+掌控板图6【百度物联】物接入 IoT Hub+App inventor2+掌控板图7

点击项目名,新建用户

【百度物联】物接入 IoT Hub+App inventor2+掌控板图8

【百度物联】物接入 IoT Hub+App inventor2+掌控板图9【百度物联】物接入 IoT Hub+App inventor2+掌控板图10

【百度物联】物接入 IoT Hub+App inventor2+掌控板图11【百度物联】物接入 IoT Hub+App inventor2+掌控板图12【百度物联】物接入 IoT Hub+App inventor2+掌控板图13【百度物联】物接入 IoT Hub+App inventor2+掌控板图14

主题在订阅和发布时要用到

【百度物联】物接入 IoT Hub+App inventor2+掌控板图15【百度物联】物接入 IoT Hub+App inventor2+掌控板图16

3、App inventor2逻辑设计

【百度物联】物接入 IoT Hub+App inventor2+掌控板图17

二、实现 掌控板与百度物联 打通
1、下载最新的Mind+
【百度物联】物接入 IoT Hub+App inventor2+掌控板图18
2、利用Mind+"自动生成"代码功能(物联网MQTT中没有百度,需在“手动编辑”修改)
【百度物联】物接入 IoT Hub+App inventor2+掌控板图19
3、从“自动生成”复制代码,粘贴至“手动编辑”,手动修改两处:
/*!
* MindPlus
* mpython
*
*/
#include <MPython.h>
#include <DFRobot_Iot.h>
// 函数声明
void obloqMqttEventT0(String& message);
// 静态常量
const String topics[5] = {"toptic","","","",""};//按实际主题填写
const MsgHandleCb msgHandles[5] = {obloqMqttEventT0,NULL,NULL,NULL,NULL};
// 创建对象
DFRobot_Iot myIot;


// 主程序开始
void setup() {
        mPython.begin();
        myIot.setMqttCallback(msgHandles);
        rgb.write(0, 0x0000FF);
        myIot.wifiConnect("mxy", "smj080823");
        while (!myIot.wifiStatus()) {yield();}
        rgb.write(0, 0xFF0000);
        display.setCursorXY(42, 22);
        display.print("Wifi_OK");
  myIot.init("******.mqtt.iot.gz.baidubce.com","用户名","","密码",topics,1883);//按实际填写
        myIot.connect();
        while (!myIot.connected()) {yield();}
        rgb.write(0, 0x00FF00);
        display.setCursorXY(42, 22);
        display.print("MQTT_OK");
}
void loop() {

}

// 事件回调函数
void obloqMqttEventT0(String& message) {
  rgb.write(0, 0x000000);
        display.setCursorXY(42, 22);
        display.print(message);
}
4、下载到掌控板中
5、修改APP inventor2,向百度物联发信息,掌控板接收后回显
【百度物联】物接入 IoT Hub+App inventor2+掌控板图20
界面设计
【百度物联】物接入 IoT Hub+App inventor2+掌控板图21
逻辑设计修改部分
三、成功截图
【百度物联】物接入 IoT Hub+App inventor2+掌控板图22【百度物联】物接入 IoT Hub+App inventor2+掌控板图23

rzyzzxw  版主

发表于 2019-10-29 08:10:11

膜拜大神
回复

使用道具 举报

gray6666  初级技神

发表于 2019-10-29 08:14:43

学习了
回复

使用道具 举报

gada888  版主

发表于 2019-11-26 15:28:28

灰常好
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail