2017-06-01 37 views
2

我正嘗試使用Orion + Ultralight 2.0向設備發送命令。 設備已註冊,我可以輕鬆發送措施。我想在池模式下工作以執行命令,但是當我執行updateContext操作時,IDAS找不到實體。下面是配置和日誌:IotAgent Ultralight 2.0中的命令FIWARE

配置:

var config = {}; 

config.mqtt = { 
    host: 'mosquitto', 
    port: 1883 
}; 

config.http = { 
    port: 7896 
}; 

config.iota = { 
    logLevel: 'DEBUG', 
    timestamp: true, 
    contextBroker: { 
     host: 'MY_IP', 
     port: '1026' 
    }, 
    server: { 
     port: 4041 
    }, 
    deviceRegistry: { 
     type: 'mongodb' 
    }, 
    mongodb: { 
     host: 'mongo', 
     port: '27017', 
     db: 'iotagentul' 
    }, 
    types: {}, 
    service: 'howtoService', 
    subservice: '/howto', 
    providerUrl: 'http://YIP:4041', 
    deviceRegistrationDuration: 'P1M', 
    defaultType: 'Thing' 
}; 

config.defaultKey = 'TEF'; 

module.exports = config; 

我已經嘗試了不同的IP的和路線,並在結束時,我試圖與公網IP,確保有來自外部的那些通信端口。

設備註冊:

curl -X POST \ 
    http://MYIP:4041/iot/devices \ 
    -H 'cache-control: no-cache' \ 
    -H 'content-type: application/json' \ 
    -H 'fiware-service: howtoService' \ 
    -H 'fiware-servicepath: /howto' \ 
    -d '{ 
    "devices": [{ 
     "device_id": "muvone", 
     "protocol": "IoTA-UL", 
     "entity_name": "muvone", 
     "entity_type": "Thing", 
     "attributes": [{ 
      "object_id": "t", 
      "name": "temperature", 
      "type": "Float" 
     }], 
     "commands": [{ 
      "name":"blink", 
      "type": "command", 
      "value": "[email protected]|%s" 
     }], 
     "static_attributes": [] 
    }] 
}' 

然後我送一些意見從物理設備,並從郵差:

curl -X POST \ 
    'http://MYIP:7896/iot/d?i=muvone&k=TEF&getCmd=1' \ 
    -H 'cache-control: no-cache' \ 
    -H 'fiware-service: howtoService' \ 
    -H 'fiware-servicepath: /howto' \ 
    -d 'temperature|16' 

裏面居然能夠正確更新實體,如可以在獵戶座語境經紀人可以看出: 查詢:

curl -X GET \ 
    http://MYIP:1026/v2/entities \ 
    -H 'cache-control: no-cache' \ 
    -H 'fiware-service: howtoService' \ 
    -H 'fiware-servicepath: /howto' \ 

回覆:

[ 
    { 
    "id": "muvone", 
    "type": "Thing", 
    "TimeInstant": { 
     "type": "ISO8601", 
     "value": "2017-06-01T11:37:52.537Z", 
     "metadata": {} 
    }, 
    "blink_info": { 
     "type": "commandResult", 
     "value": " ", 
     "metadata": {} 
    }, 
    "blink_status": { 
     "type": "commandStatus", 
     "value": "UNKNOWN", 
     "metadata": {} 
    }, 
    "temperature": { 
     "type": "Float", 
     "value": "16", 
     "metadata": { 
     "TimeInstant": { 
      "type": "ISO8601", 
      "value": "2017-06-01T11:37:52.537Z" 
     } 
     } 
    } 
    } 
] 

所以,現在,如果我想發送一個命令,我已經在很多方面做了。我試着按照本指南:

http://fiware-iot-stack.readthedocs.io/en/master/topics/device_connection/index.html

所以我試圖用以下請求:

curl -X PUT \ 
    http://MYIP:1026/v2/entities \ 
    -H 'cache-control: no-cache' \ 
    -H 'content-type: application/json' \ 
    -H 'fiware-service: howtoService' \ 
    -H 'fiware-servicepath: /howto' \ 
    -d '{ 
    "id": "muvone", 
    "type": "Thing", 
    "blink": { 
    "type" : "command", 
    "value" : "true" 
    } 
}' 

哪個迴應是:

