简体   繁体   English

什么是模拟物联网代理命令的 NGSI v2 端点?

[英]What is the NGSI v2 endpoint for mimicking IoT Agent commands?

When testing commands Southbound, I am currently using the NGSI v1 endpoint as shown:在测试 Southbound 命令时,我目前使用的是 NGSI v1 端点,如下所示:

curl -X POST \
  'http://{{iot-agent}}/v1/updateContext' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: openiot' \
  -H 'fiware-servicepath: /' \
  -d '{
    "contextElements": [
        {
            "type": "Bell",
            "isPattern": "false",
            "id": "urn:ngsi-ld:Bell:001",
            "attributes": [
                {
                    "name": "ring",
                    "type": "command",
                    "value": ""
                }
            ]
        }
    ],
    "updateAction": "UPDATE"
}'

As you can see this is an NGSI v1 request.如您所见,这是一个 NGSI v1 请求。 According to this presentation on Slideshare (slide 16) use of NGSI v1 is discouraged - I would like to replace this with an NGSI v2 request.根据关于 Slideshare(幻灯片 16)的介绍不鼓励使用 NGSI v1 - 我想用 NGSI v2 请求替换它。 I believe that all IoT Agents are now NGSI v2 capable, however I have been unable to find the details of the replacement NGSI v2 request within the documentation.我相信所有物联网代理现在都支持 NGSI v2,但是我无法在文档中找到替换 NGSI v2 请求的详细信息。

So the question is what is the equivalent cUrl command to mimic a command from Orion using NGSI v2?所以问题是使用 NGSI v2 模拟来自 Orion 的命令的等效 cUrl 命令是什么?

In this document you can see a good reference on how to send commands using the NGSIv2 API:本文档中,您可以看到有关如何使用 NGSIv2 API 发送命令的很好参考:

If you take a look to the previous device example, you can find that a "ping" command was defined.如果您查看前面的设备示例,您会发现定义了“ping”命令。 Any update on this attribute “Ping” at the NGSI entity in the ContextBroker will send a command to your device. ContextBroker 中 NGSI 实体中此属性“Ping”的任何更新都会向您的设备发送命令。 For instance, to send the "Ping" command with value "Ping request" you could use the following operation in the ContextBroker API:例如,要发送值为“Ping request”的“Ping”命令,您可以在 ContextBroker API 中使用以下操作:

 PUT /v2/entities/[ENTITY_ID]/attrs/ping { "value": "Ping request", "type": "command" }

ContextBroker API is quite flexible and allows to update an attribute in several ways. ContextBroker API 非常灵活,允许以多种方式更新属性。 Please have a look to the NGSIv2 specification for details.有关详细信息,请查看NGSIv2 规范

Important note: don't use operations in the NGSI API with creation semantics.重要说明:不要在 NGSI API 中使用具有创建语义的操作。 Otherwise, the entity/attribute will be created locally to ContextBroker and the command will not progress to the device (and you will need to delete the created entity/attribute if you want to make it to work again).否则,实体/属性将在本地创建到 ContextBroker 并且命令不会进入设备(如果您想让它再次工作,您将需要删除创建的实体/属性)。 Thus, the following operations must not be used:因此,下面的操作,不得使用:

  • POST /v2/entities
  • PUT /v2/entities
  • POST /v2/op/entites with actionType append , appendStrict or replace POST /v2/op/entites with actionType append , appendStrictreplace
  • POST /v1/updateContext with actionType APPEND , APPEND_STRICT or REPLACE使用actionType APPENDAPPEND_STRICTREPLACE POST /v1/updateContext

EDIT : all the above refers to the Orion endpoint used by final client to send commands .编辑:以上所有内容均指最终客户端用于发送命令Orion 端点 @jason-fox has clarified that question refers to the IOTA endpoint that receives commands request from Orion (it should have been evident by the {{iot-agent}} , but I missed that part sorry :) @jason-fox 已澄清该问题是指从 Orion 接收命令请求IOTA 端点{{iot-agent}}应该很明显,但我很抱歉错过了那部分:)

The Orion-to-IOTA communication for commands is based on the registration-forwarding mechanism.命令的 Orion 到 IOTA 通信基于注册转发机制。 Currently, Orion always uses NGSIv1 to forward updates (even in the case the client uses NGSIv2 updates).目前,Orion 始终使用 NGSIv1 来转发更新(即使在客户端使用 NGSIv2 更新的情况下)。 In the future, we envision the usage of NGSIv2 but in order to achieve this, first we need:未来,我们设想使用 NGSIv2,但为了实现这一目标,首先我们需要:

  • To complete the Context Source Forwarding Specification, based on NGSIv2.完成上下文源转发规范,基于NGSIv2。 It is currently under discussion in this PR .目前正在此 PR 中进行讨论。 Feedback is welcome as comments to that PR!欢迎反馈作为对该 PR 的评论!
  • To implement forwarding based in Context Source Forwarding Specification in Orion在 Orion 中实现基于上下文源转发规范的转发
  • To implement NGSIv2 endpoint compliant with Context Source Forwarding Specification in the IOTAs.在 IOTA 中实现符合上下文源转发规范的 NGSIv2 端点。

While the above gets completed, the only mechanism is the current one based in NGSIv1.虽然上面已经完成,但唯一的机制是基于 NGSIv1 的当前机制。 However, note the Orion-IOTA interaction is internal to platform component and final client could base all their interactions to the platform (in particular, to the Orion endpoint) on NGSIv2, so this is not a big issue.但是,请注意 Orion-IOTA 交互是平台组件内部的,最终客户端可以将所有与平台(特别是 Orion 端点)的交互基于 NGSIv2,所以这不是一个大问题。

The Context Source Forwarding Specification, based on NGSIv2 is now completed and the old /v1 endpoint has been deprecated .基于 NGSIv2 的上下文源转发规范现已完成,旧的/v1端点已弃用 According to the discussions of the associated Support for NGSIv2 issue , the correct request to send is as follows:根据对 NGSIv2相关支持问题的讨论,正确的发送请求如下:

curl -iX POST \
  http://localhost:4041/v2/op/update \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: openiot' \
  -H 'fiware-servicepath: /' \
  -d '{
    "actionType": "update",
    "entities": [
        {
            "type": "Bell",
            "id": "urn:ngsi-ld:Bell:001",
            "ring" : {
                "type": "command",
                "value": ""
            }
        }
    ]
}'

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

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