API¶
System¶
- class icostate.ICOsystem(*arguments, **keyword_arguments)¶
Stateful access to ICOtronic system
- Parameters:
*arguments – Positional arguments (handled by pyee)
**keyword_arguments – Keyword arguments (handled by pyee)
- async collect_sensor_nodes()¶
Get available sensor nodes
This coroutine collects sensor node information until either
no new sensor node was found or
until the given timeout, if no sensor node was found.
- Return type:
list[SensorNodeInfo]- Returns:
A list containing information about the available sensor nodes
- Raises:
NoResponseError – If there was no response to an request made by this coroutine
Examples
Import necessary code
>>> from asyncio import run
Collect sensor nodes
>>> async def collect_sensor_nodes(icosystem: ICOsystem ... ) -> list[SensorNodeInfo]: ... await icosystem.connect_stu() ... nodes = await icosystem.collect_sensor_nodes() ... await icosystem.disconnect_stu() ... return nodes >>> sensor_nodes = run(collect_sensor_nodes(ICOsystem())) >>> # We assume that at least one sensor node is available >>> len(sensor_nodes) >= 1 True
- async connect_sensor_node_mac(mac_address)¶
Connect to the node with the specified MAC address
- Parameters:
mac_address (
str) – The MAC address of the sensor node- Raises:
ArgumentError – If the specified MAC address is not valid
NoResponseError – If there was no response to an request made by this coroutine
- Return type:
None
Examples
Import necessary code
>>> from asyncio import run
Connect to a disconnect from sensor node
>>> async def connect_sensor_node(icosystem: ICOsystem, ... mac_address: str): ... await icosystem.connect_stu() ... await icosystem.connect_sensor_node_mac(mac_address) ... print(icosystem.state) ... await icosystem.disconnect_sensor_node() ... print(icosystem.state) ... await icosystem.disconnect_stu() >>> mac_address = ( ... "08-6B-D7-01-DE-81") # Change to MAC address of your node >>> run(connect_sensor_node(ICOsystem(), mac_address)) Sensor Node Connected STU Connected
- async connect_stu()¶
Connect to STU
- Raises:
NoResponseError – If there was no response to an request made by this coroutine
- Return type:
None
Examples
Import necessary code
>>> from asyncio import run
Connect and disconnect from STU
>>> async def connect_disconnect_stu(icosystem: ICOsystem): ... print(f"Before connection to STU: {icosystem.state}") ... await icosystem.connect_stu() ... print(f"After connection to STU: {icosystem.state}") ... await icosystem.disconnect_stu() ... print(f"After disconnection fro STU: {icosystem.state}") >>> run(connect_disconnect_stu(ICOsystem())) Before connection to STU: Disconnected After connection to STU: STU Connected After disconnection fro STU: Disconnected
- async disconnect_sensor_node()¶
Disconnect from current sensor node
- Raises:
NoResponseError – If there was no response to an request made by this coroutine
- Return type:
None
- async disconnect_stu()¶
Disconnect from STU
- Raises:
NoResponseError – If there was no response to an request made by this coroutine
- Return type:
None
- async enable_ota()¶
Enable OTA (Over The Air) update mode
- Raises:
NoResponseError – If there was no response to an request made by this coroutine
- Return type:
None
Examples
Import necessary code
>>> from asyncio import run
Enable OTA update mode
>>> async def enable_ota(icosystem: ICOsystem): ... await icosystem.connect_stu() ... await icosystem.enable_ota() ... await icosystem.disconnect_stu() >>> run(enable_ota(ICOsystem()))
- async get_adc_configuration(mac_address=None)¶
Read the ADC configuration of a sensor node
Depending on the state the system is in this coroutine will either:
connect to the sensor device with the given MAC address, if there is no connection yet and disconnect afterwards or
just use the current connection and get the ADC configuration of the current sensor device. In this case the given MAC address will be ignored!
- Parameters:
mac_address (
str|None) – The MAC address of the sensor device for which we want to retrieve the ADC configuration- Raises:
NoResponseError – If there was no response to an request made by this coroutine
ValueError – If you call this method without specifying the MAC address while the system is not connected to a sensor node
- Return type:
ADCConfiguration- Returns:
The ADC configuration of the sensor node
Examples
Import necessary code
>>> from asyncio import run
Read the ADC configuration of a disconnected sensor node
>>> async def get_adc_configuration(icosystem: ICOsystem, ... mac_address: str ... ) -> ADCConfiguration: ... await icosystem.connect_stu() ... print(f"Before reading ADC config: {icosystem.state}") ... adc_config = (await ... icosystem.get_adc_configuration(mac_address)) ... print(f"After reading ADC config: {icosystem.state}") ... await icosystem.disconnect_stu() ... return adc_config >>> mac_address = ( ... "08-6B-D7-01-DE-81") # Change to MAC address of your node >>> config = run(get_adc_configuration(ICOsystem(), mac_address)) Before reading ADC config: STU Connected After reading ADC config: STU Connected >>> isinstance(config.prescaler, int) True >>> isinstance(config.acquisition_time, int) True >>> isinstance(config.oversampling_rate, int) True >>> isinstance(config.reference_voltage, float) True >>> 1 <= config.prescaler <= 127 True
Read the ADC configuration of a connected sensor node
>>> async def get_adc_configuration(icosystem: ICOsystem, ... mac_address: str ... ) -> ADCConfiguration: ... await icosystem.connect_stu() ... await icosystem.connect_sensor_node_mac(mac_address) ... adc_config = await icosystem.get_adc_configuration() ... await icosystem.disconnect_sensor_node() ... await icosystem.disconnect_stu() ... return adc_config >>> mac_address = ( ... "08-6B-D7-01-DE-81") # Change to MAC address of your node >>> config = run(get_adc_configuration(ICOsystem(), mac_address)) >>> isinstance(config, ADCConfiguration) True
- async is_sensor_node_connected()¶
Check if the STU is connected to a sensor node
- Return type:
bool- Returns:
True, if the STU is connected to a sensor nodeFalse, otherwise
Examples
Import necessary code
>>> from asyncio import run
Check if a sensor node is connected
>>> async def connect_sensor_node(icosystem: ICOsystem, ... mac_address: str): ... print("Before connection to STU:", ... await icosystem.is_sensor_node_connected()) ... await icosystem.connect_stu() ... print("After connection to STU:", ... await icosystem.is_sensor_node_connected()) ... await icosystem.connect_sensor_node_mac(mac_address) ... print("After connection to sensor node:", ... await icosystem.is_sensor_node_connected()) ... await icosystem.disconnect_sensor_node() ... print("After disconnection from sensor node:", ... await icosystem.is_sensor_node_connected()) ... await icosystem.disconnect_stu() >>> mac_address = ( ... "08-6B-D7-01-DE-81") # Change to MAC address of your node >>> run(connect_sensor_node(ICOsystem(), mac_address)) Before connection to STU: False After connection to STU: False After connection to sensor node: True After disconnection from sensor node: False
- async rename(new_name, mac_address=None)¶
Set the name of the sensor node with the specified MAC address
Depending on the state the system is in this coroutine will either:
connect to the sensor device with the given MAC address, if there is no connection yet and disconnect afterwards or
just use the current connection and rename the current sensor device. In this case the given MAC address will be ignored!
- Parameters:
new_name (
str) – The new name of the sensor devicemac_address (
str|None) – The MAC address of the sensor device that should be renamed
- Raises:
NoResponseError – If there was no response to an request made by this coroutine
ValueError – If you call this method without specifying the MAC address while the system is not connected to a sensor node
Examples
Import necessary code :rtype:
None>>> from asyncio import run
Rename a disconnected sensor node
>>> async def rename_disconnected(icosystem: ICOsystem, ... mac_address: str, ... name: str): ... await icosystem.connect_stu() ... print(f"Before renaming: {icosystem.state}") ... await icosystem.rename(name, mac_address) ... print(f"After renaming: {icosystem.state}") ... await icosystem.disconnect_stu() >>> mac_address = ( ... "08-6B-D7-01-DE-81") # Change to MAC address of your node >>> name = "Test-STH" >>> run(rename_disconnected(ICOsystem(), mac_address, name)) Before renaming: STU Connected After renaming: STU Connected
Rename a connected sensor node
>>> async def rename_connected(icosystem: ICOsystem, ... mac_address: str, ... name: str): ... await icosystem.connect_stu() ... await icosystem.connect_sensor_node_mac(mac_address) ... print(f"Before renaming: {icosystem.state}") ... await icosystem.rename(name, None) ... print(f"After renaming: {icosystem.state}") ... await icosystem.disconnect_sensor_node() ... await icosystem.disconnect_stu() >>> mac_address = ( ... "08-6B-D7-01-DE-81") # Change to MAC address of your node >>> name = "Test-STH" >>> run(rename_connected(ICOsystem(), mac_address, name)) Before renaming: Sensor Node Connected After renaming: Sensor Node Connected
- async reset_stu()¶
Reset STU
- Raises:
NoResponseError – If there was no response to an request made by this coroutine
- Return type:
None
Examples
Import necessary code
>>> from asyncio import run
Reset a connected STU
>>> async def reset_stu(icosystem: ICOsystem): ... await icosystem.connect_stu() ... await icosystem.reset_stu() ... await icosystem.disconnect_stu() >>> run(reset_stu(ICOsystem()))
Resetting the STU will not work if the STU is not connected
>>> async def reset_stu_without_connection(icosystem: ICOsystem): ... await icosystem.reset_stu() >>> run(reset_stu_without_connection( ... ICOsystem())) Traceback (most recent call last): ... icostate.error.IncorrectStateError: Resetting STU only allowed in the state: STU Connected
- sensor_node_attributes: SensorNodeAttributes | None¶
Information about currently connected sensor node
- async set_adc_configuration(adc_configuration, mac_address=None)¶
Change the ADC configuration of a sensor node
Depending on the state the system is in this coroutine will either:
connect to the sensor device with the given MAC address, if there is no connection yet and disconnect afterwards or
just use the current connection and change the ADC configuration of the current sensor device. In this case the given MAC address will be ignored!
- Parameters:
mac_address (
str|None) – The MAC address of the sensor device for which we want to change the ADC configuration- Raises:
NoResponseError – If there was no response to an request made by this coroutine
ValueError – If you call this method without specifying the MAC address while the system is not connected to a sensor node
Examples
Import necessary code :rtype:
None>>> from asyncio import run
Set the ADC configuration of a disconnected sensor node
>>> async def set_adc_configuration(icosystem: ICOsystem, ... adc_config: ADCConfiguration, ... mac_address: str): ... await icosystem.connect_stu() ... print(f"Before setting ADC config: {icosystem.state}") ... adc_config = (await ... icosystem.set_adc_configuration(adc_config, ... mac_address)) ... print(f"After setting ADC config: {icosystem.state}") ... await icosystem.disconnect_stu() >>> mac_address = ( ... "08-6B-D7-01-DE-81") # Change to MAC address of your node >>> config = ADCConfiguration(prescaler=2, ... acquisition_time=8, ... oversampling_rate=64) >>> config = run(set_adc_configuration(ICOsystem(), config, ... mac_address)) Before setting ADC config: STU Connected After setting ADC config: STU Connected
Set the ADC configuration of a connected sensor node
>>> async def set_adc_configuration(icosystem: ICOsystem, ... adc_config: ADCConfiguration, ... mac_address: str): ... await icosystem.connect_stu() ... await icosystem.connect_sensor_node_mac(mac_address) ... print(f"Before setting ADC config: {icosystem.state}") ... adc_config = (await ... icosystem.set_adc_configuration(adc_config)) ... print(f"After setting ADC config: {icosystem.state}") ... await icosystem.disconnect_sensor_node() ... await icosystem.disconnect_stu() >>> mac_address = ( ... "08-6B-D7-01-DE-81") # Change to MAC address of your node >>> config = ADCConfiguration(prescaler=2, ... acquisition_time=8, ... oversampling_rate=64) >>> config = run(set_adc_configuration(ICOsystem(), config, ... mac_address)) Before setting ADC config: Sensor Node Connected After setting ADC config: Sensor Node Connected