{ 
    "error": "MethodNotAllowed", 
    "description": "method not allowed" 
} 

所以我嘗試更新的單一屬性,在這種情況下是blink屬性,它是一個命令。這應該觸發Orion Context Broker充當NGSI代理並將請求傳遞給發生的IoTAgent。但問題是,IoTAgent沒有找到實體,因爲它可以在日誌中可以看出:

curl -X PUT \ 
    'http://MYIP:1026/v2/entities/muvone/attrs/blink?type=Thing' \ 
    -H 'cache-control: no-cache' \ 
    -H 'content-type: application/json' \ 
    -H 'fiware-service: howtoService' \ 
    -H 'fiware-servicepath: /howto' \ 
    -d '{ 
    "type": "command", 
    "value": "true" 
}' 

curl -X PUT \ 
    'http://MYIP:1026/v2/entities/muvone/attrs/blink?type=Thing' \ 
    -H 'cache-control: no-cache' \ 
    -H 'content-type: application/json' \ 
    -H 'fiware-service: howtoService' \ 
    -H 'fiware-servicepath: /howto' \ 
    -H 'postman-token: 6b42d06d-2a9f-3081-e315-bd9919aeded5' \ 
    -d '{ 
    "value": "true" 
}' 

會迴應:

{ 
    "error": "NotFound", 
    "description": "The requested entity has not been found. Check type and id" 
} 

編輯:的get V2 /實體獵戶結果,發出這些請求後:

[ 
    { 
    "id": "muvone", 
    "type": "Thing", 
    "TimeInstant": { 
     "type": "ISO8601", 
     "value": "2017-06-02T10:26:32.212Z", 
     "metadata": {} 
    }, 
    "blink_info": { 
     "type": "commandResult", 
     "value": " ", 
     "metadata": {} 
    }, 
    "blink_status": { 
     "type": "commandStatus", 
     "value": "UNKNOWN", 
     "metadata": {} 
    }, 
    "temperature": { 
     "type": "Float", 
     "value": "26", 
     "metadata": { 
     "TimeInstant": { 
      "type": "ISO8601", 
      "value": "2017-06-02T10:26:32.212Z" 
     } 
     } 
    } 
    } 
] 

現在,在看看獵戶座和IoTAgent日誌,可以看出,IoTAgent沒有找到實體:

獵戶日誌請求:

time=Thursday 01 Jun 12:10:13 2017.880Z | lvl=INFO | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=1496315963-946-00000000039 | from=pending | srv=pending | subsrv=pending | comp=Orion | op=logMsg.h[1832]:lmTransactionStart | msg=Starting transaction from 91.126.73.210:2880/v2/entities/muvone/attrs/blink 
time=Thursday 01 Jun 12:10:13 2017.880Z | lvl=INFO | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=1496315963-946-00000000039 | from=91.126.73.210 | srv=pending | subsrv=/howto | comp=Orion | op=rest.cpp[872]:servicePathSplit | msg=Service Path 0: '/howto' 
time=Thursday 01 Jun 12:10:13 2017.881Z | lvl=INFO | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=1496315963-946-00000000039 | from=91.126.73.210 | srv=howtoservice | subsrv=/howto | comp=Orion | op=connectionOperations.cpp[237]:collectionCount | msg=Database Operation Successful (count: { _id.id: "muvone", _id.type: "Thing", _id.servicePath: { $in: [ /^/howto$/ ] } }) 
time=Thursday 01 Jun 12:10:13 2017.881Z | lvl=INFO | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=1496315963-946-00000000039 | from=91.126.73.210 | srv=howtoservice | subsrv=/howto | comp=Orion | op=connectionOperations.cpp[92]:collectionQuery | msg=Database Operation Successful (query: { _id.id: "muvone", _id.type: "Thing", _id.servicePath: { $in: [ /^/howto$/ ] } }) 
time=Thursday 01 Jun 12:10:13 2017.881Z | lvl=INFO | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=1496315963-946-00000000039 | from=91.126.73.210 | srv=howtoservice | subsrv=/howto | comp=Orion | op=connectionOperations.cpp[175]:collectionRangedQuery | msg=Database Operation Successful (query: { query: { $or: [ { contextRegistration.entities: { $in: [ { id: "muvone", type: "Thing" }, { type: "Thing", id: "muvone" } ] } }, { contextRegistration.entities.id: { $in: [] } } ], expiration: { $gt: 1496319013 }, contextRegistration.attrs.name: { $in: [ "blink" ] }, servicePath: { $in: [ /^/howto$/ ] } }, orderby: { _id: 1 } }) 
time=Thursday 01 Jun 12:10:13 2017.882Z | lvl=INFO | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=1496315963-946-00000000040 | from=pending | srv=pending | subsrv=pending | comp=Orion | op=logMsg.h[1832]:lmTransactionStart | msg=Starting transaction to http://MYIP:4041//updateContext 
time=Thursday 01 Jun 12:10:13 2017.882Z | lvl=INFO | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=1496315963-946-00000000040 | from=pending | srv=pending | subsrv=pending | comp=Orion | op=httpRequestSend.cpp[577]:httpRequestSendWithCurl | msg=Sending message 14 to HTTP server: sending message of 558 bytes to HTTP server 
time=Thursday 01 Jun 12:10:13 2017.886Z | lvl=INFO | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=1496315963-946-00000000040 | from=pending | srv=pending | subsrv=pending | comp=Orion | op=httpRequestSend.cpp[598]:httpRequestSendWithCurl | msg=Notification Successfully Sent to http://MYIP:4041//updateContext 
time=Thursday 01 Jun 12:10:13 2017.886Z | lvl=INFO | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=1496315963-946-00000000040 | from=pending | srv=pending | subsrv=pending | comp=Orion | op=logMsg.h[1916]:lmTransactionEnd | msg=Transaction ended 
time=Thursday 01 Jun 12:10:13 2017.886Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=postUpdateContext.cpp[225]:updateForward | msg=Internal Error (error parsing reply from prov app:) 
time=Thursday 01 Jun 12:10:13 2017.886Z | lvl=INFO | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=logMsg.h[1916]:lmTransactionEnd | msg=Transaction ended 

