简体   繁体   English

Fiware NGSI 实体中的事件和操作

[英]Events and actions in Fiware NGSI entities

Let assume we have an entity corresponding to an IoT controller device, let say a door controller. We want to define an event that could cause an action (open/close).假设我们有一个对应于 IoT controller 设备的实体,比如说一扇门 controller。我们想要定义一个可能导致动作(打开/关闭)的事件。 So we need to send a command to this device.所以我们需要向这个设备发送命令。

How would we make this happen?我们将如何做到这一点? Add an attribute in the entity like for example setDoorStatus that can be written to via the NGSI API?在实体中添加一个属性,例如可以通过 NGSI API 写入的 setDoorStatus? And then have some IoT agent or command handler subscribe to this attribute?然后让一些 IoT 代理或命令处理程序订阅此属性? Is there any example of a Data Model where this is done?是否有数据 Model 的示例?

The easiest way to do this is to provision a device using any IoT Agent .最简单的方法是使用任何IoT 代理配置设备。 IoT Agents have a standard API for device provisioning, where commands can be listed: IoT 代理有一个标准的 API 用于设备配置,其中可以列出commands

curl -L -X POST 'http://localhost:4041/iot/devices' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-H 'Content-Type: application/json' \
--data-raw '{
  "devices": [
    {
      "device_id": "door001",
      "entity_name": "urn:ngsi-ld:Door:001",
      "entity_type": "Door",
      "protocol": "PDI-IoTA-UltraLight",
      "transport": "HTTP",
      "endpoint": "http://context-provider:3001/iot/door001",
      "commands": [ 
        {"name": "unlock","type": "command"},
        {"name": "open","type": "command"},
        {"name": "close","type": "command"},
        {"name": "lock","type": "command"}
       ],
       "attributes": [
        {"object_id": "s", "name": "state", "type":"Text"}
       ],
       "static_attributes": [
         {"name":"refStore", "type": "Relationship","value": "urn:ngsi-ld:Store:001"}
       ]
    }
  ]
}
'

The IoT Agent node library defines a command paradigm for actuating devices through commands IoT Agent 节点库定义了通过命令驱动设备的命令范式

In this case you have an attribute open which is registered on a context broker as coming from a device and you can actuate the device using the following request:在这种情况下,您有一个open属性,它在上下文代理上注册为来自设备,您可以使用以下请求启动设备:

NGSI-v2 NGSI-v2

curl -L -X PATCH 'http://localhost:1026/v2/entities/urn:ngsi-ld:Door:001/attrs' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-H 'Content-Type: application/json' \
--data-raw '{
  "open": {
      "type" : "command",
      "value" : ""
  }
}'

NSGI-LD NSGI-LD

curl -L -X PATCH 'http://localhost:4041/ngsi-ld/v1/entities/urn:ngsi-ld:Device:door001/attrs/open' \
-H 'NGSILD-Tenant: openiot' \
-H 'NGSILD-Path: /' \
-H 'Content-Type: application/json' \
-H 'Link: <http://context/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
--data-raw '{ 

        "type": "Property", 
        "value": "" 

}'

The relevant IoT Agent accepts the request and passes it down to the device using the appropriate device syntax.相关的 IoT 代理接受请求并使用适当的设备语法将其传递给设备。 Once activated, additional special status and info attributes are added to the entity as soon as it has any information of the command progress.激活后,只要实体有任何命令进度信息,就会将额外的特殊statusinfo属性添加到实体中。

Full examples can be found within the FIWARE Tutorials:完整示例可以在 FIWARE 教程中找到:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM