项目四 基于 OneNET 的智慧小区安全防护系统
一.项目目标
1、通过中移OneNET物联网开放平台新建产品(MQTT);
2、根据项目场景创建产品物模型;
3、创建基于MQTT 的云平台设备;
4、查看设备运行状态及数据
5、通过模拟工具调试设备接入;
6、通过模拟设备,实现属性上报;
7、OneNET 平台下发属性值(命令)到模拟设备;
8、基于真实设备,搭建软硬件环境,接入 OneNET 平台并实现设备属性上报;
9、通过OneNET 平台的“设备调试”实现设备属性下发;
10、通过OneNET 平台的“API 调试”实现设备属性下发;
11、直接基于API 方式实现设备属性下发
12、学会OneNET 平台数据可视化编辑器的使用;
13、能够进行可视化数据源的配置;
14、对智慧小区安全防护系统进行可视化展现
二.创建智慧小区安全防护系统产品设备和模拟设备接入
2.1创建产品设备
点击物联网开放平台

点击产品开发后点击创建产品,创建智慧小区安全防护系统产品

根据下图依次选择产品品类等,选择智能化方式为“设备接入”方式

点击设备接入后出现下图,按照下图的内容填入表中,填完后点击确认,创建成功

2.2根据项目场景创建产品物模型
点击产品开发进入详情页面

点击“设置物模型”按钮,进入物模型管理页面

添加系统功能点

在页面中像下图勾选这两个系统功能点,点击添加完成添加

完成系统功能点添加,添加自定义功能点

点击“添加自定义功能点”,在弹出的添加页面中,按如下内容,添加
需的功能点信息。分别添加两个自定义功能点一个为距离,一个为蜂鸣器

第二个自定义功能点

最后点击保存

保存成功

2.3创建设备
添加设备,分别添加名为Controller和入Simulator两个设备


2.4设备状态及信息查看
初始创建的设备,显示为“未激活”,当实体设备使用该条设备信息接入到 OneNET 平台后,则显示为“在线”,断开与OneNET 平台的连接后,则显示为“离线”,

查看设备详细信息

切换到“属性”页面,可以查看当前设备下的各个物模型功能点实际数据

点击运维监控展开,“设备日志”子菜单,查看设备日志

2.5 设备分组管理
创建设备分组

创建成功后点击详情

key 可用于按分组方式接入 OneNET 平台的方式时,计算 Token 的授权凭据

点击“添加设备”按钮,弹出的页面展示了左右两栏设备列表。勾选下图两个设备进行分组


2.6模拟设备接入
模拟设备接入OneNET 平台
打开token将产品ID和设备密钥 ...填入,点击“Generate”按钮,在工具下方输入框计算产生 token

安装并配置 MQTT.fx 工具模拟设备信息
进入客户端配置页面:按下图填入相关数据,其中MQTT 协议版本号:取消默认勾中,确保下方版本选择下拉框可选,并选择为 3.1.1

点击 “User Credentials”选项页,继续设置

使用 MQTT.fx 工具模拟设备接入
运行 MQTT.fx 工具,点击选择刚刚保存的连接配置列表项,点击“Connect”,如果一切正常,工具将很快登陆接入OneNET 平台,此时 Connect 按钮变灰,右侧Disconnect 按钮处于激活状态。

可以点击”Log“ 选项页,查看工具连接服务端的情况,正常连接成功则提示类似如下图红框所示信息

当工具显示正常连接后,查看OneNET 平台中当前模拟的设备在页面显示为在线状态,点击 MQTT 工具窗口中的 “Disconnect”按钮,断开工具的 MQTT 连接,等待一会儿后,刷新OneNET平台中设备列表页面,查看显示的设备状态信息:可以看到其状态都变为离线。

模拟设备接入OneNET 平台实现属性上报
订阅属性上报结果通知消息
根据实际创建的产品和设备信息替换,将替换后完整的 topic,填入模拟
工具“Subscribe”选项页中的输入框,如下图所示

点击“Subscribe”按钮向平台订阅该主题,平台返回成功后,工具左侧中的已订阅主题列表会有一条记录,且该主题下当前消息数为 0

发送属性上报消息
点击“Publish”选项页表头将其中的产品 ID、设备名称替换为实际的信息后填入该输入框
在下空白编辑区中,输入如下内容:第二个框内的内容
输入并检查无误后,点击“Publish”按钮

