In [2]:
import json,requests
url = "http://localhost:8080/controllers/eventsManager.php"
payload = {"user": "admin","inputEvent":"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. @prefix string: <http://www.w3.org/2000/10/swap/string#>. @prefix ewe: <http://gsi.dit.upm.es/ontologies/ewe/ns/#>. @prefix ewe-time: <http://gsi.dit.upm.es/ontologies/ewe-time/ns/#>. ewe-time:Clock rdf:type ewe-time:IsTime. ewe-time:Clock ewe:hour '12:30'."}
data_channels = requests.post(url, data=payload).json()
print(data_channels)


---------------------------------------------------------------------------
ConnectionRefusedError                    Traceback (most recent call last)
/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/connection.py in _new_conn(self)
    140             conn = connection.create_connection(
--> 141                 (self.host, self.port), self.timeout, **extra_kw)
    142 

/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options)
     82     if err is not None:
---> 83         raise err
     84 

/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options)
     72                 sock.bind(source_address)
---> 73             sock.connect(sa)
     74             return sock

ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

NewConnectionError                        Traceback (most recent call last)
/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    599                                                   body=body, headers=headers,
--> 600                                                   chunked=chunked)
    601 

/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    355         else:
--> 356             conn.request(method, url, **httplib_request_kw)
    357 

/usr/lib/python3.5/http/client.py in request(self, method, url, body, headers)
   1105         """Send a complete request to the server."""
-> 1106         self._send_request(method, url, body, headers)
   1107 

/usr/lib/python3.5/http/client.py in _send_request(self, method, url, body, headers)
   1150             body = _encode(body, 'body')
-> 1151         self.endheaders(body)
   1152 

/usr/lib/python3.5/http/client.py in endheaders(self, message_body)
   1101             raise CannotSendHeader()
-> 1102         self._send_output(message_body)
   1103 

/usr/lib/python3.5/http/client.py in _send_output(self, message_body)
    933 
--> 934         self.send(msg)
    935         if message_body is not None:

/usr/lib/python3.5/http/client.py in send(self, data)
    876             if self.auto_open:
--> 877                 self.connect()
    878             else:

/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/connection.py in connect(self)
    165     def connect(self):
--> 166         conn = self._new_conn()
    167         self._prepare_conn(conn)

/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/connection.py in _new_conn(self)
    149             raise NewConnectionError(
--> 150                 self, "Failed to establish a new connection: %s" % e)
    151 

NewConnectionError: <requests.packages.urllib3.connection.HTTPConnection object at 0x7fc0191d36d8>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

MaxRetryError                             Traceback (most recent call last)
/usr/local/lib/python3.5/dist-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    422                     retries=self.max_retries,
--> 423                     timeout=timeout
    424                 )

/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    648             retries = retries.increment(method, url, error=e, _pool=self,
--> 649                                         _stacktrace=sys.exc_info()[2])
    650             retries.sleep()

/usr/local/lib/python3.5/dist-packages/requests/packages/urllib3/util/retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
    375         if new_retry.is_exhausted():
--> 376             raise MaxRetryError(_pool, url, error or ResponseError(cause))
    377 

