[toc] # 平台介绍 ​ 永天数据平台物联网场景,构建“双引擎”模式将数据的生产,收集,处理,存储和服务进行封装,面向不同层级服务和应用提供不同服务形式,数据中台一般包括数据采集、数据集成、数据治理、数据应用和数据资产管理,另外还有诸如数据标准和指标建设. # 平台架构 ```mermaid graph LR subgraph USKY-AGENT data-agent data-updater end data-agent -.tcp.-> data-acceptance data-agent -.mqtt.-> mqtt-acceptance data-updater --> updater-acceptance subgraph USKY-IOT data-acceptance mqtt-acceptance updater-acceptance end data-acceptance subgraph USKY-Manager iot-api iot-web end updater-acceptance -->iot-api data-acceptance --mq:data-collector--> data-transfer mqtt-acceptance --mq:data-collector--> data-transfer subgraph USKY-DATA data-transfer device-data-influxdb-writer device-data-mysql-writer device-data-judge end device-data-influxdb-writer --> InfluxDB iot-api --> InfluxDB iot-api --> mysql iot-web --> iot-api data-transfer --mq:device-data--> device-data-influxdb-writer data-transfer --mq:device-data--> device-data-mysql-writer data-transfer --mq--> device-data-judge ``` ![image-20220607171344797](/Users/admin/Library/Application Support/typora-user-images/image-20220607171344797.png) ```mermaid graph LR subgraph USKY-AGENT ytCore ytDog Device end ytDog -.tcp.-> ytDMPVersionServer ytCore -.tcp.-> ytDMPDataServer Device -.mqtt.-> ytDataCollectorCore subgraph USKY-IOT ytDMPDataServer ytDMPVersionServer ytDataCollectorCore end subgraph USKY-Manager iot-api iot-web end ytDMPVersionServer -->iot-api ytDMPDataServer -.http.-> InfluxDB ytDMPDataServer --mq:data-collector--> ytDeviceTypeInfluxdbWriter ytDataCollectorCore --mq:data-collector--> ytDeviceTypeInfluxdbWriter subgraph USKY-DATA ytDeviceTypeInfluxdbWriter end ytDeviceTypeInfluxdbWriter --> InfluxDB iot-api --> InfluxDB iot-api --> mysql iot-web --> iot-api ``` ## 各服务说明 - *Data-acceptance* 自定义协议设备接入,解码服务,当前按照设备类型形成独立中间件,ytDP0001、ytDP0002、ytDP0003、ytDP00033、ytDP0006、ytDP0007、ytDP0008 - Mqtt-acceptance mqtt协议设备接入,解码服务 - Data-tsdb-writer-mongo 数据存储服务 - Data-tsdb-writer-influxdb 数据存储服务(研究) - Data-cache 实时缓存服务 - Data-query. 数据查询服务 ## 服务功能 ### Data-Acceptance ## Data-Transfer - 统一接收格式 ``` { "metrics": { "温度": 1000, "电量":77, "f1":-144 }, "tags":{ "connType":"G", "type":"INFO" } "deviceId": "1000001", "deviceType":"表", "productId": "52e1a2798c0a4335855648decf24de5a", "timestamp": 1636456995855 } ``` ## device-data-writer ### device-mongo-writer - 存储设计 ``` * 数据存储策略: 每个ns的每个metric的每个自然小时的数据存储到一个文档中. * id: ns_metirc_本小时0分的毫秒时间戳 * maxTime: 下个小时0分的时间 * minTime: 本小时0分的时间 * vs中是本小时的数据,每个key代表从本小时的0分到数据时间的秒数(因为数据是个double值,本身很小,数据占用存储的部分都被时间戳占用了, * 所以通过把和本小时0分的相对值作为key,减少时间戳暂用的存储大小) ``` ``` { "_id" : "13062509066_speed_1638691200000", "maxTime" : ISODate("2021-12-05T09:00:00Z"), "metric" : "speed", "minTime" : ISODate("2021-12-05T08:00:00Z"), "ns" : "13062509066", "vs" : { "2921" : 30, "2937" : 30, "2951" : 30, "2967" : 30, "2981" : 30, "2997" : 30, "3011" : 30, "3027" : 30, "3041" : 30, "3057" : 30, "3071" : 30, "3087" : 30, "3101" : 30, "3521" : 30 } } { "_id" : "13062509066_loc_1638691200000", "maxTime" : ISODate("2021-12-05T09:00:00Z"), "metric" : "loc", "minTime" : ISODate("2021-12-05T08:00:00Z"), "ns" : "13062509066", "vs" : { "2921" : { "lat" : 30.04181, "lng" : 117.784129 }, "2937" : { "lat" : 32.041809, "lng" : 118.784129 }, "2951" : { "lat" : 30.04181, "lng" : 117.784129 }, "2967" : { "lat" : 32.041809, "lng" : 118.784129 }, "2981" : { "lat" : 30.04181, "lng" : 117.784129 }, "3521" : { "lat" : 30.04181, "lng" : 117.784129 } } } ``` ### 数据存储接口 ``` curl --location --request POST 'http://127.0.0.1:10020/device/data' \ --header 'Content-Type: application/json' \ --data-raw '{ "metrics": { "mileage": 1000, "speed": 13.5 }, "tags": { "connType":"G", "type":"INFO" }, "deviceId" : "13062509066", "productId": "52e1a2798c0a4335855648decf24de5a", "timestamp": 1655712711 }' ``` ### 数据查询接口 ``` curl --location --request POST 'http://127.0.0.1:10111/aggregateMetricsDataForSingleDevice' \ --header 'Content-Type: application/json' \ --data-raw '{ "deviceId": "13062509066", "startTime": 1655712711000, "endTime": 1655712711000, "fieldNames": ["loc","speed"], "limit": true }' ``` ## device-influxdb-writer 方案 https://help.aliyun.com/document_detail/116264.html https://help.aliyun.com/document_detail/141858.html ## device-data-judge - 进行一次研讨 - 开发力量 # 物联网平台管理(DMP) ```mermaid graph LR a[产品] b[设备] c[设备类型] d[指标] a --1-N--> b b --N..1--> c c --1..N --> d ``` ## 设备类型 | 设备系统名称 | 设备编码 | 设备简称 | 设备指标 | | ------------ | -------- | -------- | -------- | | 火系统 | | | | | 水系统 | | | | | 烟感系统 | | | | | 消防栓 | | | | | 液位 | | | | | Rtu | | | | | | | | | ![image-20220907100831471](/Users/admin/Library/Application Support/typora-user-images/image-20220907100831471.png) # 设备厂商 # 设备属性定义 ![image-20220907100714643](/Users/admin/Library/Application Support/typora-user-images/image-20220907100714643.png) 设备信息表 设备ID,设备类型, 厂商型号 ## 中间件服务 Emqx ### mongo ``` mongo --host 106.14.25.32 --port 25000 > show dbs; admin 0.000GB config 0.000GB device-data 39.409GB device_wifi_data 8.618GB local 0.000GB spoi 43.921GB test 0.006GB > use device-data switched to db device-data > show collections; deviceDataEntity paasdeviceDataEntity > db.deviceDataEntity.find({'_id':'868120262119982_speed_1637964000000'}).pretty(); 查询所有 db.deviceDataEntity.find().pretty(); db.deviceDataEntity.find({'_id':'13062509066_loc_1639062000000'}).pretty() ``` influxdb kafka(待定) redis ## 参考资料 https://book.open-falcon.org/zh_0_2/ https://blog.csdn.net/ludongguoa/article/details/121168818 https://baijiahao.baidu.com/s?id=1721161998997866645&wfr=spider&for=pc thingskit https://docs.thingskit.com/thingskit-link/#thingskit%E7%AE%80%E4%BB%8B https://demo.thingskit.com/system/customize 1. mqtt-acceptance 这个代码开放给我 cat <