Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
YiRanCN committed Jul 11, 2023
1 parent 6cfd943 commit f164b8b
Show file tree
Hide file tree
Showing 7 changed files with 217 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/iotcloud/connect/http.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
sidebar_position: 5
---

# HTTP 设备接入
7 changes: 7 additions & 0 deletions docs/iotcloud/connect/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
sidebar_position: 1
---

# 概述

设备接入云平台,最核心的点是接入协议,本平台目前支持最流行的 MQTT,传统的 TCP,以及处理异构系统或简单使用的 HTTP 协议。
145 changes: 145 additions & 0 deletions docs/iotcloud/connect/mqtt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
---
sidebar_position: 3
---

# MQTT 设备接入

我觉得大概分两种模式:

- 设备对接本平台的属性协议
- 设备对接本平台的透传协议

两种模式的设备 connect 是一样的。

### 设备 connect

---

- ClientID device:{deviceCode} 举例:device:XoVnVQ2
- Username {deviceCode} 举例:XoVnVQ2
- Password {devicePwd} 举例:YXOsHbV

连接成功后,默认订阅

- /device/${device.code}/attributes/d

可根据具体应用场景,发布

- /device/${device.code}/attributes/u
- /device/${device.code}/attributes/req/u

可根据具体应用场景,订阅

- /device/${device.code}/attributes/res/d

### 设备对接本平台的属性协议

#### 设备上报属性

---

数据流向

- 设备 >> 云端 >> 用户

允许属性类型

- 设备上报
- 设备云端共享

topic

- /device/${device.code}/attributes/u
- /account/${user.account}/${device.code}/attributes/d

plyload

- [attributeCode:string] : [value:number|string]

#### 用户写入属性

---

数据流向

- 用户 >> 云端 >> 设备

允许属性类型

- 云端下发
- 设备云端共享 注:云端收到此属性后,会立即存储;设备收到此属性后,应该立即上报;
- 云端私有 注:此类属性只会到云端,不会下发给设备

topic

- /account/${user.account}/${device.code}/attributes/u
- /device/${device.code}/attributes/d

plyload

- [attributeCode:string] : [value:number|string]

### 设备对接本平台的透传协议

#### 设备上报透传数据

---

数据流向

- 设备 >> 云端 >> 用户

允许属性类型

- 设备上报
- 设备云端共享

topic

- /device/${device.code}/t/u
- 协议解析后模拟 /device/${device.code}/attributes/u
- /account/${user.account}/${device.code}/attributes/d

plyload

- [attributeCode:string] : [value:number|string]

#### 用户写入属性

---

数据流向

- 用户 >> 云端 >> 设备

允许属性类型

- 云端下发
- 设备云端共享 注:云端收到此属性后,会立即存储;设备收到此属性后,应该立即上报;
- 云端私有 注:此类属性只会到云端,不会下发给设备

topic

- /account/${user.account}/${device.code}/attributes/u
- 协议解析后模拟 /device/${device.code}/t/d

plyload

- [attributeCode:string] : [value:number|string]

### 举例说明

#### 自行实现

有设备端研发能力的可以根据上面的协议自行研发实现。

或者设备量大的,可以让 DTU 或模组厂商根据上面的协议实现。

目前,本平台还无法做到让下面的 DTU 厂商实现属性交互协议,下面举例,只举例透传协议方式。
相对于 MQTT 透传,100%的 DTU 厂商都实现了 TCP 协议接入,大家购买 DTU 的时候请仔细辨别,并非所有的 DTU 都支持 MQTT 透传。

#### 塔石 DTU

#### 有人 DTU

#### 四信 DTU
33 changes: 33 additions & 0 deletions docs/iotcloud/connect/tcp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
sidebar_position: 3
---

# TCP 设备接入

TCP 接入应该属于最为传统的接入方式,协议可以采用私有协议或通用的 Modbus 等。

本平台实现了 ModbusRTU 协议,以及支持私有协议的 TCP 二进制、TCP 文本协议。

**特别说明**,TCP 设备接入,云端作为 TCP 的服务端,暴漏的 15000 端口号,设备端作为 TCP 的客户端。

目前,该平台实现以下三种模式:

- ModbusRTU 云端轮询模式
- 二级制私有协议 云端轮询模式
- 文本私有协议 云端轮询模式

#### TCP 注册包

三种模式的设备端注册到云端的方式是一样的。

设备端发起到云端的 TCP 的连接成功后,应该立即发送注册包,注册包的格式为 **${device.code}&${device.pwd}**

云端验证成功后,后续设备端发送的消息才会被正常的解析,否则云端会离开断掉 TCP 连接。

#### ModbusRTU 云端轮询模式

选择了此种协议格式的设备,应该配置 **Modbus 配置** ,让属性和寄存器建立关系,以保证云端可以根据关系去轮询设备的数据。

#### 二级制私有协议 云端轮询模式

#### 文本私有协议 云端轮询模式
7 changes: 7 additions & 0 deletions docs/iotcloud/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
sidebar_position: 1
---

# 概述

所有程序的代码全部开源,免费商用,不受任何限制,致力于打造免费、开源、性能优异的物联网云平台生态。
6 changes: 6 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ const config = {
position: "left",
label: "技术选型",
},
{
type: "docSidebar",
sidebarId: "iotCloudSidebar",
position: "left",
label: "Iot-Cloud帮助文档",
},
{ to: "/blog", label: "博文", position: "left" },
{
href: "https://github.com/YiRanCN",
Expand Down
14 changes: 14 additions & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ const sidebars = {
},
],

iotCloudSidebar: [
"iotcloud/index",
{
type: "category",
label: "设备接入",
items: [
{
type: "autogenerated",
dirName: "iotcloud/connect",
},
],
},
],

// But you can create a sidebar manually
/*
tutorialSidebar: [
Expand Down

0 comments on commit f164b8b

Please sign in to comment.