IDAS日誌:

time=2017-06-01T12:10:13.882Z | lvl=DEBUG | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=8dcc19e7-e3ce-472a-a1bb-c7983dad7025 | op=IoTAgentNGSI.GenericMiddlewares | srv=howtoservice | subsrv=/howto | msg=Request for path [//updateContext] from [MYIP:4041] | comp=IoTAgent 
time=2017-06-01T12:10:13.882Z | lvl=DEBUG | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=8dcc19e7-e3ce-472a-a1bb-c7983dad7025 | op=IoTAgentNGSI.GenericMiddlewares | srv=howtoservice | subsrv=/howto | msg=Body: 

{ 
    "contextElements": [ 
     { 
      "type": "Thing", 
      "isPattern": "false", 
      "id": "muvone", 
      "attributes": [ 
       { 
        "name": "blink", 
        "type": "command", 
        "value": "true" 
       } 
      ] 
     } 
    ], 
    "updateAction": "UPDATE" 
} 

| comp=IoTAgent 
time=2017-06-01T12:10:13.883Z | lvl=DEBUG | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=8dcc19e7-e3ce-472a-a1bb-c7983dad7025 | op=IoTAgentNGSI.ContextServer | srv=howtoservice | subsrv=/howto | msg=Handling update from [MYIP:4041] | comp=IoTAgent 
time=2017-06-01T12:10:13.883Z | lvl=DEBUG | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=8dcc19e7-e3ce-472a-a1bb-c7983dad7025 | op=IoTAgentNGSI.ContextServer | srv=howtoservice | subsrv=/howto | msg=[object Object] | comp=IoTAgent 
time=2017-06-01T12:10:13.883Z | lvl=DEBUG | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=8dcc19e7-e3ce-472a-a1bb-c7983dad7025 | op=IoTAgentNGSI.MongoDBDeviceRegister | srv=howtoservice | subsrv=/howto | msg=Looking for entity with name [muvone]. | comp=IoTAgent 
time=2017-06-01T12:10:13.883Z | lvl=DEBUG | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=8dcc19e7-e3ce-472a-a1bb-c7983dad7025 | op=IoTAgentNGSI.MongoDBDeviceRegister | srv=howtoservice | subsrv=/howto | msg=Entity [muvone] not found. | comp=IoTAgent 
time=2017-06-01T12:10:13.884Z | lvl=DEBUG | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=8dcc19e7-e3ce-472a-a1bb-c7983dad7025 | op=IoTAgentNGSI.ContextServer | srv=howtoservice | subsrv=/howto | msg=There was an error handling the update action: [object Object]. | comp=IoTAgent 
time=2017-06-01T12:10:13.884Z | lvl=DEBUG | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=8dcc19e7-e3ce-472a-a1bb-c7983dad7025 | op=IoTAgentNGSI.ContextServer | srv=howtoservice | subsrv=/howto | msg=Update error [ENTITY_NOT_FOUND] handing request: The entity with the requested id [muvone] was not found. | comp=IoTAgent 
time=2017-06-01T12:10:13.884Z | lvl=DEBUG | corr=446f4532-46c3-11e7-b1a4-0242ac110003 | trans=8dcc19e7-e3ce-472a-a1bb-c7983dad7025 | op=IoTAgentNGSI.DomainControl | srv=howtoservice | subsrv=/howto | msg=response-time: 2 | comp=IoTAgent 

在mongo數據庫中,可以看到註冊,實體和所有內容都正確設置。

我已經解決這個問題,工作了幾天沒有結果。 任何幫助將不勝感激。在此先感謝

UPDATE

使用獵戶座API的V1之後,結果是一樣的是,通過V2給出:

curl -X POST \ 
    http://MYIP:1026/v1/updateContext \ 
    -H 'cache-control: no-cache' \ 
    -H 'content-type: application/json' \ 
    -H 'fiware-service: howtoService' \ 
    -H 'fiware-servicepath: /howto' \ 
    -d '{ 
    "contextElements": [ 
     { 
      "type": "Thing", 
      "isPattern": "false", 
      "id": "muvone", 
      "attributes": [ 
       { 
        "name": "blink", 
        "type": "command", 
        "value": "true" 
       } 
      ] 
     } 
    ], 
    "updateAction": "UPDATE" 
} ' 

