首页 文章

Orion Context Broker Fiware中的订阅

提问于
浏览
1

我尝试向Orion Context Broker实例发送订阅 . 我发送这个JSON:

{
  "duration": "P1M",
  "reference": "http://130.206.127.23:1026/ngsi10/notifyContext",
  "notifyConditions": [
    {
      "condValues": [
        "PT10s"
      ],
      "type": "ONTIMEINTERVAL"
    }
  ],
  "entities": [
    {
      "id": "1.0",
      "type": "Capsule",
      "isPattern": "false"
    }
  ],
  "attributes": [
    "temperature"
  ]
}

我收到了下一条消息:

<subscribeContextResponse>
  <subscribeError>
    <errorCode>
      <code>400</code>
      <reasonPhrase>Bad Request</reasonPhrase>
      <details>JSON Parse Error: <unspecified file>(1): invalid escape sequence</details>
    </errorCode>
  </subscribeError>
</subscribeContextResponse>

我在the documentation中放置了它正在使用的所有属性 . 但在网络研讨会Orion Context Broker Webinar - Demo part 2我可以看到名为 Throttling 的其他属性,但我没有在文档中看到 .

我做得不好?

提前致谢 .

1 回答

  • 1

    我已经测试了您的请求(复制粘贴),这是结果(使用Orion 0.17.0) .

    命令(您可以检查有效负载是否与您使用的有效负载完全相同):

    (curl localhost:1026/v1/subscribeContext -s -S --header 'Content-Type: application/json' --header 'Accept: application/json' -d @- | python -mjson.tool) <<EOF
    {
      "duration": "P1M",
      "reference": "http://130.206.127.23:1026/ngsi10/notifyContext",
      "notifyConditions": [
        {
          "condValues": [
            "PT10s"
          ],
          "type": "ONTIMEINTERVAL"
        }
      ],
      "entities": [
        {
          "id": "1.0",
          "type": "Capsule",
          "isPattern": "false"
        }
      ],
      "attributes": [
        "temperature"
      ]
    }
    EOF
    

    结果:

    {
        "subscribeResponse": {
            "duration": "P1M", 
            "subscriptionId": "5489e0bfe5007d3271ab5a61"
        }
    }
    

    因此,我的测试还可以,所以我倾向于认为问题与编码有关,并且它没有显示在您的问题帖子中,例如使用 (错误) " 的intead和类似的东西 .

    EDIT: 另一个常见的问题来源是在"DOS text"中使用包含CB的curl请求的脚本文件(通常是由于使用了DOS / Windows文本编辑器) . 如果您运行 file yourfile.sh 并获得以下内容,则可以轻松检测到这一点

    yourfile.sh: ASCII text, with CRLF line terminators
    

    而不是以下

    yourfile.sh: ASCII text
    

    解决方案非常简单:将文件转换为"Unix text",例如使用 dos2unix 命令行工具 .

相关问题