Python SDK for communicating with the Sniff Controller Air of Sniff Logic
Install the module using pip
pip install git+https://github.com/snifflogic/python-airto run the example, run
python -m snifflogic_air.exampleTo use in your own project,
from snifflogic_air import *And then you can use Air and DataPoint as shown in example.py
The example is in example.py. The script scans for ble devices and presents a list of Airs.
Choose the device number you wish to connect to. The script will then retrieve the battery level and sample rate, modify the sample rate, acquire 5 seconds of data, and print it. It will also change the name (visible only after disconnecting and rescanning).
air.py- represents the Air device.datapoint.py- represents a single data point acquired by the Air, including both the breathing and accelerometer data.example.py- a script demonstrating how to use the Air and DataPoint classes
Air(address: str) -> None
Class for communicating with the Sniff Controller Air
Create a new Air with the given address
Args:
address (str): the Bluetooth address of the air,
as a hex string separated by colons, e.g. 72:29:35:7E:8E:70:
Changes the name of the Air so that subsequent BLE scans will see it with a different human-readable name.
The address is not affected by this change. In order to see the changem it is necessary to disconnect and scan again.
IMPORTANT! In order to preserve compatibility with our software, the name MUST start with 'Air'.
Also, The total length of the name must be no more than 8 characters.
Args: newName (str): New name of Air
Raises:
Exception: if name doesn't start with Air or is too long.
attempt to connect to the air. may raise an exception of cannot connect.
Disconnects from the air
Reads the battery level of this Air in percent.
Returns:
int: battery level in percent.
Reads the sampling rate (frequency) of this Air in Hz
Returns:
int: sampling rate in Hz
Prints out all the services and characteristics of the Air
Sets the sampling rate of this Air.
IMPORTANT! currently the Air supports 6 or 15 Hz only.
Args:
newFreq (int): new Fequency, must be 6 or 15
Raises: Exception: if newInt is not 6 or 15
async subscribe(self, notification_handler: Callable[[bleak.backends.characteristic.BleakGATTCharacteristic, bytearray], Optional[Awaitable[NoneType]]])
Subscribes to data (breathing and accelerometer)
Args: notification_handler ([BleakGATTCharacteristic, bytearray], (Awaitable[None] None)]): Function that handles incoming data when it is received. Use the DataPoint class to parse the incoming data.
unsubscribe to data
DataPoint(raw_data: bytearray) -> None
class representing a point of data acquired by the air. This includes both raw and scaled data as well as unscaled accelerometer values.
Create a new point from raw data received by the Sniff Controller Air
Args: raw_data (bytearray): byte array received from the air via BLE
String representation of a point. Does not print the raw data only the scaled.
Returns: str: String representation
If you've encountered a bug, please open an issue. Include details about your device, operating system, Python version, and Bluetooth version on your computer. Don't forget to attach your code.
Have you implemented something useful that could benefit others? Don't hesitate to submit a pull request.