結果:

{ 
    "errorCode": { 
    "code": "404", 
    "reasonPhrase": "No context element found" 
    } 
} 

第二個更新 我有一個服務,發送命令我iss用於上下文代理。不同的是,如果該命令被在設備中,將其與404錯誤響應定義,但是,如果它沒有在preprovision所定義,將其與代碼472進行響應:

未定義命令

curl -X POST \ 
    http://localhost:3000/api/devices/1111/sendCommand/update_firmware \ 
    -H 'cache-control: no-cache' \ 
    -H 'content-type: application/json' \ 
    -d '{ 
    "value":"example value" 
}' 

472:

{ 
    "contextResponses": [ 
    { 
     "contextElement": { 
     "type": "Thing", 
     "isPattern": "false", 
     "id": "muvone", 
     "attributes": [ 
      { 
      "name": "update_firmware", 
      "type": "command", 
      "value": "" 
      } 
     ] 
     }, 
     "statusCode": { 
     "code": "472", 
     "reasonPhrase": "request parameter is invalid/not allowed", 
     "details": "action: UPDATE - entity: [muvone, Thing] - offending attribute: update_firmware" 
     } 
    } 
    ] 
} 

定義命令:

curl -X POST \ 
    http://localhost:3000/api/devices/1111/sendCommand/blink \ 
    -H 'cache-control: no-cache' \ 
    -H 'content-type: application/json' \ 
    -d '{ 
    "value":"asd" 
}' 

404:

{ 
    "errorCode": { 
    "code": "404", 
    "reasonPhrase": "No context element found" 
    } 
} 
+0

你可以編輯你的問題的帖子,包括了'GET/V2/entities'結果* *後你做'PUT/v2 /實體/ muvone/attrs/blink?type = Thing',please?謝謝! – fgalan

+0

更新和編輯。結果不顯示任何我可以注意到的不同信息 – JoseBenitez

+0

新的更新。定義的命令給出了404和未定義的命令給出了472 – JoseBenitez

回答

2

我發現了這個問題的解決方案,我認爲它必須被視爲一個錯誤。這是一個問題camelcases。 就我而言,我是用頭howtoService爲Fiware服務頭,並在數據庫中正確存儲:

