Config Reference
Source code reference for the collector configuration code.
collector.src.config.datastructures.DeviceConfig
Configuration object which describes a type of device that the collector node runs on.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
str
|
A string representing the type of device, for example "Raspberry Pi 3." |
requires_micropython |
bool
|
If true, the program will not enable a start unless it is being run in a micropython environment. |
Source code in collector/src/config/datastructures.py
__init__(config, micropython)
Initializes the config and ensures the required attributes are present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, Any]
|
The device config object, ie. the dictionary contained within the "device" key in the config file. |
required |
|
bool
|
Whether the current environment is micropython |
required |
Source code in collector/src/config/datastructures.py
collector.src.config.datastructures.UploadConfig
Configuration object which describes a QuestDB target.
Attributes:
| Name | Type | Description |
|---|---|---|
host |
str
|
The database URL. |
port |
str
|
The database port. |
user |
str
|
The database username. |
password |
str
|
The database password. |
Source code in collector/src/config/datastructures.py
__init__(config)
Initializes the config and ensures the required attributes are present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, Any]
|
The upload config object, ie. the dictionary contained within the "upload" key in the config file. |
required |
Source code in collector/src/config/datastructures.py
collector.src.config.datastructures.SensorConfig
Configuration object which describes a sensor.
Attributes:
| Name | Type | Description |
|---|---|---|
sensor_id |
str
|
An ID associated with the sensor. |
sensor_code |
SensorCodeEnum
|
Associated with a specific implementation of AbstractSensorDriver. |
name |
str
|
A descriptive name for the sensor. |
gpio |
dict[str, int]
|
A dictionary where the values are GPIO pins which the sensor requires use of, and the keys are string identifiers. Used to validate that the configured GPIO pins match the allowed_gpio attribute of the device config. |
attributes |
dict[str, Any] | None
|
Any other attributes which are required to use the sensor. |
Source code in collector/src/config/datastructures.py
__init__(config, index)
Initializes the config and ensures the required attributes are present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, Any]
|
The sensor config object, ie. a dictionary contained within the "sensors" array in the config file. |
required |
|
int
|
The index of the sensor config within the "sensors" array. |
required |
|
The allowed GPIO pins as configured in the device config. |
required |
Source code in collector/src/config/datastructures.py
collector.src.config.datastructures.CollectorConfig
Configuration object which describes the collector node device.
Attributes:
| Name | Type | Description |
|---|---|---|
collector_id |
str
|
An ID associated with the node. |
node_name |
str
|
A name associated with the node. |
ssid_name |
str | None
|
If defined, the device will attempt to connect to this SSID. |
ssid_password |
str | None
|
If defined, the device will attempt to connect to this SSID. |
polling_interval |
int
|
The number of miliseconds to wait between sensor polls. Must not be negative. |
device |
DeviceConfig
|
The device config. |
upload |
UploadConfig
|
The configured upload target. |
sensors |
list[SensorConfig]
|
All configured sensors. |
Source code in collector/src/config/datastructures.py
__init__(config, device, upload, sensors)
Initializes the config and ensures the required attributes are present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, Any]
|
The config object, ie. the dictionary pulled from the config file. |
required |
|
DeviceConfig
|
The parsed device config. |
required |
|
UploadConfig
|
The parsed upload config. |
required |
|
list[SensorConfig]
|
The parsed sensor configs. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised if the polling interval is a negative number. |
Source code in collector/src/config/datastructures.py
collector.src.config.manager.ConfigManager
Parses and stores all configured paramteres for a collector node.
Attributes:
| Name | Type | Description |
|---|---|---|
micropython |
bool
|
If true, the program is being run within a micropython environment. |
_config |
CollectorConfig | None
|
The config, or None if it has not been successfully parsed. |
Source code in collector/src/config/manager.py
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
config
property
metadata
property
Packages the configuration into the metadata objects.
Returns:
| Type | Description |
|---|---|
tuple[CollectorMetadata, list[SensorMetadata]]
|
The metadata. |
__init__(micropython)
Initialize the config manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
If true, the program is being run within a micropython environment. |
required |
initialize_config()
Initializes config objects for all configuration parameters contained within the configuration file and sets the config on the class.
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised if any config is missing. |
Source code in collector/src/config/manager.py
collector.src.config.utils.get_attribute(config, attribute, config_name, required=True)
Retrieves the attribute from the config, or raises an error if it does not exist and the attribute is required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, Any]
|
The config to retrieve from. |
required |
|
str
|
The name of the attribute. |
required |
|
str
|
The name of the config. |
required |
|
bool
|
If true, an exception will be raised if the attribute doesn't exist. |
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised if the attribute does not exist within the config and is required. |
Returns:
| Type | Description |
|---|---|
Any
|
The config attribute, or None if it does not exist and is not required. |