Fiware IoAgent Ultralight 2.0固件中的命令
我正在尝试使用Orion+Ultralight 2.0向设备发送命令。 该设备已注册,我可以轻松发送测量值。我想在池模式下工作以执行命令,但是当我执行updateContext操作时,IDAS没有找到实体。以下是配置和日志:Fiware IoAgent Ultralight 2.0固件中的命令,fiware,fiware-orion,Fiware,Fiware Orion,我正在尝试使用Orion+Ultralight 2.0向设备发送命令。 该设备已注册,我可以轻松发送测量值。我想在池模式下工作以执行命令,但是当我执行updateContext操作时,IDAS没有找到实体。以下是配置和日志: curl -X PUT \ 'http://MYIP:1026/v2/entities/muvone/attrs/blink?type=Thing' \ -H 'cache-control: no-cache' \ -H 'content-type: appli
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"
}'
配置:
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": "muvone@blink|%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'
它实际上正确地更新了实体,如Orion Context Broker中所示:
查询:
答复:
[
{
"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"
}
}
}
}
]
所以现在,如果我想发送一个命令,我已经用了很多方法。我试着遵循这个指南:
因此,我尝试使用以下请求:
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"
}
因此,我尝试更新单个属性,在本例中是闪烁属性,这是一个命令。这将触发Orion上下文代理充当NGSI代理并将请求传递给IoTAgent,这将发生。但问题是IoAgent找不到实体,从日志中可以看出:
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"
}'
或
答复如下:
{
"error": "NotFound",
"description": "The requested entity has not been found. Check type and id"
}
编辑:发出这些请求后,get v2/entities to orion结果为:
[
{
"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"
}
}
}
}
]
现在,查看Orion和IoAgent日志,可以发现IoAgent没有找到实体:
Orion登录到请求:
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数据库中,可以看到注册、实体和所有内容都已正确设置
我已经围绕这个问题工作了好几天,没有结果。
任何帮助都将不胜感激。提前谢谢
更新
使用Orion 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"
}
}
第二次更新
我有一个服务,它将我发出的命令发送给上下文代理。不同之处在于,如果该命令在设备中定义,则响应404错误,但如果该命令未在预提供中定义,则响应代码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:
定义的命令:
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:
我不确定我要说什么能解决你的问题,但在阅读你的问题后,需要考虑一些事情:
导致“方法不允许”是正常的。考虑到根据,URL仅接受动词:GET(检索实体列表)和POST(创建新实体)。这不是更新现有实体的方式PUT/v2/entities
- 关于您在
时遇到的“未找到”错误,请查看此错误。根据该信息,该命令正在执行,事实上,这在您的案例中正在发生(如IOTA日志中的第二行所示)PUT/v2/entities/muvone/attrs/blink?type=Thing
{ "_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" : "muvone@blink|%s", "type" : "command", "name" : "blink" } ], "active" : [ { "type" : "Float", "name" : "temperature", "object_id" : "ta" } ], "__v" : 0 }
但是,当来自IoAgent的操作出现时,它使用小写字母,导致来自mongo筛选器的找不到操作:
{ "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后,该命令工作正常请在执行
PUT/v2/entities/muvone/attrs/blink?type=Thing
之后,编辑您的问题帖子以包含GET/v2/entities
结果,好吗?谢谢!更新和编辑。结果没有显示任何我可以注意到的新更新的不同信息。定义的命令给出了404,而未定义的命令给出了472很多@fgalan。关于不允许的方法,你是完全正确的。我只想指出,FIWARE IoT堆栈的文档是错误的:在尝试API的v1之后,我仍然发现404错误代码记录了文档错误:。谢谢嗨@fgalan我找到了问题的答案,我想我可能发现了一个bug。再次感谢您的努力:)很高兴知道您终于找到了解决方案!:)原因是FIWARE服务被用作MongoDB数据库的一部分,用于存储与设备相关的实体。由于MongoDB声明“由于数据库名称在MongoDB中不区分大小写,因此数据库名称不能仅因字符大小写不同而不同”,Orion CB将从代理接收的FIWARE服务小写。
{
"errorCode": {
"code": "404",
"reasonPhrase": "No context element found"
}
}
{ "_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" : "muvone@blink|%s", "type" : "command", "name" : "blink" } ], "active" : [ { "type" : "Float", "name" : "temperature", "object_id" : "ta" } ], "__v" : 0 }
{ "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" : "" }