{ "_id" : ObjectId("5935316c4cfcb20001ec6181"), "polling" : true, "transport" : "HTTP", "protocol" : "IoTA-UL", "internalId" : null, "registrationId" : "5935316c5937ac933167d477", "subservice" : "/howto", "service" : "howtoService", "name" : "muvone", "type" : "Thing", "id" : "muvone", "creationDate" : ISODate("2017-06-05T10:24:44.336Z"), "subscriptions" : [ ], "staticAttributes" : [ ], "commands" : [ { "object_id" : "blink", "value" : "[email protected]|%s", "type" : "command", "name" : "blink" } ], "active" : [ { "type" : "Float", "name" : "temperature", "object_id" : "ta" } ], "__v" : 0 } 

但是,當從IOTAgent操作來臨時,它採用小寫,導致從蒙戈過濾器找不到操作:

{ "op" : "query", "ns" : "iotagentul.devices", "query" : { "find" : "devices", "filter" : { "subservice" : "/howto", "service" : "howtoservice", "name" : "muvone" }, "projection" : { "__v" : 0 }, "limit" : 1, "batchSize" : 1, "singleBatch" : true }, "keysExamined" : 0, "docsExamined" : 1, "cursorExhausted" : true, "keyUpdates" : 0, "writeConflicts" : 0, "numYield" : 0, "locks" : { "Global" : { "acquireCount" : { "r" : NumberLong(2) } }, "Database" : { "acquireCount" : { "r" : NumberLong(1) } }, "Collection" : { "acquireCount" : { "r" : NumberLong(1) } } }, "nreturned" : 0, "responseLength" : 124, "protocol" : "op_query", "millis" : 0, "execStats" : { "stage" : "LIMIT", "nReturned" : 0, "executionTimeMillisEstimate" : 0, "works" : 3, "advanced" : 0, "needTime" : 2, "needYield" : 0, "saveState" : 0, "restoreState" : 0, "isEOF" : 1, "invalidates" : 0, "limitAmount" : 1, "inputStage" : { "stage" : "PROJECTION", "nReturned" : 0, "executionTimeMillisEstimate" : 0, "works" : 3, "advanced" : 0, "needTime" : 2, "needYield" : 0, "saveState" : 0, "restoreState" : 0, "isEOF" : 1, "invalidates" : 0, "transformBy" : { "__v" : 0 }, "inputStage" : { "stage" : "COLLSCAN", "filter" : { "$and" : [ { "name" : { "$eq" : "muvone" } }, { "service" : { "$eq" : "howtoservice" } }, { "subservice" : { "$eq" : "/howto" } } ] }, "nReturned" : 0, "executionTimeMillisEstimate" : 0, "works" : 3, "advanced" : 0, "needTime" : 2, "needYield" : 0, "saveState" : 0, "restoreState" : 0, "isEOF" : 1, "invalidates" : 0, "direction" : "forward", "docsExamined" : 1 } } }, "ts" : ISODate("2017-06-05T10:40:37.401Z"), "client" : "172.17.0.4", "allUsers" : [ ], "user" : "" } 

數據庫更新howtoService到howtoservice後,命令工作正常

+0

原因是FIWARE服務被用作MongoDB數據庫的一部分,用於存儲與設備相關的實體。由於MongoDB聲明「由於數據庫名稱在MongoDB中不區分大小寫,因此數據庫名稱不能僅在字符的情況下不同」,Orion CB會將接收到的FIWARE服務從代理中進行降級。 – frb

0

不知道什麼,我會說會解決你的問題,但有些東西要考慮到,閱讀你的問題後:

  • ,這是正常PUT /v2/entities導致「法不允許」。考慮到根據NGSIv2 specification/v2/entities URL只接受動詞:GET(檢索實體列表)和POST(創建新實體)。這不是更新現有實體的方式。
  • 關於「找不到」的錯誤,您會收到PUT /v2/entities/muvone/attrs/blink?type=Thing,請查看此issue report。根據這些信息,該命令正在發展,事實上,這種情況正在發生(作爲IOTA日誌中的第二行顯示)。
+0

非常感謝@fgalan。關於方法不允許,你是完全正確的。我只想說,FIWARE IoT Stack的文檔是錯誤的:[鏈接](http://fiware-iot-stack.readthedocs.io/en/master/topics/device_connection/index.html) After嘗試使用API​​的v1,我仍然發現404錯誤代碼 – JoseBenitez

+0

此結果現在已在問題 – JoseBenitez

+0

中更新注意到文檔錯誤:https://github.com/telefonicaid/fiware-iot-stack/issues/70 。謝謝! – fgalan