从 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.JdbcOdbc...