aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdi Feschiyan <edi.feschiyan@konsulko.com>2020-03-09 17:57:09 +0200
committerEdi Feschiyan <edi.feschiyan@konsulko.com>2020-03-09 17:57:09 +0200
commitba673345466a365adb107a32dc4143390d4032eb (patch)
tree783e6e32b4e1e946199445664d9ac50f04d57320
parent5ef7f0b592e609775352ad41c3fd656b10f86d24 (diff)
Began work for bluetooth binding
-rw-r--r--aglbaseservice.py10
-rw-r--r--bluetooth.py65
-rw-r--r--geoclue.py8
-rw-r--r--gps.py5
-rw-r--r--weather.py1
5 files changed, 75 insertions, 14 deletions
diff --git a/aglbaseservice.py b/aglbaseservice.py
index 3c5f907..f97402b 100644
--- a/aglbaseservice.py
+++ b/aglbaseservice.py
@@ -10,11 +10,11 @@ from os import environ
from argparse import ArgumentParser
-IPADDR = '127.0.0.1'
-PORT = '30000'
-TOKEN = 'HELLO'
-UUID = 'magic'
-URL = f'ws://{IPADDR}:{PORT}/api?token={TOKEN}&uuid={UUID}'
+# IPADDR = '127.0.0.1'
+# PORT = '30000'
+# TOKEN = 'HELLO'
+# UUID = 'magic'
+# URL = f'ws://{IPADDR}:{PORT}/api?token={TOKEN}&uuid={UUID}'
class AFBT(IntEnum):
REQUEST = 2,
diff --git a/bluetooth.py b/bluetooth.py
new file mode 100644
index 0000000..13ab0c9
--- /dev/null
+++ b/bluetooth.py
@@ -0,0 +1,65 @@
+import asyncio
+from random import randint
+from aglbaseservice import AGLBaseService
+
+Verbs = ['subscribe', 'unsubscribe', 'managed_objects', 'adapter_state', 'default_adapter', 'avrcp_controls',
+ 'connect', 'disconnect', 'pair', 'cancel_pairing', 'confirm_pairing', 'remove_device']
+
+BTEventType = ['adapter_changes', 'device_changes', 'media', 'agent']
+
+class BluetoothService(AGLBaseService):
+
+ def __init__(self, ip, port):
+ super().__init__(api='Bluetooth-Manager', ip=ip, port=port)
+
+ async def subscribe(self, event='location'):
+ super().subscribe(event=event)
+
+ async def unsubscribe(self, event='location'):
+ super().unsubscribe(event=event)
+
+ async def managed_objects(self):
+ verb = 'managed_objects'
+ msgid = randint(0, 999999)
+ msg = f'[2,"{msgid}","{self.api}/{verb}",""]'
+ print(msg)
+ await self.send(msg)
+ return await self.receive()
+
+ async def adapter_state(self, param = None, value = None):
+ verb = 'adapter_state'
+ msgid = randint(0, 999999)
+ if param:
+ p = str({'adapter': param})
+ # msg = f'[2,"{msgid}","{self.api}/{verb}","{param}": {value if value is not None else ""}]'
+ msg = f'[2,"{msgid}","{self.api}/{verb}", {p}]'
+ else:
+ msg = f'[2,"{msgid}","{self.api}/{verb}", ""]'
+
+ print(msg)
+ await self.send(msg)
+ return await self.receive()
+
+ async def default_adapter(self):
+ verb = 'default_adapter'
+ msgid = randint(0, 999999)
+ msg = f'[2,"{msgid}","{self.api}/{verb}",""]'
+ print(msg)
+ await self.send(msg)
+ return await self.receive()
+
+ async def avrcp_controls(self):
+ pass
+
+
+async def main(loop):
+ BTS = await BluetoothService(ip='192.168.234.202', port='30005')
+ #print(await BTS.managed_objects())
+ print(await BTS.adapter_state('hci0', '{"discoverable": true}'))
+ await asyncio.sleep(delay=1)
+ print(await BTS.adapter_state('hci0'))
+ print(await BTS.adapter_state('hci1', '""'))
+
+if __name__ == '__main__':
+ loop = asyncio.get_event_loop()
+ loop.run_until_complete(main(loop)) \ No newline at end of file
diff --git a/geoclue.py b/geoclue.py
index d296397..f31d91e 100644
--- a/geoclue.py
+++ b/geoclue.py
@@ -1,11 +1,11 @@
import asyncio
from random import randint
-from aglbaseservice import AGLBaseService, AFBT
+from aglbaseservice import AGLBaseService
class GeoClueService(AGLBaseService):
- def __init__(self):
- super().__init__(api='geoclue', ip='192.168.234.202', port='30009')
+ def __init__(self, ip, port, api='geoclue'):
+ super().__init__(ip=ip, port=port, api=api)
async def location(self):
verb = 'location'
@@ -22,7 +22,7 @@ class GeoClueService(AGLBaseService):
async def main(loop):
- GCS = await GeoClueService()
+ GCS = await GeoClueService(ip='192.168.234.202', port='30009')
print(await GCS.location())
listener = loop.create_task(GCS.listener())
await listener
diff --git a/gps.py b/gps.py
index 48ace14..ff6aeae 100644
--- a/gps.py
+++ b/gps.py
@@ -50,12 +50,9 @@ class GPSService:
async def main():
gpss = await GPSService()
try:
- await gpss.subscribe()
- data = await gpss.receive()
- data = await gpss.receive()
- data = await gpss.receive()
data = await gpss.receive()
print(data)
+ await gpss.subscribe()
except ConnectionClosedError as e:
print(e)
diff --git a/weather.py b/weather.py
index 1201909..3cdca79 100644
--- a/weather.py
+++ b/weather.py
@@ -38,7 +38,6 @@ class WeatherService:
return await self.receive()
-
async def main():
MPS = await WeatherService()
try: