簡體   English   中英

在FIWARE Orion中向設備發送命令無效

[英]Sending commands to devices in FIWARE Orion is not working

我正在嘗試在FIWARE上提供設備並發送命令。 就我而言,是帶有命令(“開”和“關”)的燈。 但是,它不起作用。 創建設備和發送命令的步驟是:

  1. 提供設備;
  2. 創建服務組;
  3. 使用命令創建注冊;
  4. 發送命令。

我服用fiware-教程下面的步驟,但不起作用。

我使用的代碼是:

要創建設備:

curl -iX POST \
  'http://localhost:4041/iot/devices' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: openiot' \
  -H 'fiware-servicepath: /' \
  -d '{
  "devices": [
    {
      "device_id": "lamp1",
      "entity_name": "urn:ngsi-ld:Lamp:1",
      "entity_type": "Lamp",
      "protocol": "PDI-IoTA-UltraLight",
      "transport": "HTTP",
      "endpoint": "http://iot-sensors:3001/iot/lamp1",
      "commands": [
        {"name": "on","type": "command"},
        {"name": "off","type": "command"}
       ],
       "attributes": [
        {"object_id": "s", "name": "state", "type":"Text"},
        {"object_id": "l", "name": "luminosity", "type":"Integer"}
       ],
       "static_attributes": [
         {"name":"refStore", "type": "Relationship","value": "urn:ngsi-ld:Store:001"}
      ]
    }
  ]
}
'

要創建服務組:

curl -iX POST \
  'http://localhost:4041/iot/services' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: openiot' \
  -H 'fiware-servicepath: /' \
  -d '{
 "services": [
   {
     "apikey":      "4jggokgpepnvsb2uv4s40d59ov",
     "cbroker":     "http://orion:1026",
     "entity_type": "Thing",
     "resource":    "/iot/d"
   }
 ]
}'

要為命令創建注冊:

curl -iX POST \
  'http://localhost:1026/v2/registrations' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: openiot' \
  -H 'fiware-servicepath: /' \
  -d '{
  "description": "Lamp Commands",
  "dataProvided": {
    "entities": [
      {
        "id": "urn:ngsi-ld:Lamp:1","type": "Lamp"
      }
    ],
    "attrs": [ "on", "off" ]
  },
  "provider": {
    "http": {"url": "http://orion:1026/v2"},
    "legacyForwarding": true
  }
}'

發送“ on”命令:

curl -iX PATCH \
  'http://localhost:1026/v2/entities/urn:ngsi-ld:Lamp:1/attrs' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: openiot' \
  -H 'fiware-servicepath: /' \
  -d '{
  "on": {
      "type" : "command",
      "value" : ""
  }
}'

進行HTTP get請求以檢索實體:

curl -G -X GET \
  'http://localhost:1026/v2/entities/urn:ngsi-ld:Lamp:1' \
  -d 'type=Lamp' \
  -d 'options=keyValues' \
  -H 'fiware-service: openiot' \
  -H 'fiware-servicepath: /'

我期望輸出如下:

{
  "id": "urn:ngsi-ld:Lamp:001",
  "type": "Lamp",
  "TimeInstant": "2019-08-28T13:33:51.00Z",
  "luminosity": "1115",
  "off_info": " ",
  "off_status": "UNKNOWN",
  "on_info": " on OK",
  "on_status": "OK",
  "refStore": "urn:ngsi-ld:Store:001",
  "state": "ON",
  "on": "",
  "off": ""
}

但我收到這個:

{
  "id": "urn:ngsi-ld:Lamp:1",
  "type": "Lamp",
  "TimeInstant": "2019-08-28T12:50:22.00Z",
  "luminosity": " ",
  "off_info": " ",
  "off_status": "UNKNOWN",
  "on_info": "There was an error in the response of a device to a command [404]: on NOT OK",
  "on_status": "ERROR",
  "refStore": "urn:ngsi-ld:Store:001",
  "state": " ",
  "on": "",
  "off": ""
}

假設您使用的是FIWARE教程虛擬設備,則您的設置步驟正確,並且收到的錯誤消息( 404 )表示lamp1發送時未響應您的命令。

設置設備時

 "device_id": "lamp1",
 "entity_name": "urn:ngsi-ld:Lamp:1",
 "endpoint": "http://iot-sensors:3001/iot/lamp1",

您正在聲明:

  • 存在設備( lamp1
  • 設備在Orion中具有實體名稱( urn:ngsi-ld:Lamp:1
  • 設備能夠響應顯示的URL上的命令( http://iot-sensors:3001/iot/lamp1

最后的陳述是不正確的。

上下文提供者代碼設置了4個虛擬燈:

  • lamp001
  • lamp002
  • lamp003
  • lamp004

但是沒有lamp1因此,當HTTP POST請求發送到http://iot-sensors:3001/iot/lamp1 ,響應為404 Not http://iot-sensors:3001/iot/lamp1 正確定義在Orion的實體狀態中。

順便說一句,@ fgalan完全正確地指出,對於較新版本的IoT Agents,不再需要注冊-在本教程中保留該注冊純粹是為了與舊版本向后兼容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM