首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Fiware IoT代理UL:通过mqtt向设备发送command_value

Fiware IoT代理UL:通过mqtt向设备发送command_value
EN

Stack Overflow用户
提问于 2019-06-03 12:55:44
回答 1查看 261关注 0票数 1

我正在使用物联网代理的超光,我想发送一个命令(包括一个特定的值)回到我的物联网设备。如果我以智能门这里为例,我可以发送以下内容:

代码语言:javascript
复制
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"
    }
  }'

Fiware向我的mqtt-broker发布有效负载“urn:ngsi-ld:pysense:002@color”。但我希望"100“的价值也会被传递?

我还找到了关于mqtt-命令的文档。但这一条没有具体说明在哪里发送,以及如何发送?我想它使用与请求相同的URL:http://localhost:4041/v1/updateContext?这是最新的方式来发出命令吗?

我正在使用Orion和iotagent-ul:1.8.0。

有人能帮我把“颜色”的值也输入到mqtt-消息中吗?

谢谢!

EDIT1:

我刚刚尝试过orion:2.2.0并重新注册了命令如下:

代码语言:javascript
复制
{
  "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“疯狂”(继续滚动):

代码语言:javascript
复制
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
...

我在“邮递员”中得到了以下错误的回复:

代码语言:javascript
复制
{
    "error": "NotFound",
    "description": "The requested entity has not been found. Check type and id"
}

当orion单独注册命令时,它看起来像这样,以物联网代理作为提供者,而不是orion/v1:

代码语言:javascript
复制
    {
        "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的广泛调试日志中找到的

代码语言:javascript
复制
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)

在此之后,物联网代理会更新上下文,但没有值。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-06 07:43:48

这个问题有两个解决办法。与本教程不同的第一件事是您需要向命令注册的提供者。而不是orion:1026/v1注册物联网代理。它应该是这样的,您的docker-compose.yml中的IOTA_PROVIDER_URL作为提供程序:

代码语言:javascript
复制
{
        "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"
    }

现在您可以通过两种方式发送命令。第一个命令直接指向IoT代理的北端端口,并向orion/v1/updateContext发出POST命令。第二种方法是通过向实体属性发送补丁命令来更新上下文中的命令,向请求提供实体的类型。

1: POST到updateContext

代码语言:javascript
复制
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:添加实体类型的修补程序

代码语言:javascript
复制
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对此的帮助!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56427851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档