微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从 STH-Comet 查询数据时获取空值

如何解决从 STH-Comet 查询数据时获取空值

这是我在 IoT 代理上配置服务组的方式

url = 'http://localhost:4041/iot/services'
headers = {'Content-Type': "application/json",'fiware-service': "smartparking_pmr",'fiware-servicepath': "/mtp"}

data = {
 "services": [
   {
     "apikey":      "4jggokgpepnvsb2uv4s40d59ov","cbroker":     "http://orion:1026","entity_type": "PMR","resource":    "/iot/d"
   }
 ]
}

然后我注册了设备。

url = 'http://localhost:4041/iot/devices'
headers = {'Content-Type': "application/json",'fiware-servicepath': "/mtp"}

data = {
 "devices": [
   {
     "device_id":   "711","entity_name": "urn:ngsi-ld:Pmr:711","timezone":    "Europe/Berlin","attributes": [
        { "object_id": "s","name": "SlotStatus","type": "Integer" },{ "object_id": "lat","name": "Latitude","type": "Double" },{ "object_id": "lon","name": "Longitude","type": "Double" }
      ]
   }
 ]
}

接下来我订阅 Orion Context broker。

curl -iX POST \
  'http://localhost:1026/v2/subscriptions/' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: openiot' \
  -H 'fiware-servicepath: /' \
  -d '{
  "description": "Notify STH-Comet of all smartparking_pmr SlotStatus changes","subject": {
    "entities": [
      {
        "idPattern": "Pmr.*"
      }
    ],"condition": {"attrs": ["SlotStatus"] }
  },"notification": {
    "http": {
      "url": "http://sth-comet:8666/notify"
    },"attrs": [
      "SlotStatus"
    ],"attrsFormat": "legacy"
  }
}'

在我从设备发送一些测量值之后。

url = 'http://localhost:7896/iot/d?i=711&k=4jggokgpepnvsb2uv4s40d59ov'
headers = {'Content-Type': "text/plain",'fiware-servicepath': "/mtp"}

data = "s|0|lat|13.3903|lon|52.5075"
data_raw = data.encode('utf-8')

res = requests.post(url,data=data_raw,headers=headers)

我检查了订阅是否存在于 Orion。

curl -X GET 
  'http://localhost:1026/v2/subscriptions/' 
  -H 'fiware-service: smartparking_pmr' 
  -H 'fiware-servicepath: '/mtp"

就是这样(您可以看到来自设备的最后一次更新)

[{"id":"6037a3e82e21184c83eeeadd","description":"Notify STH-Comet of all smartparking_pmr SlotStatus changes","status":"active","subject":{"entities":[{"idPattern":"Pmr.*"}],"condition":{"attrs":["SlotStatus"]}},"notification":{"timesSent":15,"lastNotification":"2021-02-25T14:35:37.000Z","attrs":["SlotStatus"],"onlyChangedAttrs":false,"attrsFormat":"legacy","http":{"url":"http://sth-comet:8666/notify"},"lastSuccess":"2021-02-25T14:35:37.000Z","lastSuccessCode":200}},{"id":"6037b1742e21184c83eeeade","condition":{"attrs":["s"]}},"notification":{"attrs":["s"],"http":{"url":"http://sth-comet:8666/notify"}}},{"id":"6037b91e072e0f6c2a7d46e2",{"id":"6037b95c072e0f6c2a7d46e3","notification":{"timesSent":1,"lastNotification":"2021-02-25T14:51:08.000Z","lastSuccess":"2021-02-25T14:51:08.000Z","lastSuccessCode":400}},{"id":"6037b95f072e0f6c2a7d46e4","lastNotification":"2021-02-25T14:51:11.000Z","lastSuccess":"2021-02-25T14:51:11.000Z","lastSuccessCode":400}}]

最后我想从 STH-Comet 查询数据。

curl "http://localhost:8666/STH/v1/contextEntities/type/PMR/id/Pmr:711/attributes/SlotStatus?lastN=10" --header "fiware-service: smartparking_pmr" --header "fiware-servicepath: /mtp"

但无论出于何种原因,我都会得到空值。

{"contextResponses":[{"contextElement":{"attributes":[{"name":"SlotStatus","values":[]}],"id":"Pmr:711","isPattern":false,"type":"PMR"},"statusCode":{"code":"200","reasonPhrase":"OK"}}]}

这是来自 STH-Comet 控制台的日志。

time=2021-02-25T14:56:57.921Z | lvl=DEBUG | corr=2dd3ef29-df47-4520-9ee3-c0dfccd5a51b | trans=2dd3ef29-df47-4520-9ee3-c0dfccd5a51b | op=OPER_STH_GET | from=n/a | srv=smartparking_pmr | subsrv=/mtp | comp=STH | msg=GET /STH/v1/contextEntities/type/PMR/id/Pmr:711/attributes/SlotStatus?lastN=10

time=2021-02-25T14:56:57.921Z | lvl=DEBUG | corr=2dd3ef29-df47-4520-9ee3-c0dfccd5a51b | trans=2dd3ef29-df47-4520-9ee3-c0dfccd5a51b | op=OPER_STH_GET | from=n/a | srv=smartparking_pmr | subsrv=/mtp | comp=STH | msg=Getting access to the raw data collection for retrieval...

time=2021-02-25T14:56:57.924Z | lvl=WARN | corr=2dd3ef29-df47-4520-9ee3-c0dfccd5a51b | trans=2dd3ef29-df47-4520-9ee3-c0dfccd5a51b | op=OPER_STH_GET | from=n/a | srv=smartparking_pmr | subsrv=/mtp | comp=STH | msg=Error when getting the raw data collection for retrieval (the collection 'null' may not exist)

time=2021-02-25T14:56:57.924Z | lvl=DEBUG | corr=2dd3ef29-df47-4520-9ee3-c0dfccd5a51b | trans=2dd3ef29-df47-4520-9ee3-c0dfccd5a51b | op=OPER_STH_GET | from=n/a | srv=smartparking_pmr | subsrv=/mtp | comp=STH | msg=Responding with no points

这很奇怪,因为我可以通过查询 Orion 看到测量记录。

curl -v http://localhost:1026/v2/entities/urn:ngsi-ld:Pmr:711 --header "Fiware-Service: smartparking_pmr" --header "Fiware-ServicePath: /mtp"

给出:

{"id":"urn:ngsi-ld:Pmr:711","type":"PMR","Latitude":{"type":"Double","value":"13.3903","Metadata":{"TimeInstant":{"type":"DateTime","value":"2021-02-25T14:35:35.743Z"}}},"Longitude":{"type":"Double","value":"52.5075","SlotStatus":{"type":"Integer","value":"0","TimeInstant":{"type":"DateTime","value":"2021-02-25T14:35:35.743Z","Metadata":{}}}

能帮帮我吗?提前致谢。

问候,

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?