1
votes

I got my own instance of Orion Context Broker and I'm using IDAS with my own fiware service. I created an entity and i can update/query info without any problem. When I subscribe to the entity to notify me when a value has changed, i get the following payload:

* Status Code: 200

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

and having a rest api listening to the host and port that i indicated upon the subscription request, i get notified of that subscription:

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

The problem is that when i try to update the value on the contextbroker, i don't get notified of that changed value.

I tryed with the accumulator-script.py and i get the same "error".

I'm using a python script created by me in a bottle framework:

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)

(I've hiden the host and port due to security issues)

EDIT:

To subscribe t the contextBroker i'm using the script SetSubscription.py from Figway by doing:

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

To update the entity i'm using my own script:

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))

It's output:

 [{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'}}]}

I undersand that there's been an update in the ContextBroker but my problem has being going on since a week ago. Therefore i am using the 0.20.

EDIT:

This is the exact request i make using the SetSubscription.py:

python2.7 SetSubscription.py bustest3 temperature http://188.???.??.???:8082

This is the payload i get once i make the subscription:

* 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"
  }
}

And in the other part i'm listening on the port and when i make the subscription i get:

"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
2
Could you edit your answer to so the exact request you are using to create the subscription and do updates (including HTTP headers), please? In addition, which Context Broker version are you using? Thanks!fgalan
Answer was edited :)Diogo Nunes
It would be great to know which exact request is SetSubscription.py putting in the wire... Could you add to your question the output you get from that command, including the "Asking to", "Headers" and "Sending PAYLOAD" fields, please? Thanks!fgalan
The answer was edited again to include what you ask! :-)Diogo Nunes

2 Answers

1
votes

I figured it out, i was forgeting to add the 'Fiware-ServicePath' : '/' header to the update_context script and for that it wasn't passing through. It's working now and the REST API is getting the changed value.

Thanks for the support :-)

0
votes

Comparing the Fiware-Service you use to do updateContext:

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

and the one it is used to create the subscription:

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

both are different. That could be the causing the problem.