查看属性上报结果
点击“Subscribe”选项页表头,查看之前订阅的属性上报结果通知消息 topic 下,收到的消息如下图

OneNET 平台中查看设备的属性最新值

OneNET 平台下发属性值到模拟工具
订阅接收平台下发属性数据的 topic
点击模拟工具的“Subscribe”选项页表头,在其中的输入框填写平台下发属性数据的 topic。点击“Subcribe”按钮完成订阅

在“设备管理”中选择要下发属性的设备,点击详情进入设备信息页面,切换功能为“设备调试”

如下图填入数据

点击“Subscribe”选项页表头,可以看到已订阅列表中,关于平台下发属性数据的topic, 当前消息数是 1。点击右侧消息列表最下方一条消息,可以看到其中的内容信息,收到的值与前一步骤中下发的值相同

仿真设备信息上传
1 进入设备调试功能

启动设备模拟器
输入关键字搜索定位到“WiFi定位”属性数据点,勾中前面的选框,并点击右侧下拉展开 箭 头 , 在 该 数 据 点 下 的 “ 热 点 mac 信 息 ” 输 入 框 中 输 入 某 个 WiFi 热 点 的 mac 地 址 信 息 , 如
dc:fe:18:f2:4c:67|ac:b3:b5:1d:63:80。点击下方的“属性上报”

观察页面右侧显示的数据上报及平台回应信息,确认数据成功上报

在设备详情页面查看设备上报的热点位置信息数据

三.基于真实设备接入 OneNET 平台
搭建实训项目终端硬件平台
“核心模块”以及“Wifi 模块”、“蜂鸣器模块”、 “超声波模块”

修改设备程序的 OneNET 平台网络接入配置参数
输入自己的Wifi 网络用户名和密码
UsartPrintf(USART_DEBUG, "Tips: AT+CWJAP/r/n");
if(!NET_DEVICE_SendCmd("AT+CWJAP=/"223345/",/"052052052/"/r/n", "GOT IP", 400))
编译成功,烧入代码

等待上线

OneNET 平台侧查看设备上报数据信息

下发属性在终端设备上执行生效(设备调试)
设备处于上线状态执行,根据图片选择,进入 OneNET 平台 的设备调试功
能页面

先勾选一个功能点,然后设置下发的数值。

下图调试日志展示了下发的报文

下发属性在终端设备上执行生效(API 调试)
在设备处于在线状态,进入“API 调试”功能页面

在中间页面展示的必填参数中,填写页面中输入必要的参数

点击下方的“执行”按钮,等待一会儿后,设备端执行下发的属性值(蜂鸣器响),同时右侧列页面刷新显示出调用结果

调试工具 Postman
在 Postman 工具的 Body 选项页内填入下图内容

在Header内填入下图 内容

token用于生成上图第2步的内容

点击send发起 API 请求,查看结果,蜂鸣器模块响起

基于OneNET 云平台的场景联动
点击页面右上角“新建场景”,填写场景名称,“距离太近告警”的场景,

选择触发条件为依次选择下图中的内容

增加“执行动作”

点击“确定”创建好改场景信息,并修改其启用状态为“开”。

再新增一个联动规则,实现距离安全时取消告警

设备上线后观察到联动日志

四安全防护系统的可视化实现
创建可视化项目


增加数据源模板

跟图填写

添加控件:常规图表中的平滑折线图

设置图表的数据来源


“数据源选择”下拉列表会出现一条可选的记录,代表以“distance” 模板生成的记录,选择该条记录作为折线图的数据源

设置不使用数据过滤器

切换回“样式”属性 Tab 页。展开“数据系列”的节点,修改列字段名为“value”

保存视图,完成可视化项

五.实训问题及解决
问题:在进行posman中蜂鸣器没有反应
解决:经过多方面排查对比,发现了该实验的基础得在设备上线时进行更改后成功
问题:模拟设备接入OneNET 平台中设备没成功上线
解决:多方面检查成功发现有一处是填产品ID不是填用户ID,改正后成功
六.总结
在本次实训中进行可视化数据源的配置对可视化较为掌握了一些规范,学会了3种去控制蜂鸣器的方法,也了解使用属性上报和属性下发 的基础知识,并在这次实验中遇到一些问题,并学会去解决它,提高了自己排查问题的能力和动手能力,对 OneNET 有了更深一步的认识,了解到了基于 OneNET 的智慧小区安全防护系统的大概流程,也进一步提高自己的动手技能了
共有 0 条评论