我正在使用IoT代理进行超轻量级传输,我想将命令(包括特定值)发送回我的IoT设备。如果我按照智能门here的示例进行操作,则可以发送以下内容:
curl -iX PATCH \
'http://localhost:1026/v2/entities/urn:ngsi-ld:pysense:002/attrs' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"color": {
"type" : "command",
"value" : "100"
}
}'
固件发布有效载荷“ urn:ngsi-ld:pysense:002 @ color |”给我的经纪人。但是我也希望传递“ 100”的值吗?
我还在Git上找到了this有关mqtt命令的文档。但是那个没有指定将其发送到哪里以及如何发送?我想它使用与this请求相同的URL:http://localhost:4041/v1/updateContext ??这是最新的发出命令的方式吗?
我正在使用Orion-ld和iotagent-ul:1.8.0。
有人可以帮助我将“颜色”的价值也纳入mqtt消息吗?
谢谢!
EDIT1:
我刚刚尝试过orion:2.2.0并重新注册了命令,如下所示:
{
"description": "Setting LED",
"dataProvided": {
"entities": [
{
"id": "urn:ngsi-ld:pysense:002", "type": "pysense"
}
],
"attrs": ["color", "brightness"]
},
"provider": {
"http": {"url": "http://orion:1026/v2"},
"legacyForwarding": true
}
}
如果我尝试发送orion-log命令,请输入以下文本发疯(继续滚动):
fiware-orion | INFO@06:42:33 logMsg.h[1844]: Starting transaction from 172.18.1.1:35800/v2/entities/urn:ngsi-ld:pysense:002/attrs
fiware-orion | INFO@06:42:33 rest.cpp[885]: Service Path 0: '/dresden'
fiware-orion | INFO@06:42:33 connectionOperations.cpp[239]: Database Operation Successful (count: { _id.id: "urn:ngsi-ld:pysense:002", _id.servicePath: { $in: [ /^/dresden$/ ] } })
fiware-orion | INFO@06:42:33 connectionOperations.cpp[94]: Database Operation Successful (query: { _id.id: "urn:ngsi-ld:pysense:002", _id.servicePath: { $in: [ /^/dresden$/ ] } })
fiware-orion | INFO@06:42:33 connectionOperations.cpp[94]: Database Operation Successful (query: { $or: [ { entities.id: "urn:ngsi-ld:pysense:002", $or: [ { entities.type: "pysense" }, { entities.type: { $exists: false } } ], entities.isPattern: "false", entities.isTypePattern: { $ne: true }, expiration: { $gt: 1559716953 }, status: { $ne: "inactive" }, servicePath: { $in: [ /^$|^/#$|^/dresden/#$|^/dresden$/, null ] } }, { entities.isPattern: "true", entities.isTypePattern: { $ne: true }, expiration: { $gt: 1559716953 }, status: { $ne: "inactive" }, servicePath: { $in: [ /^$|^/#$|^/dresden/#$|^/dresden$/, null ] }, $where: function(){for (var i=0; i < this.entities.length; i++) {if (this.enti... }, { entities.isPattern: "false", entities.isTypePattern: true, expiration: { $gt: 1559716953 }, status: { $ne: "inactive" }, servicePath: { $in: [ /^$|^/#$|^/dresden/#$|^/dresden$/, null ] }, $where: function(){for (var i=0; i < this.entities.length; i++) {if (this.enti... }, { entities.isPattern: "true", entities.isTypePattern: true, expiration: { $gt: 1559716953 }, status: { $ne: "inactive" }, servicePath: { $in: [ /^$|^/#$|^/dresden/#$|^/dresden$/, null ] }, $where: function(){for (var i=0; i < this.entities.length; i++) {if (this.enti... } ] })
fiware-orion | INFO@06:42:33 connectionOperations.cpp[177]: Database Operation Successful (query: { query: { $or: [ { contextRegistration.entities: { $in: [ { id: "urn:ngsi-ld:pysense:002", type: "pysense" }, { type: "pysense", id: "urn:ngsi-ld:pysense:002" } ] } }, { contextRegistration.entities.id: { $in: [] } } ], expiration: { $gt: 1559716953 }, contextRegistration.attrs.name: { $in: [ "color" ] }, servicePath: { $in: [ /^/dresden$/ ] } }, orderby: { _id: 1 } })
fiware-orion | ERROR@06:42:33 postUpdateContext.cpp[553]: Internal Error (attribute 'color' not found)
fiware-orion | INFO@06:42:33 logMsg.h[1844]: Starting transaction to http://orion:1026/v1/updateContext
fiware-orion | INFO@06:42:33 httpRequestSend.cpp[592]: Sending message 8 to HTTP server: sending message of 433 bytes to HTTP server
fiware-orion | INFO@06:42:33 logMsg.h[1844]: Starting transaction from 172.18.1.7:46738/v1/updateContext
fiware-orion | INFO@06:42:33 rest.cpp[885]: Service Path 0: '/dresden'
fiware-orion | INFO@06:42:33 connectionOperations.cpp[94]: Database Operation Successful (query: { _id.id: "urn:ngsi-ld:pysense:002", _id.type: "pysense", _id.servicePath: { $in: [ /^/dresden$/ ] } })
fiware-orion | INFO@06:42:34 connectionOperations.cpp[94]: Database Operation Successful (query: { $or: [ { entities.id: "urn:ngsi-ld:pysense:002", $or: [ { entities.type: "pysense" }, { entities.type: { $exists: false } } ], entities.isPattern: "false", entities.isTypePattern: { $ne: true }, expiration: { $gt: 1559716953 }, status: { $ne: "inactive" }, servicePath: { $in: [ /^$|^/#$|^/dresden/#$|^/dresden$/, null ] } }, { entities.isPattern: "true", entities.isTypePattern: { $ne: true }, expiration: { $gt: 1559716953 }, status: { $ne: "inactive" }, servicePath: { $in: [ /^$|^/#$|^/dresden/#$|^/dresden$/, null ] }, $where: function(){for (var i=0; i < this.entities.length; i++) {if (this.enti... }, { entities.isPattern: "false", entities.isTypePattern: true, expiration: { $gt: 1559716953 }, status: { $ne: "inactive" }, servicePath: { $in: [ /^$|^/#$|^/dresden/#$|^/dresden$/, null ] }, $where: function(){for (var i=0; i < this.entities.length; i++) {if (this.enti... }, { entities.isPattern: "true", entities.isTypePattern: true, expiration: { $gt: 1559716953 }, status: { $ne: "inactive" }, servicePath: { $in: [ /^$|^/#$|^/dresden/#$|^/dresden$/, null ] }, $where: function(){for (var i=0; i < this.entities.length; i++) {if (this.enti... } ] })
fiware-orion | INFO@06:42:34 connectionOperations.cpp[177]: Database Operation Successful (query: { query: { $or: [ { contextRegistration.entities: { $in: [ { id: "urn:ngsi-ld:pysense:002", type: "pysense" }, { type: "pysense", id: "urn:ngsi-ld:pysense:002" } ] } }, { contextRegistration.entities.id: { $in: [] } } ], expiration: { $gt: 1559716954 }, contextRegistration.attrs.name: { $in: [ "color" ] }, servicePath: { $in: [ /^/dresden$/ ] } }, orderby: { _id: 1 } })
fiware-orion | INFO@06:42:34 logMsg.h[1844]: Starting transaction to http://orion:1026/v1/updateContext
...
我在邮递员中得到以下错误作为答复:
{
"error": "NotFound",
"description": "The requested entity has not been found. Check type and id"
}
当orion自行注册命令时,它看起来像是使用iot-agent作为提供者,而不是orion / v1:
{
"id": "5cf677b7c7ecc4737e1e0ec9",
"expires": "2020-06-04T13:52:55.00Z",
"dataProvided": {
"entities": [
{
"id": "urn:ngsi-ld:pysense:002",
"type": "pysense"
}
],
"attrs": [
"color",
"brightness"
]
},
"provider": {
"http": {
"url": "http://iot-agent:4041"
},
"supportedForwardingMode": "all",
"legacyForwarding": true
},
"status": "active"
}
这样我实际上可以发送命令,但是它仍然会丢失值。 :(
EDIT2: 我在orion的大量调试日志中发现了一些东西:
fiware-orion | INFO@07:35:09 connectionOperations.cpp[177]: Database Operation Successful (query: { query: { $or: [ { contextRegistration.entities: { $in: [ { id: "urn:ngsi-ld:pysense:002", type: "pysense" }, { type: "pysense", id: "urn:ngsi-ld:pysense:002" } ] } }, { contextRegistration.entities.id: { $in: [] } } ], expiration: { $gt: 1559720109 }, contextRegistration.attrs.name: { $in: [ "color" ] }, servicePath: { $in: [ /^/dresden$/ ] } }, orderby: { _id: 1 } })
fiware-orion | ERROR@07:35:09 postUpdateContext.cpp[553]: Internal Error (attribute 'color' not found)
之后,IoT-Agent将更新上下文,但没有值。
答案 0 :(得分:1)
有两个解决此问题的方法。与教程不同的第一件事是需要使用命令注册的提供程序。代替orion:1026 / v1注册IoT-Agent。它应该看起来像这样,将docker-compose.yml中的IOTA_PROVIDER_URL作为提供程序:
{
"description": "Setting LED",
"dataProvided": {
"entities": [
{
"id": "urn:ngsi-ld:pysense:002",
"type": "pysense"
}
],
"attrs": [
"color",
"brightness"
]
},
"provider": {
"http": {
"url": "http://iot-agent:4041"
},
"supportedForwardingMode": "all",
"legacyForwarding": true
},
"status": "active"
}
现在,您可以通过两种方式发送命令。第一个直接通过oror / v1 / updateContext的POST命令到达IoT Agent的北端口。第二种方法是通过向实体属性发送PATCH命令,在上下文中更新命令,为请求提供实体的类型。
1:发布到updateContext
curl -iX POST \
'http://localhost:1026/v1/updateContext' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"contextElements": [
{
"type": "pysense",
"isPattern": "false",
"id": "urn:ngsi-ld:pysense:002",
"attributes": [
{
"name": "color",
"type": "command",
"value": "25"
}
]
}
],
"updateAction": "UPDATE"
}
2:PATCH添加实体类型
curl -iX PATCH \
'http://localhost:1026/v2/entities/urn_ngsi-ld:pysense:002/attrs?type=pysense' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"color": {
"type" : "command",
"value" : "90"
}
}
感谢fgalan提供的帮助!