文章目錄
- 1.設備服務
- 2.設備配置文件
- 3.設備資源
- 4.資源屬性(Attributes)
- 5.資源屬性(Properties)
- 6.設備命令
- 7.資源操作
- 8.REST 命令端點
- 9.推送事件
- EdgeX Foundry
# EdgeX Foundryhttps://iothub.org.cn/docs/edgex/
https://iothub.org.cn/docs/edgex/device-service/
1.設備服務
設備服務是與傳感器/設備或物聯網對象(“物”)交互的邊緣連接器,其中包括機器、機器人、無人機、HVAC 設備、相機等。通過利用可用的連接器,可以控制設備并/或傳輸數據至 EdgeX 或從其傳輸數據。您還可以使用設備服務 SDK 來創建您自己的 EdgeX 設備服務。
設備配置文件描述了EdgeX 系統內的一種設備類型。設備服務管理的每個設備都與設備配置文件關聯,設備配置文件根據其支持的操作定義該設備類型。
通常,設備配置文件由設備服務從文件加載,并在首次啟動時推送到核心元數據進行存儲。一旦存儲在核心元數據中,設備配置文件就會在后續啟動時從核心元數據加載。
2.設備配置文件
設備配置文件由以下字段組成
Field Name | Type | Required? | Description |
---|---|---|---|
name | String | Y | Must be unique in the EdgeX deployment. |
description | String | N | Description of the Device Profile |
manufacturer | String | N | Manufacturer of the device described by the Device Profile |
model | String | N | Model of the device(s) described by the Device Profile |
labels | Array of String | N | Free form labels for querying device profiles |
deviceResources | Array of DeviceResource | Y | See Device Resources below |
deviceCommands | Array of DeviceCommand | N | See Device Commands below |
DeviceProfile定義了設備的值和操作方法,可以是Read或Write。
創建名為 的設備配置文件my.custom.device.profile.yml
,其中包含以下內容:
name: "my-custom-device-profile"
manufacturer: "iot"
model: "MQTT-DEVICE"
description: "Test device profile"
labels:- "mqtt"- "test"
deviceResources:-name: randnumisHidden: truedescription: "device random number"properties:valueType: "Float32"readWrite: "R"-name: pingisHidden: truedescription: "device awake"properties:valueType: "String"readWrite: "R"-name: messageisHidden: falsedescription: "device message"properties:valueType: "String"readWrite: "RW"-name: jsonisHidden: falsedescription: "JSON message"properties:valueType: "Object"readWrite: "RW"mediaType: "application/json"deviceCommands:-name: valuesreadWrite: "R"isHidden: falseresourceOperations:- { deviceResource: "randnum" }- { deviceResource: "ping" }- { deviceResource: "message" }
3.設備資源
設備資源指定設備內的傳感器值,可以單獨或作為設備命令的一部分讀取或寫入該值。它具有用于識別的名稱和用于提供信息的描述。
設備資源由以下字段組成:
The device resource consists of the following fields:
Field Name | Type | Required? | Notes |
---|---|---|---|
name | String | Y | Must be unique in the EdgeX deployment. |
description | String | N | Description of the device resource |
isHidden | Bool | N | Hide the device resource as command via the Command Service, default false |
tags | String-Interface Map | N | User define collection of tags |
attributes | String-Interface Map | N | See Resource Attributes below |
properties | ResourceProperties | Y | See Resource Properties below |
4.資源屬性(Attributes)
設備資源中的attributes
參數是訪問設備上的特定值所需的設備服務特定參數。每個設備服務實現都有自己的一組所需的命名值,例如,BACnet 設備服務可能需要對象標識符和屬性標識符,而藍牙設備服務可以使用 UUID 來標識值。
設備 ONVIF 攝像頭的資源屬性示例
attributes:service: "Device"getFunction: "GetDNS"setFunction: "SetDNS"
5.資源屬性(Properties)
設備資源properties
的 描述了值以及要對其執行的可選簡單處理。
資源屬性由以下字段組成:
The resource properties consists of the following fields:
Field Name | Type | Required? | Notes |
---|---|---|---|
valueType | Enum | Y | The data type of the value. Supported types are: Uint8 , Uint16 , Uint32 , Uint64 , Int8 , Int16 , Int32 , Int64 , Float32 , Float64 , Bool , String , Binary , Object , Uint8Array , Uint16Array , Uint32Array , Uint64Array , Int8Array , Int16Array , Int32Array , Int64Array , Float32Array , Float64Array , BoolArray |
readWrite | Enum | Y | Indicates whether the value is readable or writable or both. R - Read only , W - Write only, RW - Read or Write |
units | String | N | Developer defined units of value such as secs, mins, etc |
minimum | Float64 | N | Minimum value the resource value can be set to. Error if SET command value out of minimum range |
maximum | Float64 | N | Maximum value the resource value can be set to. Error if SET command value out of maximum range |
defaultValue | String | N | Default value to use when no value is present for a set command. If present, should be compatible with the valueType field |
mask | Uint64 | N | A binary mask which will be applied to an integer reading. Only valid when valueType is one of the unsigned integer types |
shift | Int64 | N | A number of bits by which an integer reading will be shifted right. Only valid when valueType is one of the unsigned integer types |
scale | Float64 | N | A factor by which to multiply a reading before it is returned. Only valid when valueType is one of the integer or float types |
offset | Float64 | N | A value to be added to a reading before it is returned. Only valid when valueType is one of the integer or float types |
base | Float64 | N | A value to be raised to the power of the raw reading before it is returned. Only valid when valueType is one of the integer or float types |
assertion | String | N | A string value to which a reading (after processing) is compared. If the reading is not the same as the assertion value, the device’s operating state will be set to disabled. This can be useful for health checks. |
mediaType | String | N | A string indicating the content type of the Binary value. Required when valueType is Binary . |
optional | String-Any Map | N | Optional mapping for developer use |
6.設備命令
設備命令定義同時訪問多個資源。每個命名設備命令應包含多個resource operations
.具有單個資源操作的設備命令不會比 SDK 為同一設備資源創建的隱式設備命令增加任何值。
當讀數在邏輯上相關時,設備命令可能很有用,例如,對于 3 軸加速度計,一起讀取所有軸會很有幫助。
每個設備命令由以下字段組成:
Each device command consists of the following fields:
Field Name | Type | Required? | Notes |
---|---|---|---|
name | String | Y | Must be unique in this profile. |
isHidden | Bool | N | Hide the Device Command for use via Command Service, default false |
readWrite | Enum | Y | Indicates whether the command is readable or writable or both. R - Read only , W - Write only, RW - Read or Write. Resources’ readWrite included in the command must be consistent with the value chosen here. |
resourceOperations | Array of ResourceOperation | Y | see Resource Operation below |
7.資源操作
資源操作由以下字段組成:
A resource operation consists of the following fields:
Field Name | Type | Required? | Notes |
---|---|---|---|
deviceResource | String | Y | Must name a Device Resource in this profile |
defaultValue | String | N | If present, should be compatible with the Type field of the named Device Resource |
mappings | String-String Map | N | Map the GET resourceOperation value to another string value |
8.REST 命令端點
命令端點是在服務上為設備配置文件中指定的每個設備資源和每個設備命令隱式創建的。有關更多詳細信息,請參閱設備服務 API 參考中的 GET 和 SET 設備命令 API 。
9.推送事件
SDK 應實現除了收到設備 GET 請求之外生成事件的方法。 AutoEvent 機制提供以固定時間間隔生成事件的功能。異步事件隊列使設備服務能夠根據特定于實現的邏輯在任意時間生成事件。
自動事件
AutoEvents
每個設備可以具有與其關聯的多個元數據作為其定義的一部分。 AnAutoEvent
具有以下字段:
- resource:deviceResource 或 deviceCommand 的名稱,指示要讀取的內容。
- Frequency:一個字符串,表示讀取事件之間等待的時間,表示為整數后跟 ms、s、m 或 h 單位。
- onchange:布爾值:如果設置為 true,則僅當自上次事件以來包含的一個或多個讀數發生更改時才生成新事件。
設備 SDK 應根據這些AutoEvent
定義從實現中安排設備讀取。它應該使用與通過 REST 請求讀數時相同的邏輯。
異步事件隊列
SDK 應提供一種機制,使實現可以隨時提交設備讀數而不會阻塞。這可以以適合于實現語言的方式來完成,例如,Go SDK提供可以在其上推送讀數的通道,C SDK提供將讀數提交到工作隊列的功能。
- EdgeX Foundry
# EdgeX Foundryhttps://iothub.org.cn/docs/edgex/
https://iothub.org.cn/docs/edgex/device-service/