Python: add EventAgentSample
[smartapi.git] / Examples / Python / EventAgentSample / client.py
1 #!/usr/bin/python
2
3 from SmartAPI.agents.EventAgent import EventAgent
4 from SmartAPI.common.HttpClient import HttpClient
5 from SmartAPI.common.Tools import Tools
6 from SmartAPI.common.SERIALIZATION import SERIALIZATION
7 from SmartAPI.factory.Factory import Factory
8 from SmartAPI.model.Entity import Entity
9
10 def on_results(notification):
11     e = notification.getActivities()[0].getEntities()[0]
12     print "GOT CALLBACK ENTITY", e.getIdentifierUri()
13     # do something with the entity data here
14     
15
16 serverUri = "http://127.0.0.1:3333/smart/v1.0e1.0/access"
17
18 agent = EventAgent(on_results, mqtt_topic = "+/+/youcom/calculations")
19 agent.connect()
20 httpClient = HttpClient()
21 entity = Entity("http://you.com/devices/C1234")
22 request = Factory.createReadRequest("http://me.com", entity)
23 payload, content_type = Tools.serializeRequest(request)
24 response_body, response_headers = httpClient.sendPost(serverUri, payload, content_type = content_type)
25 print "DIRECT RESPONSE:\n", response_body