MaxRetryError: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /controllers/eventsManager.php (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7fc0191d36d8>: Failed to establish a new connection: [Errno 111] Connection refused',))

During handling of the above exception, another exception occurred:

ConnectionError                           Traceback (most recent call last)
<ipython-input-2-4e1130e32f22> in <module>()
      2 url = "http://localhost:8080/controllers/eventsManager.php"
      3 payload = {"user": "admin","inputEvent":"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. @prefix string: <http://www.w3.org/2000/10/swap/string#>. @prefix ewe: <http://gsi.dit.upm.es/ontologies/ewe/ns/#>. @prefix ewe-time: <http://gsi.dit.upm.es/ontologies/ewe-time/ns/#>. ewe-time:Clock rdf:type ewe-time:IsTime. ewe-time:Clock ewe:hour '12:30'."}
----> 4 data_channels = requests.post(url, data=payload).json()
      5 print(data_channels)

/usr/local/lib/python3.5/dist-packages/requests/api.py in post(url, data, json, **kwargs)
    108     """
    109 
--> 110     return request('post', url, data=data, json=json, **kwargs)
    111 
    112 

/usr/local/lib/python3.5/dist-packages/requests/api.py in request(method, url, **kwargs)
     54     # cases, and look like a memory leak in others.
     55     with sessions.Session() as session:
---> 56         return session.request(method=method, url=url, **kwargs)
     57 
     58 

/usr/local/lib/python3.5/dist-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    486         }
    487         send_kwargs.update(settings)
--> 488         resp = self.send(prep, **send_kwargs)
    489 
    490         return resp

/usr/local/lib/python3.5/dist-packages/requests/sessions.py in send(self, request, **kwargs)
    607 
    608         # Send the request
--> 609         r = adapter.send(request, **kwargs)
    610 
    611         # Total elapsed time of the request (approximately)

/usr/local/lib/python3.5/dist-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    485                 raise ProxyError(e, request=request)
    486 
--> 487             raise ConnectionError(e, request=request)
    488 
    489         except ClosedPoolError as e:

ConnectionError: HTTPConnectionPool(host='localhost', port=8080): Max retries exceeded with url: /controllers/eventsManager.php (Caused by NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection object at 0x7fc0191d36d8>: Failed to establish a new connection: [Errno 111] Connection refused',))

In [3]:
url = "http://test.ewetasker.cluster.gsi.dit.upm.es/mobileConnectionHelper.php"
payload={}
payload["command"]="createRuleParams"
payload["rule_title"]="Light presence"
payload["rule_channel_one"]="presence"
payload["rule_channel_two"]="hueLight"
payload["rule_event_title"]="Presence Detected At Distance Greater Than"
payload["event_param_1"]="1234"
payload["event_param_2"]=5
payload["rule_action_title"]="Turn on"
payload["rule_description"]="Prueba"
payload["rule_creator"]="admin"
payload["rule_place"]="GSI Lab"
print(payload)
data_channels = requests.post(url, data=payload)
print(data_channels)


{'rule_action_title': 'Turn on', 'rule_creator': 'admin', 'command': 'createRuleParams', 'rule_channel_one': 'presence', 'rule_event_title': 'Presence Detected At Distance Greater Than', 'event_param_2': 5, 'event_param_1': '1234', 'rule_channel_two': 'hueLight', 'rule_description': 'Prueba', 'rule_title': 'Light presence', 'rule_place': 'GSI Lab'}
<Response [200]>

In [32]:
import json,requests
url = "http://localhost:8080/controllers/eventsManager.php"
payload = {"user": "admin","inputEvent":"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. @prefix string: <http://www.w3.org/2000/10/swap/string#>. @prefix ewe: <http://gsi.dit.upm.es/ontologies/ewe/ns/#>. @prefix ewe-date: <http://gsi.dit.upm.es/ontologies/ewe-date/ns/#>. ewe-date:Date rdf:type ewe-date:IsDate. ewe-date:Date ewe:day '05/30/17 17:14'."}
data_channels = requests.post(url, data=payload).json()
print(data_channels)


{'actions': [{'channel': 'DoorLock', 'action': 'OpenDoor', 'parameter': ''}], 'success': 1}

In [3]:
url = "http://localhost:8080/mobileConnectionHelper.php"
payload={}
payload["command"]="createRuleParams"
payload["rule_title"]="Reminder 1"
payload["rule_channel_one"]="clock"
payload["rule_channel_two"]="apiai"
payload["rule_event_title"]="Is time"
payload["event_param_1"]="12:30"
payload["rule_action_title"]="Send event"
payload["action_param_1"]="texto regla"
payload["rule_description"]="descipcion"
payload["rule_creator"]="admin"
payload["rule_place"]="GSI Lab"
print(payload)
data_channels = requests.post(url, data=payload)
print(data_channels)


{'command': 'createRuleParams', 'rule_description': 'descipcion', 'rule_action_title': 'Send event', 'rule_place': 'GSI Lab', 'event_param_1': '12:30', 'rule_channel_one': 'clock', 'action_param_1': 'texto regla', 'rule_event_title': 'Is time', 'rule_creator': 'admin', 'rule_channel_two': 'apiai', 'rule_title': 'Reminder 1'}
<Response [200]>

In [83]:
import json,requests
url = "http://localhost:8080/controllers/eventsManager.php"
payload = {"user": "admin","inputEvent":"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. @prefix string: <http://www.w3.org/2000/10/swap/string#>. @prefix math: <http://www.w3.org/2000/10/swap/math#>. @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. @prefix ewe: <http://gsi.dit.upm.es/ontologies/ewe/ns/#>. @prefix ewe-time: <http://gsi.dit.upm.es/ontologies/ewe-time/ns/#>. ewe-time:TimeHasCome rdf:type ewe-time:TimeHasCome. ewe-time:TimeHasCome ewe-time:Hour '12:30'."}
data_channels = requests.post(url, data=payload).json()
print(data_channels)


{'success': 1, 'actions': []}

In [98]:
url = "http://localhost:8080/mobileConnectionHelper.php"
payload={}
payload["command"]="createRule"
payload["rule_title"]="prueba clock"
payload["rule_channel_one"]="clock"
payload["rule_channel_two"]="telegram"
payload["rule_event_title"]="Time has come"
payload["rule_action_title"]="Send message"
payload["rule_description"]="prueba clock 2"
payload["rule_creator"]="admin"
payload["rule_place"]="Home"
infile = open('rule.txt', 'r')
payload["rule"]=infile.read()
infile.close()
print(payload)
data_channels = requests.post(url, data=payload)
print(data_channels)


{'rule_event_title': 'Time has come', 'rule_place': 'Home', 'rule_creator': 'admin', 'rule_title': 'prueba clock', 'command': 'createRule', 'rule_action_title': 'Send message', 'rule_description': 'prueba clock 2', 'rule': '@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.\n@prefix string: <http://www.w3.org/2000/10/swap/string#>.\n@prefix math: <http://www.w3.org/2000/10/swap/math#>.\n@prefix ewe: <http://gsi.dit.upm.es/ontologies/ewe/ns/#>.\n@prefix ewe-presence: <http://gsi.dit.upm.es/ontologies/ewe-connected-home-presence/ns/#>.\n@prefix ewe-telegram: <http://gsi.dit.upm.es/ontologies/ewe-telegram/ns/#>.\n@prefix ov: <http://vocab.org/open/#>.\n\n{\n\t?event rdf:type ewe-time:TimeHasCome.\n        ?event ewe-time:Hour ?hour.\n        ?hour string:equalIgnoringCase "15:00".\n\n}\n=>\n{\n\tewe-telegram:Telegram2 rdf:type ewe-telegram:SendMessage;\n\tov:message "Prueba Telegram".\n}.\n\n', 'rule_channel_two': 'telegram', 'rule_channel_one': 'Clock'}
<Response [200]>

In [2]:
import time
t=time.strftime("%X")
t=t[:5]
d=time.strftime("%x")+" "+t
print(d)
print(t)


05/31/17 18:43
18:43

In [22]:
t="18:42"
t="05/31/17 18:53"
url = "http://test.ewetasker.cluster.gsi.dit.upm.es//controllers/eventsManager.php"
event="@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. @prefix string: <http://www.w3.org/2000/10/swap/string#>. @prefix ewe: <http://gsi.dit.upm.es/ontologies/ewe/ns/#>. @prefix ewe-date: <http://gsi.dit.upm.es/ontologies/ewe-date/ns/#>. ewe-date:Moment rdf:type ewe-date:DateHasCome. ewe-date:Moment ewe-date:Day '"+t+"'."
payload = {"user": "admin","inputEvent":event}
data= requests.post(url, data=payload).json()
print(data)


{'actions': [{'parameter': '', 'channel': 'HueLight', 'action': 'TurnOff'}], 'success': 1}

In [2]:
url = "http://test.ewetasker.cluster.gsi.dit.upm.es/mobileConnectionHelper.php"
payload={}

payload["command"]="createRuleParams"
payload["rule_title"]="Reminder "
payload["rule_channel_one"]="date"
payload["rule_channel_two"]="apiai"
payload["rule_event_title"]="Date has come"
payload["event_param_1"]="05/31/17 18:43"
payload["rule_action_title"]="Send event"
payload["action_param_1"]="05/31/17 18:43"
payload["rule_description"]="05/31/17 18:43"
payload["rule_creator"]="admin"
payload["rule_place"]="GSI Lab"
print(requests.post(url, data=payload))


<Response [200]>

In [ ]: