Fiware IoT代理UL:通过mqtt将command_value发送到设备 [英] Fiware IoT Agent UL: Send command_value via mqtt to device
问题描述
我正在使用IoT代理进行超轻量级传输,我想将命令(包括特定值)发送回我的IoT设备.如果我按照智能门示例操作,请在此处我可以发送类似以下内容:
I am using the IoT-agent for ultra light and I'd like to send a command (including a specific value) back to my IoT-Device. If I follow the example for a smart door here I can send something like:
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"的值吗?
Fiware publishes the payload "urn:ngsi-ld:pysense:002@color|" to my mqtt-broker. But I would expect the value of "100" to be passed as well?
我还找到了此文档在Git上有关mqtt-commands的信息.但是那个没有指定将其发送到哪里以及如何发送?我想它使用与此请求相同的URL: http://localhost:4041/v1/updateContext ??这是最新的发出命令的方式吗?
I also found this documentation on Git regarding mqtt-commands. But that one does not specify where to send that and how? I suppose it uses the the same URL as this request: http://localhost:4041/v1/updateContext ?? Is that the up-to-date way to issue commands?
我正在使用Orion-ld和iotagent-ul:1.8.0.
I am using Orion-ld and the iotagent-ul:1.8.0.
有人可以帮助我将颜色"的价值也应用到mqtt消息中吗?
Can somebody help me getting the value of "color" into the mqtt-message as well?
谢谢!
我刚刚尝试过orion:2.2.0并重新注册了命令,如下所示:
I just tried orion:2.2.0 and reregistered the command like this:
{
"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命令,请输入以下文本发疯(继续滚动):
If i try to send the command orion-logs go crazy (keep scrolling) with the following text:
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
...
在邮递员中,我收到以下错误作为答复:
And I get the following error as a reply in Postman:
{
"error": "NotFound",
"description": "The requested entity has not been found. Check type and id"
}
当orion自己注册命令时,它看起来像是用iot-agent作为提供者,而不是orion/v1:
When orion registers the command by itself it looks like this with the iot-agent as provider instead of 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"
}
这样,我实际上可以发送命令,但是它仍然会丢失该值.:(
With that I can actually send a command but it still misses the value. :(
我在orion的大量调试日志中发现了一些东西:
Something I found in the extensive debug logs of 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将更新上下文,但没有值.
After that the IoT-Agent updates the context but without a value.
推荐答案
有两个针对此问题的修复程序.与教程不同的第一件事是需要使用命令注册的提供程序.代替orion:1026/v1注册IoT-Agent.它应该看起来像这样,将docker-compose.yml中的IOTA_PROVIDER_URL作为提供程序:
There are two fixes to that problem. First thing that differs from the tutorial is the provider you need to register with a command. Instead of orion:1026/v1 register the IoT-Agent. It should look something like this with the IOTA_PROVIDER_URL from your docker-compose.yml as provider:
{
"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"
}
现在,您可以通过两种方式发送命令.第一个是使用orion/v1/updateContext的POST命令直接连接到IoT Agent的北端口.第二种方法是通过向实体属性发送PATCH命令,在上下文中更新命令,从而为请求提供实体的类型.
Now you can send a command in two ways. The first one is directly to the north port of the IoT Agent with a POST command to orion/v1/updateContext. The second one is to update the command in the context by sending a PATCH command to the entities attributes, providing the type of the entity to the request.
1:POST到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提供的帮助!
Thanks to fgalan for the help with that!
这篇关于Fiware IoT代理UL:通过mqtt将command_value发送到设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!