-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_connection_to_two_aidlabs.py
More file actions
38 lines (27 loc) · 1.44 KB
/
example_connection_to_two_aidlabs.py
File metadata and controls
38 lines (27 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import asyncio
from aidlab import AidlabManager, DataType, Device, DeviceDelegate, DisconnectReason
FIRST_ADDRESS = "<YOUR FIRST DEVICE's ADDRESS>"
SECOND_ADDRESS = "<YOUR SECOND DEVICE's ADDRESS>"
class MainManager(DeviceDelegate):
"""Main class for managing devices."""
async def run(self):
devices = await AidlabManager().scan()
if len(devices) > 0:
first_device = next((device for device in devices if device.address == FIRST_ADDRESS), None)
second_device = next((device for device in devices if device.address == SECOND_ADDRESS), None)
if first_device is not None:
await first_device.connect(self)
if second_device is not None:
await second_device.connect(self)
while True:
await asyncio.sleep(1)
def did_connect(self, device: Device):
print("Connected to: ", device.address)
if device.address == FIRST_ADDRESS or device.address == SECOND_ADDRESS:
asyncio.create_task(device.collect([DataType.RESPIRATION], []))
def did_disconnect(self, device: Device, reason: DisconnectReason):
print("Disconnected from: ", device.address, reason)
def did_receive_respiration(self, device: Device, _: int, value: float):
if device.address == FIRST_ADDRESS or device.address == SECOND_ADDRESS:
print("Respiration: ", value, device.address)
asyncio.run(MainManager().run())