订阅后没有来自 Orion Context Broker 的通知

No notification from Orion Context Broker after Subscription

我有自己的 Orion Context Broker 实例,我正在使用 IDAS 和我自己的固件服务。我创建了一个实体,我可以毫无问题地 update/query 获取信息。当我订阅实体以在值更改时通知我时,我得到以下有效负载:

* Status Code: 200

{
  "subscribeResponse" : {
    "subscriptionId" : "555c979c98add18cc3e1839b",
    "duration" : "P1M",
    "throttling" : "PT5S"
  }
}

休息一下 api 监听我在订阅请求中指定的主机和端口,我收到了该订阅的通知:

 [20/May/2015 10:22:59] "POST / HTTP/1.1" 200 

问题是,当我尝试更新 contextbroker 上的值时,我没有收到有关更改值的通知。

我尝试使用累加器-script.py,我得到了相同的 "error"。

我正在使用我在 bottle 框架中创建的 python 脚本:

import bottle

DEFAULT = {'url': '/'}

@bottle.post(DEFAULT['url'] )
def post_default():
    print str(bottle.request.json)

if __name__ == '__main__':
    bottle.run(host='188.1??.??.??', port=????, debug=True, reloader=True)

(由于安全问题,我隐藏了主机和端口)

编辑:

为了订阅 contextBroker,我正在使用来自 Figway 的脚本 SetSubscription.py,方法是:

python2.7 SetSubscription.py [entity][attribute][server url] 

要更新实体,我正在使用我自己的脚本:

import json
import urllib
import urllib2

BASE_URL = 'http://188.?.?.?:????'
UPDATE_URL = BASE_URL+'/ngsi10/updateContext'

HEADERS = {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'Fiware-Service': 'fiwaretestapi' 
}



UPDATE_EXAMPLE = {
    "contextElements": [
        {
            "type": "",
            "isPattern": "false",
            "id": "bustest3",
            "attributes": [
            {
                "name": "temperature",
                "type": "int",
                "value": "19"
            }
            ]
        }
    ],
    "updateAction": "APPEND"
}


def post(url, data):
    """"""
    req = urllib2.Request(url, data, HEADERS)
    f = urllib2.urlopen(req)
    result = json.loads(f.read())
    f.close()
    return result

if __name__ == "__main__":
    print post(UPDATE_URL, json.dumps(UPDATE_EXAMPLE))

输出:

 [{u'contextElement': {u'attributes': [{u'type': u'int', u'name': u'temperature', u'value': u''}], u'type': u'thing', u'id': u'bustest3', u'isPattern': u'false'}, u'statusCode': {u'code': u'200', u'reasonPhrase': u'OK'}}]}
{u'contextResponses': [{u'contextElement': {u'attributes': [{u'type': u'string', u'name': u'att_name', u'value': u'value', u'metadatas': [{u'type': u'ISO8601', u'name': u'TimeInstant', u'value': u'2015-05-20T14:36:45.752248Z'}]}, {u'type': u'int', u'name': u'temperature', u'value': u'19', u'metadatas': [{u'type': u'ISO8601', u'name': u'TimeInstant', u'value': u'2015-05-20T14:36:45.751958Z'}]}, {u'type': u'ISO8601', u'name': u'TimeInstant', u'value': u'2015-05-20T14:36:45.751958Z'}], u'type': u'thing', u'id': u'bustest3', u'isPattern': u'false'}, u'statusCode': {u'code': u'200', u'reasonPhrase': u'OK'}}]}

我知道 ContextBroker 有更新,但我的问题从一周前开始就一直存在。因此我使用的是 0.20.

编辑:

这正是我使用 SetSubscription.py:

提出的要求
python2.7 SetSubscription.py bustest3 temperature http://188.???.??.???:8082

这是我订阅后获得的有效载荷:

* Asking to http://188.???.??.???:1026/v1/subscribeContext
* Headers: {'Fiware-Service': 'fiwaretestapi', 'content-type': 'application/json', 'accept': 'application/json', 'X-Auth-Token': 'NULL'}
* Sending PAYLOAD:
{
    "reference": "http://188.???.??.???:8082",
    "throttling": "PT5S",
    "entities": [
        {
            "type": "",
            "id": "bustest3",
            "isPattern": "false"
        }
    ],
    "attributes": [
        "temperature"
    ],
    "duration": "P1M",
    "notifyConditions": [
        {
            "condValues": [
                "temperature"
            ],
            "type": "ONCHANGE"
        }
    ]
}

...

* Status Code: 200

{
  "subscribeResponse" : {
    "subscriptionId" : "555ef47298add18cc3e1839d",
    "duration" : "P1M",
    "throttling" : "PT5S"
  }
}

而在另一部分,我正在监听端口,当我进行订阅时,我得到:

"POST / HTTP/1.1" 200 0
{u'originator': u'localhost', u'subscriptionId': u'???????????????????????', u'contextResponses': [{u'contextElement': {u'attributes': [{u'type': u'int', u'name': u'temperature', u'value': u'100', u'metadatas': [{u'type': u'ISO8601', u'name': u'TimeInstant', u'value': u'2015-05-20T14:36:45.751958Z'}]}], u'type': u'thing', u'id': u'bustest3', u'isPattern': u'false'}, u'statusCode': {u'code': u'200', u'reasonPhrase': u'OK'}}]}
188.???.??.??? - - [22/May/2015 05:20:50] "POST / HTTP/1.1" 200 0

比较您用来执行 updateContext 的 Fiware-Service:

HEADERS = {
    ...
    'Fiware-Service: 'my_service' 
}

以及用于创建订阅的那个:

Headers: {'Fiware-Service': 'fiwaretestapi', ...}

两者不同。这可能是导致问题的原因。

我想出来了,我忘记将 'Fiware-ServicePath' : '/' header 添加到 update_context 脚本中它没有通过。它现在正在运行,REST API 正在获取更改后的值。

感谢支持:-)