blue_st_sdk package¶
Subpackages¶
- blue_st_sdk.advertising_data package
- blue_st_sdk.features package
- Subpackages
- Submodules
- blue_st_sdk.features.device_timestamp_feature module
- blue_st_sdk.features.feature_accelerometer module
- blue_st_sdk.features.feature_activity_recognition module
- blue_st_sdk.features.feature_audio_scene_classification module
- blue_st_sdk.features.feature_gyroscope module
- blue_st_sdk.features.feature_humidity module
- blue_st_sdk.features.feature_magnetometer module
- blue_st_sdk.features.feature_pressure module
- blue_st_sdk.features.feature_proximity module
- blue_st_sdk.features.feature_proximity_gesture module
- blue_st_sdk.features.feature_stepper_motor module
- blue_st_sdk.features.feature_switch module
- blue_st_sdk.features.feature_temperature module
- blue_st_sdk.features.field module
- Module contents
- blue_st_sdk.firmware_upgrade package
- blue_st_sdk.utils package
- Submodules
- blue_st_sdk.utils.ble_node_definitions module
- blue_st_sdk.utils.blue_st_exceptions module
- blue_st_sdk.utils.dict_put_single_element module
- blue_st_sdk.utils.number_conversion module
- blue_st_sdk.utils.python_utils module
- blue_st_sdk.utils.unwrap_timestamp module
- blue_st_sdk.utils.uuid_to_feature_map module
- Module contents
Submodules¶
blue_st_sdk.debug_console module¶
debug
The debug module is responsible for managing the debugging capabilities offered by the BlueSTSDK.
-
class
blue_st_sdk.debug_console.
DebugConsole
(node, stdinout_characteristic, stderr_characteristic)[source]¶ Class used to read/write debug messages.
-
__init__
(node, stdinout_characteristic, stderr_characteristic)[source]¶ Constructor.
- Args:
- node (
blue_st_sdk.node.Node
): Node that will send the data. stdinout_characteristic (Characteristic): The BLE characteristic used to read/write data from/to stdin/stdout. Refer to Characteristic for more information. stderr_characteristic (Characteristic): The BLE characteristic used to read data from stderr. Refer to Characteristic for more information.
-
add_listener
(listener)[source]¶ Adding a listener.
- Args:
- listener (
blue_st_sdk.debug.DebugListener
): Listener to be added.
-
get_node
()[source]¶ Getting the node that listen to / write to this debug console.
- Returns:
- node (
blue_st_sdk.node.Node
): the node that listen/write to this debug console.
-
on_update_characteristic
(characteristic, data)[source]¶ The characteristic has been updated.
If it is a debug characteristic, data are sent to the registered listeners.
- Args:
- characteristic (Characteristic): The BLE characteristic that has been updated. Refer to Characteristic for more information. data (str): The data notified from the given characteristic.
-
on_write_characteristic
(characteristic, data, status)[source]¶ The characteristic has been written.
- Args:
- characteristic (Characteristic): The BLE characteristic that has been written. data (bytearray): Received data. status (bool): True if the writing operation was successfully, False otherwise.
-
-
class
blue_st_sdk.debug_console.
DebugConsoleListener
[source]¶ Bases:
object
Interface used by the
blue_st_sdk.debug.DebugConsole
class to notify changes on a debug console. Data received/sent from/to a node are encoded with ISO-8859-1 charset.-
on_stderr_receive
(debug_console, message)[source]¶ Called whenever a new message is received on the standard error.
- Args:
- debug_console (object): Console that sends the message. message (str): The message received on the stderr console.
- Raises:
NotImplementedError
if the method has not been implemented.
-
on_stdin_send
(debug_console, message, status)[source]¶ Called whenever a new message is sent to the standard input.
- Args:
- debug_console (object): Console that receives the message. message (str): The message sent to the stdin console. status (bool): True if the message is sent correctly, False otherwise.
- Raises:
NotImplementedError
if the method has not been implemented.
-
on_stdout_receive
(debug_console, message)[source]¶ Called whenever a new message is received on the standard output.
- Args:
- debug_console (object): Console that sends the message. message (str): The message received on the stdout console.
- Raises:
NotImplementedError
if the method has not been implemented.
-
blue_st_sdk.feature module¶
feature
The feature module represents a feature exported by a Bluetooth Low Energy (BLE) device.
-
class
blue_st_sdk.feature.
ExtractedData
(sample, read_bytes)[source]¶ Bases:
object
Class used to return the data and the number of bytes read after extracting data with the
blue_st_sdk.feature.Feature.extract_data()
method.-
__init__
(sample, read_bytes)[source]¶ Constructor.
- Args:
- sample (
blue_st_sdk.feature.Sample
): A sample object. read_bytes (int): The number of bytes read after extracting data.
-
get_sample
()[source]¶ Get the data extracted from the byte stream.
- Returns:
blue_st_sdk.feature.Sample
: The data extracted from the byte stream.
-
-
class
blue_st_sdk.feature.
Feature
(name, node, description)[source]¶ Bases:
object
This class contains description and data exported by a node.
Adding a new sensor in a node implies extending this class and implementing the
blue_st_sdk.feature.Feature.extract_data()
method to extract the information from the raw data coming from the node.This class manages notifications and listeners’ subscriptions.
-
__init__
(name, node, description)[source]¶ Constructor.
- Args:
- name (str): Name of the feature.
node (
blue_st_sdk.node.Node
): Node that will update the feature. description (list): Description of the data of the feature (list ofblue_st_sdk.features.field.Field
objects).
-
add_listener
(listener)[source]¶ Add a listener.
- Args:
- listener (
blue_st_sdk.feature.FeatureListener
): Listener to be added.
-
add_logger
(logger)[source]¶ Add a logger.
- Args:
- logger (
blue_st_sdk.feature.FeatureLogger
): Logger to be added.
-
extract_data
(timestamp, data, offset)[source]¶ Extract the data from the feature’s raw data.
You have to parse the data inside the “data” field and skip the first “offset” byte.
This method has to extract the data, create a
blue_st_sdk.feature.Sample
object, and return anblue_st_sdk.feature.ExtractedData
object containing it.The method that calls this one has to manage the lock acquisition/release and to notify the user about the new sample.
- Args:
- timestamp (int): Data’s timestamp. data (str): The data read from the feature. offset (int): Offset where to start reading data.
- Returns:
blue_st_sdk.feature.ExtractedData
: An object containing the number of bytes read and the extracted data.- Raises:
NotImplementedError
if the method has not been implemented.blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidDataException
if the data array has not enough data to read.
-
get_characteristic
()[source]¶ Get the characteristic that offers the feature.
- Note:
- By design, it is the characteristic that offers more features beyond the current one, among those offering the current one.
- Returns:
- characteristic: The characteristic that offers the feature. Refer to Characteristic for more information.
-
get_fields_description
()[source]¶ “Get the description of the data fields of the feature.
- Returns:
- list: The description of the data fields of the feature (list of
blue_st_sdk.features.field.Field
objects).
-
get_last_update
()[source]¶ Get the time of the last update.
- Returns:
- datetime: The time of the last update received. Refer to datetime for more information.
-
get_parent_node
()[source]¶ Get the node that updates the feature.
- Return:
blue_st_sdk.node.Node
: The node that updates the feature.
-
classmethod
has_valid_index
(sample, index)[source]¶ Check whether the sample has valid data at the index position.
- Args:
- sample (
blue_st_sdk.feature.Sample
): Sample data. index (int): Position to be tested. - Returns:
- bool: True if the sample is not null and has a non null value at the index position, False otherwise.
-
is_enabled
()[source]¶ Checking whether the node exports the data of the feature.
A node can export a feature in the advertising data without having the equivalent characteristic.
- Returns:
- bool: True if the node exports the data of the feature, False otherwise.
-
is_notifying
()[source]¶ Checking whether the notifications for the feature are enabled.
- Returns:
- bool: True if the feature is notifying, False otherwise.
-
remove_listener
(listener)[source]¶ Remove a listener.
- Args:
- listener (
blue_st_sdk.feature.FeatureListener
): Listener to be removed.
-
remove_logger
(logger)[source]¶ Remove a logger.
- Args:
- logger (
blue_st_sdk.feature.FeatureLogger
): Logger to be removed.
-
set_enable
(flag)[source]¶ Set the enable status of the feature.
- Args:
- flag (bool): New enable status: True to enable, False otherwise.
-
set_notify
(flag)[source]¶ Set the notification status of the feature.
- Args:
- flag (bool): New notification status: True to enable, False otherwise.
-
update
(timestamp, data, offset, notify_update=False)[source]¶ Update feature’s internal data through an atomic operation, and notify the registered listeners about the update, if needed.
This method has to be called by a node whenever it receives new data from the feature, not by the application.
When overriding this method, please remember to update the timestamp and the last-updated value, and to acquire the write-lock.
- Args:
- timestamp (int): Package’s timestamp. data (list): Feature’s data. offset (int): Offset position to start reading data. notify_update (bool, optional): If True all the registered listeners are notified about the new data.
- Returns:
- int: The number of bytes read.
- Raises:
blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidDataException
if the data array has not enough data to read.
-
-
class
blue_st_sdk.feature.
FeatureListener
[source]¶ Bases:
object
Interface used by the
blue_st_sdk.feature.Feature
class to notify changes of a feature’s data.-
on_update
(feature, sample)[source]¶ To be called whenever the feature updates its data.
- Args:
- feature (
blue_st_sdk.feature.Feature
): Feature that has updated. sample (blue_st_sdk.feature.Sample
): Sample data extracted from the feature. - Raises:
NotImplementedError
if the method has not been implemented.
-
-
class
blue_st_sdk.feature.
FeatureLogger
[source]¶ Bases:
object
Interface used by the
blue_st_sdk.feature.Feature
class to log changes of a feature’s data.-
log_update
(feature, raw_data, sample)[source]¶ To be called to log the updates of the feature.
- Args:
- feature (
blue_st_sdk.feature.Feature
): Feature that has updated. raw_data (str): Raw data used to update the feature. sample (blue_st_sdk.feature.Sample
): Sample data extracted from the feature. - Raises:
NotImplementedError
if the method has not been implemented.
-
-
class
blue_st_sdk.feature.
Sample
(data, description, timestamp=0)[source]¶ Bases:
object
Class that contains the last data from the node.
-
__init__
(data, description, timestamp=0)[source]¶ Constructor.
- Args:
- data (list): Feature’s data.
description (list): Description of the data of the feature (list
of
blue_st_sdk.features.field.Field
objects). timestamp (int): Data’s timestamp.
-
equals
(sample)[source]¶ Check the equality of the sample w.r.t. the given one.
- Args:
- sample (
blue_st_sdk.feature.Sample
): A sample object. - Returns:
- bool: True if the objects are equal (timestamp and data), False otherwise.
-
classmethod
from_sample
(copy_me)[source]¶ Make a copy of a sample.
- Args:
- copy_me (
blue_st_sdk.feature.Sample
): A given sample.
-
get_description
()[source]¶ Get the description.
- Returns:
- list: A list of
blue_st_sdk.features.field.Field
describing the sample.
-
blue_st_sdk.manager module¶
manager
The manager module is responsible for managing the discovery process of Bluetooth Low Energy (BLE) devices/nodes and allocating the needed resources.
-
class
blue_st_sdk.manager.
Manager
[source]¶ Bases:
object
Singleton class to manage the discovery of Bluetooth Low Energy (BLE) devices.
Before starting the scanning process, it is possible to define a new Device Id and to register/add new features to already defined devices.
It notifies a new discovered node through the
blue_st_sdk.manager.ManagerListener
class. Each callback is performed asynchronously by a thread running in background.-
SCANNING_TIME_DEFAULT_s
= 10¶ Default Bluetooth scanning timeout in seconds.
-
__init__
()[source]¶ Constructor.
- Raises:
Exception
is raised in case an instance of the same class has already been instantiated.
-
classmethod
add_features_to_node
(device_id, mask_to_features_dic)[source]¶ Add features to a node.
Register a new device identifier with the corresponding mask-to-features dictionary summarizing its available features, or add available features to an already registered device, before performing the discovery process.
Otherwise, it is possible to register the feature after discovering a node and before connecting to it (see
blue_st_sdk.node.Node.add_external_features()
).- Args:
- device_id (int): Device identifier. mask_to_features_dic (dict): Mask-to-features dictionary to be added to the features decoder dictionary referenced by the device identifier. The feature masks of the dictionary must have only one bit set to “1”.
- Raises:
blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidFeatureBitMaskException
is raised when a feature is in a non-power-of-two position.
-
add_listener
(listener)[source]¶ Add a listener.
- Args:
- listener (
blue_st_sdk.manager.ManagerListener
): Listener to be added.
-
discover
(timeout_s=10, asynchronous=False, show_warnings=False)[source]¶ Perform the discovery process.
This method can be run in synchronous (blocking) or asynchronous (non-blocking) way. Default is synchronous.
The discovery process will last timeout_s seconds if provided, a default timeout otherwise.
Please note that when running a discovery process, the already connected devices get disconnected (limitation intrinsic to the bluepy library).
- Args:
- timeout_s (int, optional): Time in seconds to wait before stopping the discovery process. asynchronous (bool, optional): If True the method is run in asynchronous way, thus non-blocking the execution of the thread, the opposite otherwise. show_warnings (bool, optional): If True shows warnings, if any, when discovering devices not respecting the BlueSTSDK’s advertising data format, nothing otherwise.
- Returns:
- bool: True if the synchronous discovery has finished or if the asynchronous discovery has started, False if a discovery is already running.
- Raises:
blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidOperationException
is raised if this method is not run as root.
-
classmethod
get_node_features
(device_id)[source]¶ Get a copy of the features map available for the given device identifier.
- Args:
- device_id (int): Device identifier.
- Returns:
- dict: A copy of the features map available for the given device identifier if found, the base features map otherwise.
-
get_node_with_name
(name)[source]¶ Get the node with the given name.
- Note:
- As the name is not unique, it will return the fist node matching. The match is case sensitive.
- Args:
- name (str): Name of the device.
- Returns:
blue_st_sdk.node.Node
: The node with the given name, None if not found.
-
get_node_with_tag
(tag)[source]¶ Get the node with the given tag.
- Args:
- tag (str): Unique string identifier that identifies a node.
- Returns:
blue_st_sdk.node.Node
: The node with the given tag, None if not found.
-
get_nodes
()[source]¶ Get the list of the discovered nodes until the time of invocation.
- Returns:
- list of
blue_st_sdk.node.Node
: The list of all discovered nodes until the time of invocation.
-
classmethod
instance
()[source]¶ Getting an instance of the class.
- Returns:
blue_st_sdk.manager.Manager
: An instance of the class.
-
is_discovering
()[source]¶ Check the discovery process.
- Returns:
- bool: True if the manager is looking for new nodes, False otherwise.
-
remove_listener
(listener)[source]¶ Remove a listener.
- Args:
- listener (
blue_st_sdk.manager.ManagerListener
): Listener to be removed.
-
reset_discovery
()[source]¶ Reset the discovery process.
Stop the discovery process and remove all the already discovered nodes. Node already bounded with the device will be kept in the list.
- Raises:
blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidOperationException
is raised if this method is not run as root.
-
start_discovery
(show_warnings=False)[source]¶ Start the discovery process.
This is an asynchronous (non-blocking) method.
The discovery process will last indefinitely, until stopped by a call to
stop_discovery()
. This method can be particularly useful when starting a discovery process from an interactive GUI.Please note that when running a discovery process, the already connected devices get disconnected (limitation intrinsic to the bluepy library).
- Args:
- show_warnings (bool, optional): If True shows warnings, if any, when discovering devices not respecting the BlueSTSDK’s advertising data format, nothing otherwise.
- Returns:
- bool: True if the discovery has started, False if a discovery is already running.
- Raises:
blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidOperationException
is raised if this method is not run as root.
-
stop_discovery
()[source]¶ Stop a discovery process.
To be preceeded by a call to
start_discovery()
. This method can be particularly useful when stopping a discovery process from an interactive GUI.- Returns:
- bool: True if the discovery has been stopped, False if there are no running discovery processes.
- Raises:
blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidOperationException
is raised if this method is not run as root.
-
-
class
blue_st_sdk.manager.
ManagerListener
[source]¶ Bases:
object
Interface used by the
blue_st_sdk.manager.Manager
class to notify that a new Node has been discovered or that the scanning has started/stopped.-
on_discovery_change
(manager, enabled)[source]¶ This method is called whenever a discovery process starts or stops.
- Args:
- manager (
blue_st_sdk.manager.Manager
): Manager instance that starts/stops the process. enabled (bool): True if a new discovery starts, False otherwise. - Raises:
NotImplementedError
if the method has not been implemented.
-
on_node_discovered
(manager, node)[source]¶ This method is called whenever a new node is discovered.
- Args:
- manager (
blue_st_sdk.manager.Manager
): Manager instance that discovers the node. node (blue_st_sdk.node.Node
): New node discovered. - Raises:
NotImplementedError
if the method has not been implemented.
-
blue_st_sdk.node module¶
node
The node module is responsible for managing a Bluetooth Low Energy (BLE) device/ node and allocating the needed resources.
-
class
blue_st_sdk.node.
Node
(scan_entry)[source]¶ Bases:
bluepy.btle.Peripheral
,object
Bluetooth Low Energy device class.
This class allows exporting features using Bluetooth Low Energy (BLE) transmission.
-
__init__
(scan_entry)[source]¶ Constructor.
- Args:
- scan_entry (ScanEntry): BLE device. It contains device information
- and advertising data. Refer to ScanEntry for more information.
- Raises:
blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidAdvertisingDataException
is raised if the advertising data is not well formed.blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidOperationException
is raised if the operation requested is not supported.
-
add_external_features
(user_defined_features)[source]¶ Add available features to an already discovered device.
This method has effect only if called before connecting to the node.
If a UUID is already known, it will be overwritten with the new list of available features.
Otherwise, it is possible to add available features before performing the discovery process (see
blue_st_sdk.manager.Manager.addFeaturesToNode()
method).- Args:
- user_defined_features (dict): User-defined feature to be added.
-
add_listener
(listener)[source]¶ Add a listener.
- Args:
- listener (
blue_st_sdk.node.NodeListener
): Listener to be added.
-
characteristic_can_be_notified
(characteristic)[source]¶ Check if a characteristics can be notified.
- Args:
- characteristic (Characteristic): The BLE characteristic to check. Refer to Characteristic for more information.
- Returns:
- bool: True if the characteristic can be notified, False otherwise.
-
characteristic_can_be_read
(characteristic)[source]¶ Check if a characteristics can be read.
- Args:
- characteristic (Characteristic): The BLE characteristic to check. Refer to Characteristic for more information.
- Returns:
- bool: True if the characteristic can be read, False otherwise.
-
characteristic_can_be_written
(characteristic)[source]¶ Check if a characteristics can be written.
- Args:
- characteristic (Characteristic): The BLE characteristic to check. Refer to Characteristic for more information.
- Returns:
- bool: True if the characteristic can be written, False otherwise.
-
characteristic_has_other_notifying_features
(characteristic, feature)[source]¶ Check whether a characteristic has other enabled features beyond the given one.
- Args:
- characteristic (Characteristic): The BLE characteristic to check.
Refer to
Characteristic
for more information.
feature (
blue_st_sdk.feature.Feature
): The given feature. - Returns:
- True if the characteristic has other enabled features beyond the given one, False otherwise.
-
connect
(user_defined_features=None)[source]¶ Open a connection to the node.
Please note that there is no supervision timeout API within the SDK, hence it is not possible to detect immediately an unexpected disconnection; it is detected and notified via listeners as soon as a read/write/notify operation is executed on the device (limitation intrinsic to the bluepy library).
- Args:
- user_defined_features (dict, optional): User-defined feature to be added.
- Returns:
- bool: True if the connection to the node has been successful, False otherwise.
-
disable_notifications
(feature)[source]¶ Ask the node to stop notifying when a feature updates its value.
- Args:
- feature (
blue_st_sdk.feature.Feature
): The given feature. - Returns:
- bool: False if the feature is not handled by this node, or it is disabled, or it is not possible to turn notifications off for it, True otherwise.
-
disconnect
()[source]¶ Close the connection to the node.
- Returns:
- bool: True if the disconnection to the node has been successful, False otherwise.
-
enable_notifications
(feature)[source]¶ Ask the node to notify when a feature updates its value.
The received values are notified thought a feature listener.
- Args:
- feature (
blue_st_sdk.feature.Feature
): The given feature. - Returns:
- bool: False if the feature is not handled by this node, or it is disabled, or it is not possible to turn notifications on for it, True otherwise.
-
equals
(node)[source]¶ Compare the current node with the given one.
- Returns:
- bool: True if the current node is equal to the given node, False otherwise.
-
get_advertising_data
()[source]¶ Update advertising data.
- Returns:
blue_st_sdk.advertising_data.blue_st_advertising_data.BlueSTAdvertisingData
: Formatted Blue ST Advertising Data object.
-
get_debug
()[source]¶ Getting a debug console used to read/write debug messages from/to the Bluetooth device.
- Returns:
blue_st_sdk.debug_console.DebugConsole
: A debug console used to read/write debug messages from/to the Bluetooth device. None if the device doesn’t export the debug service.
-
get_feature
(feature_class)[source]¶ Get a feature of the given type (class name).
- Args:
- feature_class (class): Type (class name) of the feature to search for.
- Returns:
- The feature of the given type (class name) if exported by this node, “None” otherwise.
-
get_features
(feature_class=None)[source]¶ Get the list of features.
Get the list of available features in the advertising data, or the list of features of the specific type (class name) if given.
- Args:
- feature_class (class, optional): Type (class name) of the feature to search for.
- Returns:
- list: A list of features. An empty list if no features are found.
-
get_friendly_name
()[source]¶ Get a friendly name of the node.
- Returns:
- str: A friendly name of the node.
-
get_last_rssi
()[source]¶ Get the most recent value of RSSI.
- Returns:
- int: The last known RSSI value.
-
get_last_rssi_update_date
()[source]¶ Get the time of the last RSSI update received.
- Returns:
- datetime: The time of the last RSSI update received. Refer to datetime for more information.
-
get_protocol_version
()[source]¶ Get the device Protocol Version.
- Returns:
- int: The device Protocol Version.
-
get_status
()[source]¶ Get the status of the node.
- Returns:
blue_st_sdk.node.NodeStatus
: The status of the node.
-
get_tag
()[source]¶ Get the tag of the node.
The tag is a unique identification, i.e. its MAC address.
- Returns:
- str: The MAC address of the node (hexadecimal string separated by colons).
-
get_tx_power_level
()[source]¶ Get the node transmission power in mdb.
- Returns:
- int: The node transmission power in mdb.
-
get_type
()[source]¶ Get the type of the node.
- Returns:
blue_st_sdk.node.NodeType
: The type of the node.- Raises:
blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidAdvertisingDataException
if the device type is unknown.
-
get_type_id
()[source]¶ Get the type identifier of the node.
- Returns:
- int: The type identifier of the node.
-
is_alive
(rssi)[source]¶ Check whether the node is alive.
To be called whenever the
blue_st_sdk.manager.Manager
class receives a new advertising data from this node.- Args:
- rssi (int): The RSSI of the last advertising data.
-
is_connected
()[source]¶ Check whether the node is connected.
- Returns:
- bool: True if the node is connected, False otherwise.
-
is_sleeping
()[source]¶ Check whether the node is sleeping.
- Returns:
- bool: True if the node is sleeping, False otherwise.
-
notifications_enabled
(feature)[source]¶ Check whether notifications are enabled for a feature.
- Args:
- feature (
blue_st_sdk.feature.Feature
): The given feature. - Returns:
- bool: True if notifications are enabled, False otherwise.
-
read_feature
(feature)[source]¶ Synchronous request to read a feature.
- Args:
- feature (
blue_st_sdk.feature.Feature
): The feature to read. - Raises:
blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidOperationException
is raised if the feature is not enabled or the operation required is not supported.blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidDataException
if the data array has not enough data to read.
-
remove_listener
(listener)[source]¶ Remove a listener.
- Args:
- listener (
blue_st_sdk.node.NodeListener
): Listener to be removed.
-
set_notification_status
(characteristic, status)[source]¶ Ask the node to set the notification status of the given characteristic.
- Args:
- characteristic (Characteristic): The BLE characteristic to check. Refer to Characteristic for more information. status (bool): True if the notifications have to be turned on, False otherwise.
-
update_advertising_data
(advertising_data)[source]¶ Update advertising data.
- Args:
- advertising_data (list): Advertising data. Refer to ‘getScanData()’ method of ScanEntry class for more information.
- Raises:
blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidAdvertisingDataException
is raised if the advertising data is not well formed.
-
wait_for_notifications
(timeout_s)[source]¶ Block until a notification is received from the peripheral, or until the given timeout has elapsed.
If a notification is received, the
blue_st_sdk.feature.FeatureListener.on_update()
method of any added listener is called.- Args:
- timeout_s (float): Time in seconds to wait before returning.
- Returns:
- bool: True if a notification is received before the timeout elapses, False otherwise.
-
write_feature
(feature, data)[source]¶ Synchronous request to write a feature.
- Args:
- feature (
blue_st_sdk.feature.Feature
): The feature to write. data (str): The data to be written. - Raises:
blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidOperationException
is raised if the feature is not enabled or the operation required is not supported.
-
-
class
blue_st_sdk.node.
NodeDelegate
(node)[source]¶ Bases:
bluepy.btle.DefaultDelegate
Delegate class for handling Bluetooth Low Energy devices’ notifications.
-
__init__
(node)[source]¶ Constructor.
- Args:
- node (
blue_st_sdk.node.Node
): The node which sends notifications.
-
-
class
blue_st_sdk.node.
NodeListener
[source]¶ Bases:
object
Interface used by the
blue_st_sdk.node.Node
class to notify changes of a node’s status.-
on_connect
(node)[source]¶ To be called whenever a node connects to a host.
- Args:
- node (
blue_st_sdk.node.Node
): Node that has connected to a - host.
- node (
- Raises:
NotImplementedError
if the method has not been implemented.
-
on_disconnect
(node, unexpected=False)[source]¶ To be called whenever a node disconnects from a host.
- Args:
- node (
blue_st_sdk.node.Node
): Node that has disconnected from a host. unexpected (bool, optional): True if the disconnection is unexpected, False otherwise (called by the user). - Raises:
NotImplementedError
if the method has not been implemented.
-
on_status_change
(node, new_status, old_status)[source]¶ To be called whenever a node changes its status.
- Args:
- node (
blue_st_sdk.node.Node
): Node that has changed its status. new_status (blue_st_sdk.node.NodeStatus
): New status. old_status (blue_st_sdk.node.NodeStatus
): Old status. - Raises:
NotImplementedError
if the method has not been implemented.
-
-
class
blue_st_sdk.node.
NodeStatus
[source]¶ Bases:
enum.Enum
Status of the node.
-
CONNECTED
= 'CONNECTED'¶ Connected to the node. This status can be fired 2 times while doing a secure connection using Bluetooth pairing.
-
CONNECTING
= 'CONNECTING'¶ Opening a connection with the node.
-
DEAD
= 'DEAD'¶ Dummy final status.
-
DISCONNECTING
= 'DISCONNECTING'¶ Closing the connection to the node.
-
IDLE
= 'IDLE'¶ Waiting for a connection and sending advertising data.
-
INIT
= 'INIT'¶ Dummy initial status.
-
LOST
= 'LOST'¶ The advertising data has been received for some time, but not anymore.
-
UNREACHABLE
= 'UNREACHABLE'¶ The node disappeared without first disconnecting.
-
-
class
blue_st_sdk.node.
NodeType
[source]¶ Bases:
enum.Enum
Type of node.
-
BLUE_COIN
= 3¶ BlueCoin.
-
DISCOVERY_IOT01A
= 7¶ B-L475E-IOT01A.
-
GENERIC
= 0¶ Unknown device type.
-
NUCLEO
= 8¶ NUCLEO-based.
-
SENSOR_TILE
= 2¶ SensorTile.
-
SENSOR_TILE_BOX
= 6¶ SensorTile.box.
-
STEVAL_BCN002V1
= 5¶ BlueNRG-Tile STEVAL.
-
STEVAL_IDB008VX
= 4¶ BlueNRG1 / BlueNRG2 STEVAL.
-
STEVAL_WESU1
= 1¶ STEVAL-WESU1.
-