From 50c32fea276e683eb9f7ff516de11f2c06a013f7 Mon Sep 17 00:00:00 2001 From: Daniel Pollithy Date: Wed, 30 Aug 2017 17:49:54 +0200 Subject: [PATCH] d3.js --- client.py | 6 +++++- drone.py | 15 ++++++++++++--- drone_poller.py | 19 +++++++++++++++++++ http/drone.py | 11 ----------- settings.py | 2 +- 5 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 drone_poller.py delete mode 100644 http/drone.py diff --git a/client.py b/client.py index 4e9753e..d0d709c 100644 --- a/client.py +++ b/client.py @@ -102,7 +102,7 @@ def protocol(address): sock.close() -if __name__ == '__main__': +def run(): connecting = True while connecting: nearby_devices = bluetooth.discover_devices(lookup_names=True) @@ -125,3 +125,7 @@ if __name__ == '__main__': connecting = False time.sleep(settings.BT_SLEEP) + + +if __name__ == '__main__': + run() \ No newline at end of file diff --git a/drone.py b/drone.py index 809b217..0305631 100644 --- a/drone.py +++ b/drone.py @@ -1,4 +1,13 @@ -# run two threads -# 1) the bluetooth connector -# 2) the website listener +from multiprocessing import Process +import client +import drone_poller + +def run(): + p = Process(target=drone_poller.run) + p.start() + client.run() + + +if __name__ == '__main__': + run() diff --git a/drone_poller.py b/drone_poller.py new file mode 100644 index 0000000..2174161 --- /dev/null +++ b/drone_poller.py @@ -0,0 +1,19 @@ +import urllib +import json +import time + +import settings + +url = 'http://google.de' + + +def run(): + while True: + response = urllib.urlopen(url) + data = json.loads(response.read()) + print(data) + time.sleep(settings.WEBSITE_POLLING_SLEEP) + + +if __name__ == '__main__': + run() \ No newline at end of file diff --git a/http/drone.py b/http/drone.py deleted file mode 100644 index eba7797..0000000 --- a/http/drone.py +++ /dev/null @@ -1,11 +0,0 @@ -# this file checks in a given interval a http endpoint for booking the drone should make - -import urllib -import json -import settings - -while True: - url = 'http://localhost:8080/drone/{}/bookings'.format(settings.CLIENT_ETHEREUM_ADDRESS) - response = urllib.urlopen(url) - data = json.loads(response.read()) - print data \ No newline at end of file diff --git a/settings.py b/settings.py index 72f8216..321f426 100644 --- a/settings.py +++ b/settings.py @@ -8,7 +8,7 @@ RASPY_BT_ADDRESS = 'B8:27:EB:76:09:0B' DEMO = False -WEBSITE_POLLING_SLEEP = 1 # seconds +WEBSITE_POLLING_SLEEP = 5 # seconds BT_SLEEP = 0.01 # seconds DISTANCE_SLEEP = 0.1