Aidlab SDK for Python allows you to read data from many Aidlabs at once. This SDK supports Windows, macOS, and Linux operating systems and has been tested using Python 3.
Aidlab SDK does not support Anaconda.
Note that laptop or PC with Bluetooth 4.0+ module is required.
Working with Aidlab using Python allows you to juggle with data almost immediately. This example shows how to receive data from nearby discovered Aidlabs:
import Aidlab class MainManager(Aidlab.Aidlab): def did_connect(self, aidlab): print("Connected to: ", aidlab.address) def did_disconnect(self, aidlab): print("Disconnected from: ", aidlab.address) def did_receive_respiration(self, aidlab, timestamp, values): print(value) if __name__ == '__main__': signals = ["respiration"] main_manager = MainManager() main_manager.connect(signals) while True: pass
Save it as
example.py, turn the Aidlab on and run:
Note: run with the
sudoon Unix-based systems.
Aidlab class exposes the
connect function which allows you to scan nearby Aidlabs and listen to data distribution events:
connect(signals: [str], addresses: [str])
connect function expects two parameters:
signals- an array of signals you would like to listen to. List of the available signals.
addresses- an optional parameter which you can use if you know the address(es) of the Aidlab(s) you'd like to connect to.
Python SDK allows you to connect to several Aidlabs at the same time, however, simultaneous subscription to
respiration signals due to the high sampling rate may cause delay or loss of samples on older Bluetooth LE chips.
Since both the Bluetooth detection and name lookup process are probabilistic,
connect will sometimes fail to detect devices that are in range. In these cases, it may be a good idea to try again once or twice before giving up.
Since we are inheriting from
Aidlab, we can now listen to events.
For each event, an
IAidlab object is a parameter. You can obtain the following information from it:
firmware_revision- the firmware version currently installed on your Aidlab
serial_number- Aidlab's serial number
hardware_revision- Aidlab's hardware version
address- Aidlab's MAC address
You can also use several functions:
# modify the ECG filtration method (you can choose between normal and aggressive) def set_ecg_filtration_method(self, method): pass # start data synchronization def start_synchronization(self): pass # stop data synchronization def stop_synchronization(self): pass # send commands to Aidlab (e.g. to change LED brightness) def send(self, command): pass
Commands can not be sent to Aidlab while synchronization is enabled. If you're utilizing synchronization in your app, remember to always use the
stop_synchronizationfunction before using
Aidlab SDK represents Aidlab's Bluetooth address as a string of the form
xx:xx:xx:xx:xx, where each
x is a hexadecimal character representing one octet of the 48-bit address, with most significant octets listed first. Bluetooth devices on Linux and Windows will always be identified using an address string of this form. For example:
On Mac, the Aidlab's Bluetooth address is represented as a UUID, in such form:
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, as 32 hexadecimal (base-16) digits, displayed in 5 groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters (32 alphanumeric characters and 4 hyphens). For example:
If you don't know the Aidlab's Bluetooth address, see "Finding the Bluetooth address" under the FAQ section below.
Connecting to two (or more) Aidlabs
This section will show how to stream
battery from two Aidlabs simultaneously:
1. Turn the Aidlabs on.
2. Run the connectivity routine:
import Aidlab first_address = "<YOUR FIRST AIDLAB's ADDRESS>" second_address = "<YOUR SECOND AIDLAB's ADDRESS>" class MainManager(Aidlab.Aidlab): def is_connected(self, aidlab): print("Connected to: ", aidlab.address) def is_disconnected(self, aidlab): print("Disconnected from: ", aidlab.address) def did_receive_respiration(self, aidlab, timestamp, values): if aidlab_address == first_address: print("Respiration: ", values, aidlab.address) elif aidlab_address == second_address: print("Respiration: ", values, aidlab.address) def did_receive_battery_level(self, aidlab, stateOfCharge): if aidlab_address == first_address: print("Battery: ", stateOfCharge, aidlab.address) elif aidlab_address == second_address: print("Battery: ", stateOfCharge, aidlab.address) if __name__ == '__main__': signals = ["battery", "respiration"] main_manager = MainManager() main_manager.connect(signals) while True: pass
3. Wait till connection will be established.
Finding the Bluetooth address
In order to connect to Aidlabs of your choice, the Bluetooth address must be known.
Obtaining Aidlab's MAC Bluetooth address (Linux)
You scan Aidlab address with a BLE scanner. For instance, on Linux you can use
$ sudo hcitool lescan LE Scan ... b9:b2:76:d7:ac:16 (aidlab)
Alternatively, you can get a list of all available Bluetooth devices and their MAC addresses using the command
hciconfig, like so:
$ hciconfig hci0: Type: BR/EDR Bus: USB BD Address: b9:b2:76:d7:ac:16 ACL MTU: 1017:8 SC0 MTU: 64:8 ...
To test the connectivity, you can use the
gatttool -b b9:b2:76:d7:ac:16 -I connect char-write-cmd 12 0100
You can take control over synchronization of the data from your Aidlab's internal memory to your app using
IAidlab functions mentioned above and special synchronization-related events. A simple example illustrating data synchronization is available in the
example_synchronization.py file. The full list of events can be found under Synchronization events here.
Aidlab sends past data and currently recorded data to your app simultaneously.
To be able to synchronize data, you have to enable it first. For more information, go to Enabling data synchronization on the Getting Started page.
If you want to get information about the current state of the SDK, add the following lines to your code:
import logging logging.basicConfig(level=logging.INFO)