Sensor Wrappers (OzWrapper)

Each wrapper abstracts over one or more hardware drivers for a specific measurement category. All wrappers extend SensorBase.SensorBase.GenericSensor.

Environmental

OzTemp – Temperature & Humidity

Temperature, humidity, pressure, and dew-point sensor wrapper.

Abstracts over multiple hardware drivers – BME280, SHT31, SHT41, DS18B20, ES12248, MPL1152, LPS25HB, and ATH20 – providing a unified interface for ambient temperature, relative humidity, barometric pressure, and dew-point readings through the GenericSensor contract.

class OzWrapper.OzTemp.OzTemp.OzTemp[source]

Bases: GenericSensor

Wrapper for temperature, humidity, pressure, and dew-point sensors.

Manages initialisation, periodic reading, and value aggregation for every temperature-family sensor supported by the device. The specific hardware driver instantiated depends on the part number received in the Gateway configuration.

Variables:
  • configuration – List of sensor config dicts from the Gateway.

  • v_temphum – Nested list holding accumulated readings per sensor/parameter.

  • bme280 – BME280 driver instance for ambient temperature/humidity/pressure.

  • boxbme280 – BME280 driver instance for box-internal readings.

  • sht – SHT31 driver instance.

  • sht_address – I2C address of the active SHT31 sensor.

  • bme_address – Index into bme_add for the active box BME280 address.

  • bme_add – Candidate I2C addresses for the box BME280.

  • bme_sensor – Whether the primary BME280 address is still valid.

  • mpl1152 – MPL1152 barometric-pressure driver instance.

configuration: ClassVar[list[dict]] = []
v_temphum: ClassVar[list] = []
bme280 = None
boxbme280 = None
sht = None
sht_address = 0
bme_address = 0
bme_add: ClassVar[list] = [118, 119]
bme_sensor = True
mpl1152 = None
__init__()[source]

Initialise the OzTemp wrapper with default state.

Return type:

None

initialize(config, init_value)[source]

Initialise all temperature sensors listed in the Gateway config.

Parameters:
  • config (dict) – List of sensor configuration dicts from the Gateway.

  • init_value (dict) – Mutable dict updated with per-sensor init status.

Return type:

bool

Returns:

True if at least one sensor initialised successfully.

initializeSensor(sensor)[source]

Initialise a single temperature-family sensor by part number.

Creates the appropriate hardware driver, takes an initial reading for each configured parameter, and stores the bootstrap values in v_temphum.

Parameters:

sensor (dict) – Single sensor configuration dict containing part number, enable flag, GPIO settings, and parameter list.

Return type:

int

Returns:

1 if the sensor was initialised successfully, 0 otherwise.

getSensorReading(calibrationKeys=None)[source]

Read current values from all initialised temperature sensors.

Applies sensitivity and correction offsets, accumulates values for later averaging, and returns real-time data keyed by short-code.

Parameters:

calibrationKeys (list[str] | None) – Optional list of short-code keys to restrict which parameters are read. If empty or None, all parameters are read.

Return type:

dict

Returns:

Dict mapping parameter short-codes to their latest readings.

putSensorValue(value, calibrationKeys=None)[source]

Flush accumulated readings into the output dict and reset counters.

Optionally triggers the SHT31 heater for humidity-sensor conditioning.

Parameters:
  • value (dict) – Mutable output dict to populate with aggregated readings.

  • calibrationKeys (list[str] | None) – Optional list of short-code keys to restrict which parameters are flushed.

Return type:

dict

Returns:

The updated output dict with lists of accumulated values per short-code.

putInitvalues(value)[source]

Record each sensor’s init status into the shared init-value dict.

Parameters:

value (<module ‘json’ from ‘/opt/buildhome/.asdf/installs/python/3.12.12/lib/python3.12/json/__init__.py’>) – Mutable dict updated in-place with a "temp" key containing a list of per-sensor init statuses.

Return type:

<module ‘json’ from ‘/opt/buildhome/.asdf/installs/python/3.12.12/lib/python3.12/json/__init__.py’>

Returns:

The updated init-value dict.

getTempHum(partNo, pm)[source]

Dispatch a reading request to the correct measurement sub-method.

Parameters:
  • partNo (int) – Hardware part number identifying the sensor model.

  • pm (int) – Parameter identifier (1=temp, 2=humidity, 3=pressure, 4=dew point).

Return type:

float

Returns:

The measured value rounded to two decimal places.

getMAXTemp(pm)[source]

Read temperature from the MAX31875 sensor (currently unused).

Parameters:

pm (int) – Parameter identifier used to derive the I2C channel.

Return type:

float

Returns:

Temperature in degrees Celsius, rounded to two decimal places.

getTemp(partNo)[source]

Read temperature from the sensor identified by part number.

Parameters:

partNo (int) – Hardware part number selecting the driver to query.

Return type:

Union[float, Literal[0]]

Returns:

Temperature in degrees Celsius, or 0 on failure.

getHum(partNo)[source]

Read relative humidity from the sensor identified by part number.

Parameters:

partNo (int) – Hardware part number selecting the driver to query.

Return type:

Union[float, Literal[0]]

Returns:

Relative humidity in percent, or 0 on failure.

getPressure(partNo)[source]

Read barometric pressure from the sensor identified by part number.

Parameters:

partNo (int) – Hardware part number selecting the driver to query.

Return type:

Union[float, Literal[0]]

Returns:

Pressure in hPa, or 0 on failure.

getDewPoint(partNo)[source]

Calculate dew point using the Magnus-Tetens formula.

Requires temperature and humidity from an SHT31 sensor (part 25).

Parameters:

partNo (int) – Hardware part number (only 25 is supported).

Return type:

Union[float, Literal[0]]

Returns:

Dew point in degrees Celsius, or 0 on failure.

OzDust – Particulate Matter

OzCO2 – Carbon Dioxide

CO2 sensor wrapper.

Abstracts over CO2 hardware drivers – ELTCO2 and SCD40 – providing a unified interface for carbon dioxide concentration, temperature, and humidity readings through the GenericSensor contract.

class OzWrapper.OzCO2.OzCO2.OzCO2[source]

Bases: GenericSensor

Wrapper for CO2 sensors.

Manages initialisation, periodic reading, and value aggregation for CO2 sensors. Supports ELT CO2 (I2C) and SCD40 (I2C) drivers, selected by the part number in the Gateway configuration.

Variables:
  • configuration (dict) – List of sensor config dicts from the Gateway.

  • v_co2 (list) – Nested list holding accumulated readings per sensor/parameter.

  • ELT_CO2 (ELTCO2 | None) – ELTCO2 driver instance, or None if not configured.

  • SCD_CO2 (SCD40 | None) – SCD40 driver instance, or None if not configured.

__init__()[source]

Initialise the OzCO2 wrapper with default state.

Return type:

None

initialize(config, init_value)[source]

Initialise all CO2 sensors listed in the Gateway config.

Parameters:
  • config (dict) – List of sensor configuration dicts from the Gateway.

  • init_value (dict) – Mutable dict updated with per-sensor init status.

Return type:

bool

Returns:

True if at least one sensor initialised successfully.

initializeSensor(sensor)[source]

Initialise a single CO2 sensor by part number.

Creates the appropriate hardware driver, takes initial readings with retries, and stores bootstrap values in v_co2.

Parameters:

sensor (dict) – Single sensor configuration dict containing part number, enable flag, GPIO settings, and parameter list.

Return type:

int

Returns:

1 if the sensor was initialised successfully, 0 otherwise.

getCO2(partNo, pm)[source]

Read a CO2-related measurement from the correct driver.

Parameters:
  • partNo (int) – Hardware part number identifying the sensor model.

  • pm (int) – Parameter identifier (1=CO2 ppm, 2=temperature, 3=humidity).

Return type:

float | int

Returns:

The measured value, or 0.0 if unsupported.

findKeyinList(keys, sensor)[source]

Check whether any parameter short-code in the sensor matches the given keys.

Parameters:
  • keys (list[str]) – List of short-code prefixes to match against.

  • sensor (dict) – Sensor config dict containing a "parameters" list.

Return type:

bool

Returns:

True if at least one parameter short-code matches a key.

getSensorReading(calibrationKeys=None)[source]

Read current values from all initialised CO2 sensors.

Applies sensitivity and correction offsets, accumulates values for later averaging, and returns real-time data keyed by short-code.

Parameters:

calibrationKeys (list[str] | None) – Optional list of short-code keys to restrict which parameters are read.

Return type:

dict

Returns:

Dict mapping parameter short-codes to their latest readings.

putSensorValue(value, calibrationKeys=None)[source]

Flush accumulated CO2 readings into the output dict and reset counters.

Parameters:
  • value (dict) – Mutable output dict to populate with aggregated readings.

  • calibrationKeys (list[str] | None) – Optional list of short-code keys to restrict which parameters are flushed.

Return type:

dict

Returns:

The updated output dict.

putInitvalues(value)[source]

Record each sensor’s init status into the shared init-value dict.

Parameters:

value (dict) – Mutable dict updated in-place with a "co2" key.

Return type:

dict

Returns:

The updated init-value dict.

OzCH4 – Methane

Methane (CH4) sensor wrapper.

Abstracts over the ELT CH4 UART driver to provide a unified interface for methane concentration readings through the GenericSensor contract.

class OzWrapper.OzCH4.OzCH4.OzCH4[source]

Bases: GenericSensor

Wrapper for methane (CH4) sensors.

Manages initialisation, periodic reading, and value aggregation for CH4 sensors using the ELT CH4 UART driver.

Variables:
  • configuration (dict) – List of sensor config dicts from the Gateway.

  • v_ch4 (list) – Nested list holding accumulated readings per sensor/parameter.

  • CH4 – ELT CH4 driver instance, or None if not configured.

__init__()[source]

Initialise the OzCH4 wrapper with default state.

Return type:

None

initialize(config, init_value)[source]

Initialise all CH4 sensors listed in the Gateway config.

Parameters:
  • config (dict) – List of sensor configuration dicts from the Gateway.

  • init_value (dict) – Mutable dict updated with per-sensor init status.

Return type:

bool

Returns:

True if at least one sensor initialised successfully.

initializeSensor(sensor)[source]

Initialise a single CH4 sensor by part number.

Creates the ELT CH4 UART driver, takes an initial reading, and stores bootstrap values in v_ch4.

Parameters:

sensor (dict) – Single sensor configuration dict containing part number, enable flag, GPIO/UART settings, and parameter list.

Return type:

int

Returns:

1 if the sensor was initialised successfully, 0 otherwise.

getCH4(partNo, pm)[source]

Read a CH4 measurement from the correct driver.

Parameters:
  • partNo (int) – Hardware part number identifying the sensor model.

  • pm (int) – Parameter identifier (1=CH4 concentration).

Return type:

float

Returns:

The measured value as a float, or 0.0 if unsupported.

getSensorReading()[source]

Read current values from all initialised CH4 sensors.

Applies sensitivity and correction offsets, accumulates values for later averaging, and returns real-time data keyed by short-code.

Return type:

dict

Returns:

Dict mapping parameter short-codes to their latest readings.

putSensorValue(value)[source]

Flush accumulated CH4 readings into the output dict and reset counters.

Parameters:

value (dict) – Mutable output dict to populate with aggregated readings.

Return type:

dict

Returns:

The updated output dict.

putInitvalues(value)[source]

Record each sensor’s init status into the shared init-value dict.

Parameters:

value (dict) – Mutable dict updated in-place with a "ch4" key.

Return type:

dict

Returns:

The updated init-value dict.

OzCO – Carbon Monoxide

Carbon monoxide (CO) sensor wrapper.

Provides a stub implementation for CO sensor readings through the GenericSensor contract. Currently uses hardcoded test values as the hardware driver has not yet been integrated.

class OzWrapper.OzCO.OzCO.OzCO[source]

Bases: GenericSensor

Wrapper for carbon monoxide (CO) sensors.

Currently a stub implementation with hardcoded values. Designed to be extended with a real CO sensor driver once hardware is available.

Variables:
  • sensor_config – List of sensor config dicts from the Gateway.

  • v_co – Nested list holding accumulated readings per sensor/parameter.

sensor_config = {}
v_co = []
__init__()[source]

Initialise the OzCO wrapper with default state.

initialize(config)[source]

Initialise all CO sensors listed in the Gateway config.

Parameters:

config (<module ‘json’ from ‘/opt/buildhome/.asdf/installs/python/3.12.12/lib/python3.12/json/__init__.py’>) – List of sensor configuration dicts from the Gateway.

Returns:

True (always, as this is a stub implementation).

initializeSensor(sensor)[source]

Initialise a single CO sensor by part number.

Parameters:

sensor (<module ‘json’ from ‘/opt/buildhome/.asdf/installs/python/3.12.12/lib/python3.12/json/__init__.py’>) – Single sensor configuration dict containing part number, enable flag, and parameter list.

Returns:

1 if the sensor was initialised successfully.

getCO(partNo, pm)[source]

Read a CO measurement (stub returning hardcoded value).

Parameters:
  • partNo (int) – Hardware part number identifying the sensor model.

  • pm (int) – Parameter identifier (1=CO concentration).

Returns:

Hardcoded CO value for testing, or None if unsupported.

getSensorReading()[source]

Read current values from all initialised CO sensors.

Accumulates values for later averaging and returns real-time data.

Returns:

Dict mapping parameter short-codes to their latest readings.

putSensorValue(value)[source]

Compute averages and flush CO readings into the output dict.

Applies sensitivity and correction offsets to the averaged value.

Parameters:

value (<module ‘json’ from ‘/opt/buildhome/.asdf/installs/python/3.12.12/lib/python3.12/json/__init__.py’>) – Mutable output dict to populate with averaged readings.

Return type:

<module ‘json’ from ‘/opt/buildhome/.asdf/installs/python/3.12.12/lib/python3.12/json/__init__.py’>

Returns:

The updated output dict.

Meteorological

OzWind – Wind Speed & Direction

Wind speed, direction, and gust sensor wrapper.

Communicates with a SAMD-based co-processor over UART (via the OzLan driver) to read wind direction, wind speed, and wind gust measurements through the GenericSensor contract.

class OzWrapper.OzWind.OzWind.OzWind[source]

Bases: GenericSensor

Wrapper for wind sensors communicating via a SAMD co-processor.

Reads wind direction, wind speed, and optionally wind gust from a SAMD-based board over serial. Includes spike filtering to reject implausible jumps in consecutive readings.

Variables:
  • configuration – List of sensor config dicts from the Gateway.

  • v_wind – Nested list holding wind reading arrays per sensor.

  • wind_old – Previous wind reading used for spike filtering.

  • wind_port – OzLan serial port instance for SAMD communication.

  • speed_threshold – Maximum acceptable speed jump between consecutive reads.

  • dir_threshold – Maximum acceptable direction jump between consecutive reads.

configuration: ClassVar[dict] = {}
v_wind: ClassVar[list] = []
wind_old = None
wind_port: ClassVar[OzLan] = None
speed_threshold = 10
dir_threshold = 10
__init__()[source]

Initialise the OzWind wrapper with default state.

Return type:

None

is_valid_wind(wind_old, wind_new)[source]

Validate a new wind reading against the previous one using thresholds.

Rejects readings where both speed and direction jump exceed their respective thresholds simultaneously, which indicates a sensor glitch.

Parameters:
  • wind_old – Previous wind reading as a list [direction, speed, …].

  • wind_new – New wind reading as a list [direction, speed, …].

Returns:

True if the new reading is plausible, False if it should be rejected.

initialize(config, init_value)[source]

Initialise all wind sensors listed in the Gateway config.

Parameters:
  • config (dict) – List of sensor configuration dicts from the Gateway.

  • init_value (dict) – Mutable dict updated with per-sensor init status.

Return type:

bool

Returns:

True (always returns True for SAMD-based sensors).

initializeSensor(sensor)[source]

Initialise a single wind sensor by part number.

Opens the serial connection to the SAMD co-processor, configures the wind measurement type, and takes an initial reading.

Parameters:

sensor (dict) – Single sensor configuration dict containing part number, enable flag, and GPIO/UART settings.

Return type:

int

Returns:

1 if the SAMD reports the sensor is alive, 0 or -1 otherwise.

initializeWind(sensor)[source]

Open the serial connection to the SAMD and verify sensor liveness.

Sends a configuration command followed by a liveness check.

Parameters:

sensor (dict) – Sensor config dict with GPIO/UART port, baud, and optional thresholds.

Return type:

int

Returns:

1 if the SAMD reports the wind sensor is alive, 0 otherwise.

getSensorReading()[source]

Trigger a wind reading from all initialised sensors.

This method does not return data directly; values are collected in putSensorValue.

Return type:

None

putSensorValue(value)[source]

Read final wind values and populate the output dict.

Applies spike filtering against the previous reading; substitutes zeroes if the new reading is rejected.

Parameters:

value (dict) – Mutable output dict to populate with wind readings.

Return type:

dict

Returns:

The updated output dict.

getWindSensorReading(partNo, flag=False)[source]

Conditionally read wind data from the SAMD.

Parameters:
  • partNo (int) – Hardware part number identifying the sensor model.

  • flag (bool) – If True, perform the actual read; otherwise return 0.

Return type:

int

Returns:

Wind data list when flag is True, 0 otherwise.

getWind(partNo)[source]

Read wind direction, speed, and optionally gust from the SAMD.

Parameters:

partNo (int) – Hardware part number (211=dir+speed, 213=dir+speed+gust).

Returns:

[direction, speed] or [direction, speed, gust].

Return type:

list

OzRain – Rainfall

Rainfall sensor wrapper.

Communicates with a SAMD-based co-processor over UART (via the OzLan driver) to read tipping-bucket rain gauge counts and compute rainfall amounts through the GenericSensor contract.

class OzWrapper.OzRain.OzRain.OzRain[source]

Bases: GenericSensor

Wrapper for rainfall sensors via a SAMD co-processor.

Configures the rain gauge GPIO on the SAMD, reads accumulated tip counts, and converts them to rainfall amounts.

Variables:
  • configuration – List of sensor config dicts from the Gateway.

  • v_rain – Nested list holding accumulated readings per sensor.

  • rain_port – OzLan serial port instance for SAMD communication.

configuration: ClassVar[dict] = {}
v_rain: ClassVar[list[list[int]]] = []
rain_port: OzLan | None = None
__init__()[source]

Initialise the OzRain wrapper with default state.

Return type:

None

initialize(config, init_value)[source]

Initialise all rainfall sensors listed in the Gateway config.

Parameters:
  • config (dict) – List of sensor configuration dicts from the Gateway.

  • init_value (dict) – Mutable dict updated with per-sensor init status.

Return type:

bool

Returns:

True (always returns True for SAMD-based sensors).

initializeSensor(sensor)[source]

Initialise a single rainfall sensor by part number.

Opens the serial connection to the SAMD and sends the rain gauge GPIO configuration command.

Parameters:

sensor (dict) – Single sensor configuration dict containing part number, enable flag, and GPIO/UART settings.

Return type:

int

Returns:

1 if the sensor was initialised successfully, 0 otherwise.

getRain(partNo, pm)[source]

Read the accumulated rain count from the SAMD co-processor.

Parameters:
  • partNo (int) – Hardware part number identifying the sensor model.

  • pm (int) – Parameter identifier (1=rain count).

Return type:

int

Returns:

Rain count value, or 0 on error or unsupported part.

getSensorReading()[source]

Trigger a rain reading from all initialised sensors.

This method does not return data directly; values are collected in putSensorValue.

Return type:

None

putSensorValue(value)[source]

Read final rainfall values and populate the output dict.

Applies sensitivity and correction offsets to the raw rain count.

Parameters:

value (dict) – Mutable output dict to populate with rainfall readings.

Return type:

dict

Returns:

The updated output dict.

getRainSensorReading(partNo, flag=False)[source]

Conditionally read rain data from the SAMD.

Parameters:
  • partNo (int) – Hardware part number identifying the sensor model.

  • flag (bool) – If True, perform the actual read; otherwise return 0.

Return type:

int

Returns:

Rain count value when flag is True, 0 otherwise.

OzFlood – Flood Level

Flood level sensor wrapper.

Abstracts over flood-level hardware drivers – Flood (I2C ultrasonic) and FloodUART (UART ultrasonic) – providing a unified interface for water-level distance measurements through the GenericSensor contract.

class OzWrapper.OzFlood.OzFlood.OzFlood[source]

Bases: GenericSensor

Wrapper for flood-level distance sensors.

Manages initialisation, periodic reading, and value aggregation for ultrasonic flood-level sensors (I2C and UART variants).

Variables:
  • flood_driver – Flood I2C driver instance, or None.

  • flood_UARTport – FloodUART driver instance, or None.

  • configuration (dict) – List of sensor config dicts from the Gateway.

  • v_flood (list) – Nested list holding accumulated readings per sensor/parameter.

  • s_flood (list) – Supplementary flood state list.

flood_driver = None
flood_UARTport = None
__init__()[source]

Initialise the OzFlood wrapper with default state.

Return type:

None

initialize(config, init_value)[source]

Initialise all flood sensors listed in the Gateway config.

Parameters:
  • config (dict) – List of sensor configuration dicts from the Gateway.

  • init_value (dict) – Mutable dict updated with per-sensor init status.

Return type:

bool

Returns:

True if at least one sensor initialised successfully.

initializeSensor(sensor)[source]

Initialise a single flood sensor by part number.

Creates the appropriate driver (I2C or UART), takes an initial reading, and stores bootstrap values in v_flood.

Parameters:

sensor (dict) – Single sensor configuration dict containing part number, enable flag, GPIO/I2C settings, and parameter list.

Return type:

int

Returns:

1 if the sensor was initialised successfully, 0 otherwise.

getSensorReading()[source]

Read current flood levels from all initialised sensors.

Applies sensitivity and correction offsets, accumulates values for later averaging, and returns real-time data keyed by short-code.

Return type:

dict

Returns:

Dict mapping parameter short-codes to their latest readings.

putSensorValue(value)[source]

Flush accumulated flood readings into the output dict and reset counters.

Parameters:

value (dict) – Mutable output dict to populate with aggregated readings.

Return type:

dict

Returns:

The updated output dict.

putInitvalues(value)[source]

Record each sensor’s init status into the shared init-value dict.

Parameters:

value (dict) – Mutable dict updated in-place with a "flood" key.

Return type:

dict

Returns:

The updated init-value dict.

getFlood(partNo, pm)[source]

Read a flood-level measurement from the correct driver.

Parameters:
  • partNo (int) – Hardware part number (71=I2C, 72=UART).

  • pm (int) – Parameter identifier (currently unused; single measurement).

Return type:

int | None

Returns:

Distance measurement in mm, or None if unsupported.

OzSoil – Soil Moisture

Soil sensor wrapper.

Abstracts over multiple soil sensor drivers – JXBS3001, SEN0600, and NIUBOL (8-in-1 and 3-in-1) – providing a unified interface for soil pH, moisture, temperature, electrical conductivity, nitrogen, phosphorus, and potassium readings through the GenericSensor contract.

class OzWrapper.OzSoil.OzSoil.OzSoil[source]

Bases: GenericSensor

Wrapper for soil sensors (pH, moisture, temperature, EC, NPK).

Manages initialisation, periodic reading, and value aggregation for Modbus-based soil sensors connected via UART.

Variables:
  • jxbs – JXBS3001 Modbus soil sensor driver instance.

  • configuration – List of sensor config dicts from the Gateway.

  • v_soil – Nested list holding accumulated readings per sensor/parameter.

jxbs = None
__init__()[source]

Initialise the OzSoil wrapper with default state.

Return type:

None

initialize(config, init_value)[source]

Initialise all soil sensors listed in the Gateway config.

Parameters:
  • config (dict) – List of sensor configuration dicts from the Gateway.

  • init_value (dict) – Mutable dict updated with per-sensor init status.

Return type:

bool

Returns:

True if at least one sensor initialised successfully.

initializeSensor(sensor)[source]

Initialise a single soil sensor by part number.

Creates the appropriate Modbus driver, takes initial readings for each configured parameter, and stores bootstrap values in v_soil.

Parameters:

sensor (dict) – Single sensor configuration dict containing part number, enable flag, UART settings, and parameter list.

Return type:

int

Returns:

1 if the sensor was initialised successfully, 0 otherwise.

getSoil(partNo, pm)[source]

Read a soil measurement from the correct driver.

Parameter mapping for configuration keys:

so1 – pH, so2 – Soil Moisture (%), so3 – Soil Temperature (C), so4 – Electrical Conductivity (uS/cm), so5 – Nitrogen Content (mg/kg), so6 – Phosphorus Content (mg/kg), so7 – Potassium Content (mg/kg).

Parameters:
  • partNo (int) – Hardware part number identifying the sensor model.

  • pm (int) – Parameter identifier (1-8, mapping varies by sensor).

Returns:

The measured value, or None if unsupported.

CONTEXT: KEY USED IN CONFIGURATION FILES: so1-pH so2-Soil Moisture (%) so3-Soil Temperature (°C) so4-Electrical Conductivity (µS/cm) so5-Nitrogen Content (mg/kg) so6-Phosphorus Content (mg/kg) so7-Potassium Content (mg/kg)

getSensorReading()[source]

Read current values from all initialised soil sensors.

Applies sensitivity and correction offsets, accumulates values for later averaging, and returns real-time data keyed by short-code.

Return type:

dict

Returns:

Dict mapping parameter short-codes to their latest readings.

putSensorValue(value)[source]

Flush accumulated soil readings into the output dict and reset counters.

Parameters:

value (dict) – Mutable output dict to populate with aggregated readings.

Return type:

dict

Returns:

The updated output dict.

putInitvalues(value)[source]

Record each sensor’s init status into the shared init-value dict.

Parameters:

value (dict) – Mutable dict updated in-place with a "soil" key.

Return type:

dict

Returns:

The updated init-value dict.

OzSurface – Surface Temperature

Surface temperature sensor wrapper.

Communicates with a SAMD-based co-processor over UART (via the OzLan driver) to read surface temperature measurements through the GenericSensor contract.

class OzWrapper.OzSurface.OzSurface.OzSurface[source]

Bases: GenericSensor

Wrapper for surface temperature sensors via a SAMD co-processor.

Reads surface temperature from a SAMD-connected probe through serial JSON commands.

Variables:
  • configuration – List of sensor config dicts from the Gateway.

  • v_surface – Nested list holding surface temperature readings.

  • surface_port – OzLan serial port instance for SAMD communication.

configuration: ClassVar[dict] = {}
v_surface: ClassVar[list[list[int]]] = []
surface_port: OzLan | None = None
__init__()[source]

Initialise the OzSurface wrapper with default state.

Return type:

None

initialize(config, init_value)[source]

Initialise all surface temperature sensors from the Gateway config.

Parameters:
  • config (dict) – List of sensor configuration dicts from the Gateway.

  • init_value (dict) – Mutable dict updated with per-sensor init status.

Return type:

bool

Returns:

True (always returns True for SAMD-based sensors).

initializeSensor(sensor)[source]

Initialise a single surface temperature sensor by part number.

Opens the serial connection to the SAMD and takes an initial reading.

Parameters:

sensor (dict) – Single sensor configuration dict containing part number, enable flag, and GPIO/UART settings.

Return type:

int

Returns:

1 if the SAMD reports the sensor is alive, 0 or -1 otherwise.

initializeSurface(sensor)[source]

Open the serial connection to the SAMD and verify sensor liveness.

Sends a configuration command followed by a liveness check.

Parameters:

sensor (dict) – Sensor config dict with GPIO/UART port and baud settings.

Return type:

int

Returns:

1 if the SAMD reports the surface sensor is alive, 0 otherwise.

getSensorReading()[source]

Trigger a surface temperature reading from all initialised sensors.

Return type:

None

putSensorValue(value)[source]

Read final surface temperature values and populate the output dict.

Parameters:

value (dict) – Mutable output dict to populate with readings.

Return type:

dict

Returns:

The updated output dict.

getSurfaceSensorReading(partNo, flag=False)[source]

Conditionally read surface temperature data from the SAMD.

Parameters:
  • partNo (int) – Hardware part number identifying the sensor model.

  • flag (bool) – If True, perform the actual read; otherwise return 0.

Return type:

int

Returns:

Surface temperature data list when flag is True, 0 otherwise.

getSurface(partNo)[source]

Read surface temperature from the SAMD co-processor.

Parameters:

partNo (int) – Hardware part number (411=surface temperature probe).

Return type:

list[int]

Returns:

List containing the surface temperature value.

Light & Noise

OzUVLight – UV Light

UV light, visible light, IR, and solar radiation sensor wrapper.

Abstracts over multiple light sensor drivers – TSL2591, VEML6070, Si1133, Si1147, LTR390, and RikaPyro – providing a unified interface for lux, UV index, visible light, infrared, and solar irradiance readings through the GenericSensor contract.

class OzWrapper.OzUVLight.OzUVLight.OzUVLight[source]

Bases: GenericSensor

Wrapper for UV, visible light, IR, and solar radiation sensors.

Manages initialisation, periodic reading, and value aggregation for multiple light sensor ICs. The specific driver instantiated depends on the part number in the Gateway configuration.

Variables:
  • configuration – List of sensor config dicts from the Gateway.

  • v_uvlight – Nested list holding accumulated readings per sensor/parameter.

  • light – TSL2591 visible-light driver instance.

  • uv – VEML6070 UVA driver instance.

  • uv_si1133 – Si1133 UV driver instance.

  • uv_si1147 – Si1147 multi-spectrum driver instance.

  • uv_ltr390 – LTR390 UV/ambient-light driver instance.

  • rika_pyro – RikaPyro solar pyranometer driver instance.

  • light_full – Cached full-spectrum reading from TSL2591.

configuration: ClassVar[dict] = {}
v_uvlight: ClassVar[list] = []
light = None
uv = None
uv_si1133 = None
uv_si1147 = None
uv_ltr390 = None
rika_pyro = None
light_full = None
__init__()[source]

Initialise the OzUVLight wrapper with default state.

Return type:

None

initialize(config, init_value)[source]

Initialise all UV/light sensors listed in the Gateway config.

Parameters:
  • config (dict) – List of sensor configuration dicts from the Gateway.

  • init_value (dict) – Mutable dict updated with per-sensor init status.

Return type:

bool

Returns:

True if at least one sensor initialised successfully.

initializeSensor(sensor)[source]

Initialise a single UV/light sensor by part number.

Creates the appropriate hardware driver, configures gain/timing, takes initial readings with retries, and stores bootstrap values in v_uvlight.

Parameters:

sensor (dict) – Single sensor configuration dict containing part number, enable flag, GPIO/I2C settings, and parameter list.

Return type:

int

Returns:

1 if the sensor was initialised successfully, 0 otherwise.

getSensorReading()[source]

Read current values from all initialised UV/light sensors.

Applies sensitivity and correction offsets, accumulates values for later averaging, and returns real-time data keyed by short-code.

Return type:

dict

Returns:

Dict mapping parameter short-codes to their latest readings.

putSensorValue(value)[source]

Flush accumulated UV/light readings into the output dict and reset.

Parameters:

value (dict) – Mutable output dict to populate with aggregated readings.

Return type:

dict

Returns:

The updated output dict.

putInitvalues(value)[source]

Record each sensor’s init status into the shared init-value dict.

Parameters:

value (dict) – Mutable dict updated in-place with a "uvlight" key.

Return type:

dict

Returns:

The updated init-value dict.

getUVLight(partNo, pm)[source]

Dispatch a UV/light reading to the appropriate sub-method.

Routes to getLight for TSL2591 (part 32), rika_pyro for pyranometer (part 37), or getUV for all other UV/light sensors.

Parameters:
  • partNo (int) – Hardware part number identifying the sensor model.

  • pm (int) – Parameter identifier selecting the measurement type.

Return type:

float

Returns:

The measured value as a float.

getLight(partNo, pm)[source]

Read visible-light data from the TSL2591 sensor.

Parameters:
  • partNo (int) – Hardware part number (32=TSL2591).

  • pm (int) – Parameter identifier (1=lux, 2=UV-equivalent, 3=IR).

Return type:

float

Returns:

The measured value as a float, or 0.0 on error.

getUV(partNo, pm)[source]

Read UV or multi-spectrum data from UV sensor ICs.

Supports VEML6070, Si1133, Si1147, and LTR390.

Parameters:
  • partNo (int) – Hardware part number identifying the sensor model.

  • pm (int) – Parameter identifier (varies by sensor: UV index, visible, IR, lux, UVS, etc.).

Return type:

float

Returns:

The measured value as a float, or 0.0 on error.

OzVisible – Visible Light

Visible light sensor wrapper.

Communicates with a SAMD-based co-processor over UART (via the OzLan driver) to read ambient visible-light intensity measurements through the GenericSensor contract.

class OzWrapper.OzVisible.OzVisible.OzVisible[source]

Bases: GenericSensor

Wrapper for visible-light sensors via a SAMD co-processor.

Reads ambient visible-light intensity from a SAMD-connected sensor through serial JSON commands.

Variables:
  • configuration – List of sensor config dicts from the Gateway.

  • v_visible – Nested list holding visible-light readings.

  • visible_port – OzLan serial port instance for SAMD communication.

configuration: ClassVar[dict] = {}
v_visible: ClassVar[list] = []
visible_port: ClassVar[OzLan] = None
__init__()[source]

Initialise the OzVisible wrapper with default state.

Return type:

None

initialize(config, init_value)[source]

Initialise all visible-light sensors listed in the Gateway config.

Parameters:
  • config (dict) – List of sensor configuration dicts from the Gateway.

  • init_value (dict) – Mutable dict updated with per-sensor init status.

Return type:

bool

Returns:

True (always returns True for SAMD-based sensors).

initializeSensor(sensor)[source]

Initialise a single visible-light sensor by part number.

Opens the serial connection to the SAMD and takes an initial reading.

Parameters:

sensor (dict) – Single sensor configuration dict containing part number, enable flag, and GPIO/UART settings.

Return type:

int

Returns:

1 if the SAMD reports the sensor is alive, 0 or -1 otherwise.

initializeVisible(sensor)[source]

Open the serial connection to the SAMD and verify sensor liveness.

Parameters:

sensor (dict) – Sensor config dict with GPIO/UART port and baud settings.

Return type:

int

Returns:

1 if the SAMD reports the visible sensor is alive, 0 otherwise.

getSensorReading()[source]

Trigger a visible-light reading from all initialised sensors.

Return type:

None

putSensorValue(value)[source]

Read final visible-light values and populate the output dict.

Parameters:

value (dict) – Mutable output dict to populate with readings.

Return type:

dict

Returns:

The updated output dict.

getVisibleSensorReading(partNo, flag=False)[source]

Conditionally read visible-light data from the SAMD.

Parameters:
  • partNo (int) – Hardware part number identifying the sensor model.

  • flag (bool) – If True, perform the actual read; otherwise return 0.

Return type:

int

Returns:

Visible-light value when flag is True, 0 otherwise.

getVisible(partNo)[source]

Read visible-light intensity from the SAMD co-processor.

Parameters:

partNo (int) – Hardware part number (311=visible-light sensor).

Return type:

int

Returns:

Visible-light intensity value, or 0 on error.

OzNoise – Noise Level

Noise level sensor wrapper.

Communicates with a SAMD-based co-processor over UART (via the OzLan driver) to read ambient noise-level measurements (average, max, min dB) through the GenericSensor contract.

class OzWrapper.OzNoise.OzNoise.OzNoise[source]

Bases: GenericSensor

Wrapper for noise-level sensors via a SAMD co-processor.

Reads average, maximum, and minimum noise levels (dB) from a SAMD-connected microphone sensor through serial JSON commands.

Variables:
  • configuration – List of sensor config dicts from the Gateway.

  • v_noise – Nested list holding noise reading arrays per sensor.

  • noise_port – OzLan serial port instance for SAMD communication.

  • debug – Whether debug mode is active for raw SAMD readings.

configuration: ClassVar[dict] = {}
v_noise: ClassVar[list[list[int]]] = []
noise_port: OzLan | None = None
debug: bool = False
__init__()[source]

Initialise the OzNoise wrapper with default state.

Return type:

None

initialize(config, init_value)[source]

Initialise all noise sensors listed in the Gateway config.

Parameters:
  • config (dict) – List of sensor configuration dicts from the Gateway.

  • init_value (dict) – Mutable dict updated with per-sensor init status.

Return type:

bool

Returns:

True (always returns True for SAMD-based sensors).

initializeSensor(sensor)[source]

Initialise a single noise sensor by part number.

Opens the serial connection to the SAMD, sends the noise configuration, and takes an initial reading.

Parameters:

sensor (dict) – Single sensor configuration dict containing part number, enable flag, and GPIO/UART settings.

Return type:

int

Returns:

1 if the SAMD reports the sensor is alive, 0 otherwise.

initializeNoise(sensor)[source]

Open the serial connection to the SAMD and verify sensor liveness.

Sends a noise configuration command followed by a liveness check.

Parameters:

sensor (dict) – Sensor config dict with GPIO/UART port, baud, and optional debug settings.

Return type:

int

Returns:

1 if the SAMD reports the noise sensor is alive, 0 otherwise.

getSensorReading()[source]

Trigger a noise reading from all initialised sensors.

This method does not return data directly; values are collected in putSensorValue.

Return type:

None

putSensorValue(value)[source]

Read final noise values and populate the output dict.

Parameters:

value (dict) – Mutable output dict to populate with noise readings.

Return type:

dict

Returns:

The updated output dict.

getNoise(partNo)[source]

Read noise levels (avg, max, min) from the SAMD co-processor.

Parameters:

partNo (int) – Hardware part number (41=noise sensor).

Return type:

list[int]

Returns:

List of [average, max, min] noise levels in dB.

getNoiseSensorReading(partNo, flag=False)[source]

Conditionally read noise data from the SAMD.

Parameters:
  • partNo (int) – Hardware part number identifying the sensor model.

  • flag (bool) – If True, perform the actual read; otherwise return zeroes.

Return type:

list[int]

Returns:

List of [average, max, min] noise levels when flag is True, [0, 0, 0] otherwise.

OzLightning – Lightning Detection

Lightning detection sensor wrapper.

Abstracts over the AS3935 lightning detector IC (via I2C) to provide a unified interface for lightning strike count, estimated distance, and disturber count readings through the GenericSensor contract.

class OzWrapper.OzLightning.OzLightning.OzLightning[source]

Bases: GenericSensor

Wrapper for the AS3935 lightning detection sensor.

Manages initialisation, periodic reading, and value aggregation for lightning strike count, estimated distance, and disturber detection.

Variables:
  • uv_as3935 – AS3935 I2C driver instance, or None if not configured.

  • configuration – List of sensor config dicts from the Gateway.

  • v_uvlight – Nested list holding accumulated readings per sensor/parameter.

uv_as3935 = None
__init__()[source]

Initialise the OzLightning wrapper with default state.

Return type:

None

initialize(config, init_value)[source]

Initialise all lightning sensors listed in the Gateway config.

Parameters:
  • config (dict) – List of sensor configuration dicts from the Gateway.

  • init_value (dict) – Mutable dict updated with per-sensor init status.

Return type:

bool

Returns:

True if at least one sensor initialised successfully.

initializeSensor(sensor)[source]

Initialise a single lightning sensor by part number.

Creates the AS3935 I2C driver, takes initial readings with retries, and stores bootstrap values in v_uvlight.

Parameters:

sensor (dict) – Single sensor configuration dict containing part number, enable flag, and parameter list.

Return type:

int

Returns:

1 if the sensor was initialised successfully, 0 otherwise.

getSensorReading()[source]

Read current lightning data from all initialised sensors.

Applies sensitivity and correction offsets, accumulates values for later averaging, and returns real-time data keyed by short-code.

Return type:

dict

Returns:

Dict mapping parameter short-codes to their latest readings.

putSensorValue(value)[source]

Flush the last accumulated lightning readings and clear counters.

Clears the AS3935 strike/disturber counters after flushing.

Parameters:

value (dict) – Mutable output dict to populate with the latest readings.

Return type:

dict

Returns:

The updated output dict.

putInitvalues(value)[source]

Record each sensor’s init status into the shared init-value dict.

Parameters:

value (dict) – Mutable dict updated in-place with a "lightning" key.

Return type:

dict

Returns:

The updated init-value dict.

clearData()[source]

Reset the AS3935 strike count, disturber count, and distance list.

Return type:

None

getLightning(partNo, pm)[source]

Dispatch a lightning reading to the appropriate sub-method.

Parameters:
  • partNo (int) – Hardware part number identifying the sensor model.

  • pm (int) – Parameter identifier (1=strike count, 2=distance, 3=disturbers).

Return type:

int | float

Returns:

The measured value, or 0.0 if unsupported.

getLightningDistance(partNo, pm)[source]

Read lightning data from the AS3935 sensor.

Parameters:
  • partNo (int) – Hardware part number (39=AS3935).

  • pm (int) – Parameter identifier (1=strike count, 2=distance km, 3=disturber count).

Return type:

int | float

Returns:

The measured value, or 0.0 on error.

System & Infrastructure

OzSystem – System Monitoring

System monitoring wrapper for CPU temperature, disk usage, and GSM modem status.

Provides access to host-level diagnostics (CPU thermal readings, storage metrics) and cellular modem information (signal strength, SIM details) through the GenericSensor interface.

class OzWrapper.OzSystem.OzSystem.OzSystem[source]

Bases: GenericSensor

Wrapper for system-level monitoring: CPU, storage, and GSM modem.

Reads CPU temperature (enabling/disabling the cooling fan as needed), disk usage statistics, and cellular modem signal quality.

Variables:
  • gsmModem – QuectelModem instance for cellular communication, or None.

  • MCP – MCP230XX GPIO expander used for fan control, or None.

  • CPU_TEMP_THRESHOLD – Temperature in Celsius above which the CPU fan activates.

  • CPU_FAN – GPIO pin number for the CPU cooling fan.

  • mcp_flag – Whether the MCP GPIO expander is available.

  • modem_port – Serial port path for the Quectel modem.

  • modem_baud – Baud rate for the modem serial connection.

  • device_space_cmd – Shell command used to query disk space.

  • configuration – Sensor configuration list from the Gateway.

  • v_system – Accumulated system reading values per sensor/parameter.

gsmModem = None
MCP = None
CPU_TEMP_THRESHOLD = 35
CPU_FAN = 6
mcp_flag = True
modem_port = '/dev/ttyUSB2'
modem_baud = 115200
device_space_cmd = 'df ~ -hP'
__init__()[source]

Initialize OzSystem with empty configuration and value storage.

Return type:

None

initialize(config, init_value, mcpFlag)[source]

Initialize system sensors (CPU stats and/or GSM modem).

Parameters:
  • config (dict) – List of sensor configuration dicts from the Gateway.

  • init_value (dict) – Dict to populate with initialization results.

  • mcpFlag (bool) – Whether the MCP GPIO expander is present on this board.

Return type:

bool

Returns:

True if all configured sensors initialized successfully, False otherwise.

initializeSensor(sensor)[source]

Initialize a single system sensor (CPU stats or GSM modem).

Parameters:

sensor (dict) – Configuration dict containing part number, enable flag, and parameters.

Return type:

int

Returns:

1 if the sensor initialized successfully, 0 otherwise.

getSystemStat(partNo, pm)[source]

Dispatch a system stat request to the appropriate handler.

Parameters:
  • partNo (int) – Part number identifying the subsystem (10 = CPU/disk, 11 = modem).

  • pm (int) – Parameter ID within the subsystem.

Return type:

float | int | None

Returns:

The requested metric value, or None if the part number is unrecognized.

getSystemInfo(pm)[source]

Read a host system metric and manage the CPU cooling fan.

Parameters:

pm (int) – Parameter ID (1 = CPU temp, 2 = disk used %, 3 = disk used GB, 4 = disk available GB).

Return type:

float | int | None

Returns:

The requested metric value, or None if the parameter is unrecognized.

getModemInfo(pm)[source]

Read a GSM modem metric.

Parameters:

pm (int) – Parameter ID (1 = signal strength).

Return type:

int | None

Returns:

The modem metric value, or None if the parameter is unrecognized.

getSensorReading()[source]

Collect a single round of system sensor readings.

Return type:

dict

Returns:

Dict mapping send-codes to their current values.

putSensorValue(value)[source]

Aggregate accumulated readings and merge them into the output payload.

Parameters:

value (dict) – Shared output dict to populate with averaged system metrics.

Return type:

dict

Returns:

The updated output dict with system metrics added.

getSimDetails()[source]

Query the GSM modem for SIM card and network details.

Return type:

Union[dict, Literal[0]]

Returns:

Dict with keys ‘csq’, ‘cgreg’, ‘cereg’, ‘iccid’, ‘imei’, ‘module’ on success, or 0 on failure.

putInitvalues(value)[source]

Add SIM initialization details to the init payload.

Parameters:

value (<module ‘json’ from ‘/opt/buildhome/.asdf/installs/python/3.12.12/lib/python3.12/json/__init__.py’>) – Shared init payload dict.

Return type:

<module ‘json’ from ‘/opt/buildhome/.asdf/installs/python/3.12.12/lib/python3.12/json/__init__.py’>

Returns:

The updated init payload with a ‘sim’ key containing SIM details.

execute_os_command(command)[source]

Execute a shell command and return its stdout output.

Parameters:

command (str) – The shell command string to execute.

Return type:

str

Returns:

Decoded stdout output of the command.

OzBattery – Battery Management

Battery and fuel gauge monitoring wrapper.

Reads voltage, current, and state-of-charge from the MAX17261 fuel gauge IC over I2C, providing battery health telemetry for solar-powered deployments.

class OzWrapper.OzBattery.OzBattery.OzBattery[source]

Bases: GenericSensor

Wrapper for MAX17261 fuel gauge battery monitoring.

Reads instantaneous voltage, current, and state-of-charge from the MAX17261 IC and accumulates time-series values for averaging.

Variables:
  • configuration (dict) – Sensor configuration list from the Gateway.

  • v_battery (list) – Nested list of per-sensor, per-parameter accumulated values.

  • battery – MAX17261 driver instance, or None before initialization.

  • debug (bool) – Whether debug logging is enabled for this sensor.

  • res (float) – Sense resistor value in ohms for current measurement.

  • resFlag – Whether a custom sense resistor value was provided.

__init__()[source]

Initialize OzBattery with default configuration and empty accumulators.

Return type:

None

initialize(config, init_value)[source]

Initialize the battery fuel gauge sensor from Gateway configuration.

Parameters:
  • config (<module ‘json’ from ‘/opt/buildhome/.asdf/installs/python/3.12.12/lib/python3.12/json/__init__.py’>) – List of sensor configuration dicts from the Gateway.

  • init_value (dict) – Dict to populate with initialization status flags.

Return type:

bool

Returns:

True if at least one battery sensor initialized successfully.

initializeSensor(sensor)[source]

Initialize a single MAX17261 fuel gauge and take initial readings.

Parameters:

sensor (dict) – Configuration dict with part number, capacity, and parameters.

Return type:

int

Returns:

1 on success, -1 on failure.

getBattery(partNo, pm)[source]

Read a single battery metric from the MAX17261 fuel gauge.

Parameters:
  • partNo (int) – Part number identifying the fuel gauge model.

  • pm (int) – Parameter ID (1 = voltage, 2 = current, 3 = state-of-charge).

Return type:

float | int

Returns:

The battery metric value, or 0.0 if the part number is unsupported.

getSensorReading()[source]

Read current battery values and accumulate them for averaging.

Return type:

dict

Returns:

Dict mapping send-codes to their latest calibrated values.

putSensorValue(value)[source]

Transfer accumulated battery readings into the output payload and reset.

Parameters:

value (dict) – Shared output dict to populate with battery time-series data.

Return type:

dict

Returns:

The updated output dict with battery data added.

putInitvalues(value)[source]

Add battery sensor initialization flags to the init payload.

Parameters:

value (dict) – Shared init payload dict.

Return type:

dict

Returns:

The updated init payload with a ‘battery’ key listing init statuses.

OzError – Error Tracking

Sensor data filtering and aggregation wrapper.

Provides a configurable pipeline of range, delta, statistical, and low-pass filters followed by aggregation functions (average, energy-average, vector wind) to clean raw sensor time-series before publication.

class OzWrapper.OzError.OzError.OzError[source]

Bases: object

Sensor data quality filter and aggregation engine.

Applies a configurable chain of filters (range, delta, statistical, low-pass) to raw sensor readings, then aggregates the cleaned values using parameter-specific strategies (arithmetic mean, energy dB average, vector wind, latest GPS, min/max).

Variables:
  • DEBUG – Class-level debug flag.

  • counter – Warm-up countdown; filters are bypassed until this reaches 0.

  • publish_interval – Seconds between publish cycles (used for warm-up display).

  • debug_mode – Instance-level verbose logging toggle.

  • low_pass_cache_values (dict) – Per-key cache for the exponential moving average filter.

  • cache_filtered_values (dict) – Per-key cache of the most recent filtered series.

  • old_values (dict) – Per-key cache of the last aggregated value (fallback on empty series).

  • filter_length (int) – Number of samples required before low-pass filtering activates.

DEBUG = False
__init__()[source]

Initialize OzError with default filter config for all known parameters.

Return type:

None

putSensorValue(values, calibration=False)[source]

Filter and aggregate raw sensor value lists into scalar outputs.

Parameters:
  • values (dict[str, list] | dict[str, list[list]]) – Dict mapping send-codes to raw value lists (or nested [values, timestamps] pairs).

  • calibration (bool) – If True, skip filtering and use simple averaging.

Return type:

dict

Returns:

The updated dict with each key replaced by its aggregated scalar value, plus optional confidence keys (<key>_cf) when outliers were removed.

setConfig(config)[source]

Merge external filter configuration into the error config.

Parameters:

config (dict) – Dict with parameter filter overrides and optional ‘length’ and ‘debug’ keys.

Return type:

None

sensor_filter(key, values)[source]

Run the configured filter pipeline for a given sensor key.

Parameters:
  • key (str) – Sensor send-code identifying the parameter.

  • values (list) – Raw numeric values to filter.

Return type:

tuple[int, list]

Returns:

Tuple of (total_removed_count, filtered_values).

aggregate_value(key)[source]

Run the configured aggregation pipeline for a given sensor key.

Parameters:

key (str) – Sensor send-code identifying the parameter.

Return type:

float

Returns:

The final aggregated scalar value.

range_filter(key, values)[source]

Remove values outside the configured min/max range for a parameter.

Parameters:
  • key (str) – Sensor send-code for config lookup.

  • values (list) – Numeric values to filter.

Return type:

tuple[int, list]

Returns:

Tuple of (removed_count, values_within_range).

delta_filter(key, values)[source]

Remove spike values that exceed the configured delta from the previous reading.

Parameters:
  • key (str) – Sensor send-code for config lookup.

  • values (list) – Numeric values to filter.

Return type:

tuple[int, list]

Returns:

Tuple of (removed_count, spike-free_values).

statistical_filter(key, values)[source]

Remove outliers beyond a configurable number of standard deviations.

Parameters:
  • key (str) – Sensor send-code for config lookup.

  • values (list) – Numeric values to filter.

Return type:

tuple[int, list]

Returns:

Tuple of (removed_count, values_within_statistical_bounds).

low_pass_filter(key, values, alpha=0.15)[source]

Apply exponential moving average (low-pass) filter to smooth sensor readings. Reduces high-frequency noise while preserving signal trends.

Formula: filtered[n] = α × input[n] + (1 - α) × filtered[n-1]

Parameters:
  • key (str) – Sensor key for cache lookup

  • values (list) – List of sensor values to filter

  • alpha (float) – Smoothing factor (0 < α ≤ 1). Lower = more smoothing Default 0.15 provides good noise reduction

Returns:

(remove_count, filtered_values)
  • remove_count: Always 0 (low-pass doesn’t remove values)

  • filtered_values: Smoothed values

Return type:

tuple[int, list]

Note

Requires accumulating filter_length values before filtering begins. During accumulation, returns original values unchanged.

average(key)[source]

Compute arithmetic mean of the cached filtered values for a key.

Parameters:

key (str) – Sensor send-code to look up in the filtered cache.

Return type:

float

Returns:

Rounded average, or 0.0 if the series is empty.

min_value(key)[source]

Return the minimum of the cached filtered values for a key.

Parameters:

key (str) – Sensor send-code to look up in the filtered cache.

Return type:

float

Returns:

Rounded minimum, or 0.0 if the series is empty.

max_value(key)[source]

Return the maximum of the cached filtered values for a key.

Parameters:

key (str) – Sensor send-code to look up in the filtered cache.

Return type:

float

Returns:

Rounded maximum, or 0.0 if the series is empty.

energy_average(key)[source]

Compute acoustically correct energy average for decibel values.

Uses the formula: 10 * log10(mean(10^(dB/10))) with numerical stability via max-value subtraction.

Parameters:

key (str) – Sensor send-code to look up in the filtered cache.

Return type:

float

Returns:

Energy-averaged dB value, or arithmetic mean as fallback.

vector_direction(key)[source]

Compute vector-averaged direction from directional data and related magnitudes.

Uses U/V component decomposition for proper circular averaging of wind direction paired with wind speed magnitudes.

Parameters:

key (str) – Sensor send-code for the directional parameter (e.g., ‘wd’).

Return type:

float

Returns:

Vector-averaged direction in degrees [0, 360), or 0.0 if empty.

latest_value(key)[source]

Return the most recent value from the filtered cache (used for GPS coordinates).

Parameters:

key (str) – Sensor send-code to look up in the filtered cache.

Return type:

float

Returns:

The last value in the series, or 0.0 if empty.

vector_magnitude(key)[source]

Compute vector-averaged magnitude from speed and related direction data.

Uses U/V component decomposition to compute the resultant wind speed magnitude from paired speed and direction series.

Parameters:

key (str) – Sensor send-code for the magnitude parameter (e.g., ‘ws’).

Return type:

float

Returns:

Vector-averaged magnitude, or 0.0 if empty.

OzGPS – GPS Location

GPS location wrapper for Quectel modem GNSS receivers.

Reads latitude, longitude, and satellite count from a Quectel modem’s GPS subsystem, and optionally synchronizes the device RTC with GPS time.

class OzWrapper.OzGPS.OzGPS.OzGPSParam[source]

Bases: object

Container for a single GPS module’s configuration and driver reference.

Variables:
  • partNo – Part number identifying the GPS module type.

  • configuration_port – Serial port for modem AT commands.

  • gps_port – Serial port for NMEA GPS data.

  • baud – Baud rate for the GPS serial connection.

  • gps_driver – QuectelGPS driver instance, or None before initialization.

  • old_data – Cache of previous GPS readings for fallback.

Parameters:
  • partNo (int)

  • gps_port (str)

  • configuration_port (str)

  • baud (int)

gps_driver = None
__init__(partNo, gps_port, configuration_port, baud)[source]

Initialize GPS parameter container.

Parameters:
  • partNo (int) – Part number for this GPS module.

  • gps_port (str) – Serial port path for NMEA data.

  • configuration_port (str) – Serial port path for AT commands.

  • baud (int) – Baud rate for GPS serial communication.

Return type:

None

partNo = 0
gps_port = '/dev/ttyUSB1'
configuration_port = '/dev/ttyUSB2'
baud = 115200
setDriver(gps_driver)[source]

Assign the QuectelGPS driver instance.

Parameters:

gps_driver (Gps) – Initialized QuectelGPS driver object.

Return type:

None

class OzWrapper.OzGPS.OzGPS.OzGPS[source]

Bases: object

GPS location wrapper managing Quectel GNSS modules.

Reads latitude, longitude, and satellite count from GPS NMEA data, accumulates time-series values, and optionally syncs the hardware RTC.

Variables:
  • gps_poll – Whether to actively poll GPS on each reading cycle.

  • lat – Last known latitude in decimal degrees.

  • lon – Last known longitude in decimal degrees.

  • put_sensor – Whether GPS data should be included in published payloads.

  • xone – xOne assisted-GPS enable flag.

  • xpath – URL path for xTRA ephemeris data download.

  • xname – Filename of the xTRA ephemeris binary.

  • v_gps – Accumulated GPS reading values per sensor/parameter.

  • configuration – GPS sensor configuration list from the Gateway.

  • s_gps – List of OzGPSParam instances (one per configured GPS module).

gps_poll = True
lat = 0.0
lon = 0.0
put_sensor = 0
xone = 0
xpath = 'http://xtrapath6.izatcloud.net/'
xname = 'xtra3grc.bin'
v_gps: ClassVar[list] = []
__init__()[source]

Initialize OzGPS with empty configuration and sensor lists.

Return type:

None

initialize(config)[source]

Initialize all configured GPS modules.

Parameters:

config (dict) – List of GPS sensor configuration dicts from the Gateway.

Return type:

bool

Returns:

True if initialization succeeded, False on error.

initializeSensor(sensor)[source]

Initialize a single GPS module and take an initial reading.

Parameters:

sensor (dict) – Configuration dict with part number, port settings, and parameters.

Return type:

int

Returns:

1 on success, 0 on failure or if the sensor is disabled.

getSensorReading()[source]

Poll all GPS modules and accumulate lat/lon/satellite readings.

Return type:

dict

Returns:

Dict mapping send-codes to their latest GPS values.

putSensorValue(value)[source]

Transfer accumulated GPS readings into the output payload and reset.

Parameters:

value (dict) – Shared output dict to populate with GPS time-series data.

Return type:

dict

Returns:

The updated output dict with GPS data added.

putInitvalues(value)[source]

Add GPS location to the init payload and sync the RTC from GPS time.

Parameters:

value (dict) – Shared init payload dict to update with location coordinates.

Return type:

None

poll_loc()[source]

Check whether a valid GPS fix has been obtained.

Return type:

bool

Returns:

True if a non-zero latitude is available, False otherwise.

monitor_gps_datetime()[source]

Compare GPS time with the hardware RTC and update RTC if drift exceeds 10 seconds.

Return type:

None

OzRGB – LED Indicator

RGB LED indicator wrapper for NeoPixel status display.

Drives a NeoPixel LED strip to indicate device status (network connectivity, data sending, errors) through color and blink/fade patterns, and optionally shows AQI-based beacon colors on remaining LEDs.

OzWrapper.OzRGB.OzRGB.hex_to_rgb(hex_code)[source]

Convert a 6-character hex color code to an (R, G, B) tuple.

Parameters:

hex_code (str) – Six-character hex string (e.g., ‘50f0e6’), without ‘#’ prefix.

Return type:

tuple

Returns:

Tuple of (red, green, blue) integers in the range 0-255.

OzWrapper.OzRGB.OzRGB.get_color_from_value(value)[source]

Look up the beacon hex color for a given AQI value.

Parameters:

value (int) – AQI (or other index) value to classify.

Return type:

str | None

Returns:

Hex color string from the beacon config, or None if below all ranges.

class OzWrapper.OzRGB.OzRGB.Magic[source]

Bases: object

LED animation engine providing fade and blink patterns for NeoPixel strips.

Variables:
  • brightness – Current brightness level (0.0 to 1.0).

  • min_bright – Minimum brightness counter value for fade animations.

  • max_bright – Maximum brightness counter value for fade animations.

  • bright_divider – Divisor to convert counter to NeoPixel brightness (0.0-1.0).

  • fadInDelay – Milliseconds between brightness increments during fade-in.

  • fadeOutWait – Milliseconds between brightness decrements during fade-out.

  • pixels – NeoPixel strip instance being controlled.

  • RISING – Direction constant for increasing brightness.

  • FALLING – Direction constant for decreasing brightness.

  • blink_delay – Milliseconds between blink toggles.

  • blink_direction – Current blink phase (RISING or FALLING).

Parameters:

pixels (NeoPixel)

brightness = 0
min_bright = 1
max_bright = 100
bright_divider = 100
fadInDelay = 20
fadeOutWait = 20
counter_brightness = 0
RISING = 1
FALLING = -1
prev_blinking = 0
__init__(pixels)[source]

Initialize the animation engine with a NeoPixel strip.

Parameters:

pixels (NeoPixel) – NeoPixel strip instance to control.

Return type:

None

pixels = None
setFadeProperty(brightness=0, min_bright=1, max_bright=100, bright_divider=100, fadInDelay=20, fadeOutWait=10)[source]

Configure fade animation properties.

Parameters:
  • brightness (int) – Initial brightness counter value.

  • min_bright (int) – Minimum brightness counter for fade range.

  • max_bright (int) – Maximum brightness counter for fade range.

  • bright_divider (int) – Divisor to convert counter to NeoPixel brightness.

  • fadInDelay (int) – Milliseconds between fade-in steps.

  • fadeOutWait (int) – Milliseconds between fade-out steps.

Return type:

None

fade()[source]

Advance the fade animation by one step (non-blocking).

Return type:

None

blinking(blink_delay=60)[source]

Advance the blink animation by one step (non-blocking).

Parameters:

blink_delay (int) – Milliseconds between on/off toggles.

Return type:

None

micros()[source]

Return the current time in microseconds.

Return type:

int

millis()[source]

Return the current time in milliseconds.

Return type:

int

OzWrapper.OzRGB.OzRGB.main(os_network_alert_file, network_status=None, beacon_queue=None)[source]

Run the RGB LED main loop, updating status and beacon colors continuously.

Parameters:
  • os_network_alert_file (None) – Unused (legacy network alert file path).

  • network_status (Queue | None) – Queue providing integer network status codes for LED color.

  • beacon_queue (Queue | None) – Queue providing AQI data for beacon LED coloring.

Return type:

None

Communication

OzSocket – WebSocket

WebSocket communication wrapper using Socket.IO.

Manages bidirectional real-time communication with the Gateway container, receiving MQTT data and calibration keys, broadcasting sensor payloads to downstream queues (Modbus, HMI, Display), and emitting raw device data.

class OzWrapper.OzSocket.OzSocket.OzSocket[source]

Bases: object

Socket.IO client for real-time data exchange with the Gateway.

Connects to the Gateway WebSocket endpoint, receives MQTT sensor data and calibration commands, fans out payloads to local consumer queues, and emits raw device data back to the server.

Variables:
  • configuration (dict) – Socket configuration dict from the Gateway.

  • web_socket_url (str) – WebSocket endpoint URL.

  • ignoring_keys (list[str]) – Telemetry keys excluded from negative-value clamping.

  • calibration_keys (list[str]) – Keys requiring calibration before processing.

  • sending_queue (list[Queue]) – List of Queues for broadcasting data to downstream consumers.

  • receiving_queue (list[Queue]) – List of Queues for incoming MQTT data.

  • mqtt_send_queue (Queue | None) – Queue for outgoing MQTT data to emit via socket.

  • socket (Client) – Socket.IO client instance with auto-reconnection.

  • need_data_publish (Event) – Threading event controlling data publish gating.

  • debug_mode (bool) – Whether verbose debug logging is enabled.

__init__()[source]

Initialize the socket client, configure default endpoints, and set up key filters.

Variables:
  • socket (socketio.Client) – Socket.IO client configured with reconnection and timeout options.

  • web_socket_url (str) – WebSocket endpoint URL loaded from the WS_URL environment variable or defaulting to http://redis.local:8080.

  • ignoring_keys (list[str]) – Telemetry keys that should be ignored when handling socket messages.

  • calibration_keys (list[str]) – Telemetry keys that require calibration before processing.

  • sending_queue (list[queue.Queue]) – Collection of queues used to broadcast incoming messages across consumers.

Return type:

None

setup(socket_config, sending_queue, receiving_queue, mqtt_send_queue, need_data_publish)[source]

Configure queues, register Socket.IO callbacks, and connect to the server.

Parameters:
  • socket_config (dict) – Configuration dict with socket settings.

  • sending_queue (list[Queue]) – List of Queues to broadcast received data to consumers.

  • receiving_queue (list[Queue]) – List of Queues for incoming MQTT data.

  • mqtt_send_queue (Queue) – Queue for outgoing data to emit via socket.

  • need_data_publish (Event) – Event flag controlling whether data is published.

Return type:

None

loop()[source]

Start a background thread to emit queued data and wait on the socket connection.

Return type:

None

socket_callbacks()[source]

Register all Socket.IO event handlers (connect, disconnect, data listeners).

Return type:

None

run(socket_config, sending_queue, receiving_queue, mqtt_send_queue, need_data_publish)[source]

Entry point: set up the socket and start the event loop if enabled.

Parameters:
  • socket_config (dict) – Configuration dict with ‘en’ enable flag.

  • sending_queue (list[Queue]) – List of Queues for downstream consumers.

  • receiving_queue (list[Queue]) – List of Queues for incoming MQTT data.

  • mqtt_send_queue (Queue) – Queue for outgoing data emission.

  • need_data_publish (Event) – Event flag for data publish gating.

Return type:

None

OzModbus – Modbus

Modbus RTU/TCP server wrapper for exposing sensor data as holding registers.

Maps sensor telemetry keys to Modbus holding register addresses and serves them over RTU (serial) and/or TCP transports using PyModbus, enabling integration with SCADA and PLC systems.

class OzWrapper.OzModbus.OzModbus.OzModbus[source]

Bases: object

Modbus server wrapper mapping sensor keys to holding registers.

Receives sensor payloads from a queue, writes values into a Modbus register context, and serves them via RTU and/or TCP server threads.

Variables:
  • pymodbus – PyModbus driver instance managing the server context.

  • slaveId – Modbus slave/unit ID for this device.

  • modbus_context – Server data context holding register values.

  • holding_register – Function code for holding registers (3).

  • isRealtime – Whether to process only realtime data payloads.

  • payloaddata – Latest sensor payload received from the queue.

  • modbus_keys (dict[str, int]) – Mapping of sensor send-codes to register addresses.

  • can_negative (list[str]) – List of send-codes allowed to have negative values.

pymodbus = None
slaveId = 0
modbus_context = None
holding_register = 3
isRealtime = 0
payloaddata = None
__init__()[source]

Initialize OzModbus with the default register map and negative-value whitelist.

Return type:

None

setup(modbusConfig, modbus_queue)[source]

Configure and start the Modbus RTU and/or TCP server(s).

Parses serial port, baud rate, parity, server mode, host/port, and slave ID from the configuration, builds the register context, and starts server threads.

Parameters:
  • modbusConfig (dict) – Configuration dict with gpio, modconfig, and hostconfig sections.

  • modbus_queue (Queue) – Queue supplying sensor data payloads for register updates.

Return type:

None

loop(modbus_queue)[source]

Continuously read payloads from the queue and update Modbus registers.

Parameters:

modbus_queue (Queue) – Queue supplying sensor data payloads.

Return type:

None

run(modbusConfig, modbus_queue)[source]

Entry point: set up the Modbus server and start the data loop if enabled.

Parameters:
  • modbusConfig (dict) – Configuration dict with ‘en’ enable flag.

  • modbus_queue (Queue) – Queue supplying sensor data payloads.

Return type:

None

OzLora – LoRa Radio

LoRa communication wrapper for transmitting sensor data over LoRaWAN.

Encodes sensor telemetry into binary LoRa payloads and transmits them via Melange, OTTA, or LORA-E5 modules, supporting both ABP and OTAA activation modes with configurable regional settings.

class OzWrapper.OzLora.OzLora.OzLora[source]

Bases: object

LoRaWAN communication wrapper supporting multiple LoRa module types.

Manages LoRaWAN key provisioning, binary payload encoding via struct, dual-buffer transmission, and downlink command processing (including remote reboot).

Variables:
  • module – LoRa driver instance (Melange, OTTA, or LORAE5), or None.

  • appkey – OTAA application key.

  • network_key – ABP network session key.

  • app_session_key – ABP application session key.

  • dev_addr – ABP device address.

  • lora_class – LoRaWAN device class (A, B, or C).

  • lora_mode – Activation mode (ABP or OTAA).

  • lora_region – Regional frequency plan identifier.

  • isRealtime – Whether to transmit only realtime data payloads.

  • modulePart – Module type selector (0 = Melange, 1 = OTTA, 2 = LORA-E5).

  • lora_keys – Primary payload register map (send-code to [offset, byte-length]).

  • lora_keys_2 – Secondary payload register map.

  • lora_buffer – Primary binary transmit buffer.

  • lora_buffer_2 – Secondary binary transmit buffer.

module = None
__init__()[source]

Initialize OzLora with default keys, buffers, and register maps.

Return type:

None

setup(loraConfig)[source]

Configure the LoRa module with keys, port settings, and regional parameters.

Parameters:

loraConfig (dict) – Configuration dict with gpio, keys, class, mode, and region.

Return type:

None

convert(val, points=2)[source]

Pack a sensor value into a binary byte list for LoRa transmission.

Uses struct packing with network byte order. Supports 1-byte unsigned, 2-byte unsigned/signed (x10 scaling), and 4-byte float/unsigned int.

Parameters:
  • val (float) – Sensor value to encode.

  • points (int) – Byte length and format selector (1, 2, 3=signed-2, 4).

Return type:

list[int]

Returns:

List of integer byte values ready for the LoRa buffer.

rebootGSM(gsm_port='/dev/ttyUSB3')[source]

Reboot the GSM modem via AT command and wait for it to come back online.

Parameters:

gsm_port (str) – Serial port path of the GSM modem.

Return type:

None

rebootSystem()[source]

Reboot the entire device by resetting the GSM modem and triggering SAMD watchdog.

Return type:

None

loop(loraqueue)[source]

Continuously read payloads, encode into LoRa buffers, and transmit.

Processes downlink commands (reboot) and re-initializes the module on transmission failure.

Parameters:

loraqueue (Queue) – Queue supplying sensor data payloads.

Return type:

None

run(loraConfig, loraqueue)[source]

Entry point: set up the LoRa module and start the transmit loop if enabled.

Parameters:
  • loraConfig (dict) – Configuration dict with ‘en’ enable flag.

  • loraqueue (Queue) – Queue supplying sensor data payloads.

Return type:

None

OzDisplay – E-Paper Display

E-paper and 7-segment display wrapper for showing sensor readings.

Drives TM1637 (4-digit 7-segment) or TM1638 (8-digit with LEDs) displays to show real-time sensor values with unit indicator LEDs, supporting multi-parameter cycling.

class OzWrapper.OzDisplay.OzDisplay.OzDisplay[source]

Bases: object

Wrapper for TM1637/TM1638 7-segment displays with unit indicator LEDs.

Shows sensor readings on a 7-segment display, cycling through multiple parameters with configurable decimal precision and unit LED indicators.

Variables:
  • display – TM1637Decimal or TM1638 driver instance, or None before setup.

  • payloaddata – Latest sensor payload received from the queue.

  • CLK – GPIO clock pin for the display.

  • DIO – GPIO data pin for the display.

  • STB – GPIO strobe pin for TM1638 displays.

  • MCP – MCP230XX GPIO expander for unit LEDs (TM1637 mode), or None.

  • sTime – Display refresh timeout in seconds.

  • displayParam – Currently displayed parameter send-code.

  • displayUnit – Currently displayed unit string.

  • displayCount – Index into the multi-parameter cycle list.

  • isRealtime – Whether to process only realtime data payloads.

  • parameters (list) – Display parameter configuration list.

  • multiParam (list) – List of send-codes to cycle through on the display.

display = None
payloaddata = None
CLK = 21
DIO = 20
STB = 3
MCP = None
sTime = 10
displayParam = None
displayUnit = None
displayCount = -1
isRealtime = 0
__init__()[source]

Initialize OzDisplay with default pin assignments and unit mappings.

Return type:

None

updateLed()[source]

Update the unit indicator LED based on the currently displayed parameter.

Return type:

None

setup(displayConfig)[source]

Configure the display driver, unit LEDs, and parameter cycling.

Parameters:

displayConfig (dict) – Configuration dict with parameters, refresh time, part number, and realtime flag.

Return type:

None

loop(displayqueue)[source]

Continuously read payloads and update the display with sensor values.

Cycles through configured parameters and formats values with the specified decimal precision.

Parameters:

displayqueue (Queue) – Queue supplying sensor data payloads.

Return type:

None

run(displayConfig, displayqueue)[source]

Entry point: set up the display and start the update loop if enabled.

Parameters:
  • displayConfig (dict) – Configuration dict with ‘en’ enable flag.

  • displayqueue (Queue) – Queue supplying sensor data payloads.

Return type:

None

OzHMI – 7-Segment Display

HMI (Human-Machine Interface) display wrapper for Nextion/UART touch screens.

Drives a Nextion-style UART HMI display to show sensor parameter names, values, and units on multiple pages, along with status icons for WiFi, GSM, GPS, and battery. Also queries the network manager for connectivity details.

class OzWrapper.OzHMI.OzHMI.OzHMI[source]

Bases: object

HMI display wrapper for Nextion-style UART touch screens.

Receives sensor payloads from a queue, maps send-codes to human-readable parameter labels and units, and writes formatted values to the HMI driver. Also manages status icons (WiFi, GSM, GPS, battery) and settings pages.

Variables:
  • hmi – HMI driver instance, or None before setup.

  • deviceId – Device identifier shown on the HMI about page.

  • hmi_port – UART serial port path for the HMI display.

  • hmi_baud – Baud rate for HMI serial communication.

  • timezone – Timezone string for timestamp display.

  • hmi_key_Param – Mapping of send-codes to display parameter labels.

  • hmi_key_Unit – Mapping of send-codes to display unit strings.

  • hmi_key_fc – Mapping of send-codes to conversion factors.

  • isRealtime – Whether to process only realtime data payloads.

  • network – Network instance for internet connectivity checks.

Sample Data frame of Oizom V6 device: {‘d’: {‘temp’: 0, ‘hum’: 0, ‘hum_cf’: 0, ‘g51’: 342.09, ‘g55’: 347.92, ‘g61’: 345.15, ‘g65’: 359.71, ‘g81’: 352.66, ‘g85’: 357.04, ‘g21’: 331.56, ‘g25’: 348.03, ‘s1’: 55.02, ‘leq’: 49.45, ‘lmax’: 60.5, ‘lmin’: 44.8, ‘wd’: 339, ‘ws’: 1.841428518, ‘rain’: 0, ‘t’: 1691524500}, ‘deviceId’: ‘P1950’, ‘deviceType’: ‘POLLUDRON_PRO’} Standard Oizom Key Units: {“g1 “: “ppm”, “g2 “: “mg/m3”, “g3 “: “ug/m3”, “g4 “: “ug/m3”, “g5 “: “ug/m3”, “g6 “: “ug/m3”, “g7 “: “ug/m3”, “g8 “: “ug/m3”, “g9 “: “%”, “v1 “: “ppb”, “v2 “: “ppb”, “v3 “: “ppb”, “v4 “: “ppm”, “v5 “: “ppb”, “v6 “: “ppb”, “p1 “: “ug/m3”, “p2 “: “ug/m3”, “p3 “: “ug/m3”, “p4 “: “ug/m3”, “temp “: “Celsius”, “hum “: “%”, “t “: “Seconds”, “leq “: “dB”, “lmin “: “dB”, “lmax “: “dB”, “rain “: “mm”, “light “: “Lux”, “flood “: “mm”, “uv “: “Index”, “ws “: “m/s”, “wd “: “Degree”, “pr “: “HPa”} Standard Oizom Key Parameters: {“g1” : “CO2”, “g2” : “CO”, “g3” : “NO2”, “g4” : “NH3”, “g5” : “O3”, “g6” : “H2S”, “g7” : “NO”, “g8” : “SO2”, “g9” : “O2”, “v1” : “Cl2”, “v2” : “TVOC”, “v3” : “CH2O”, “v4” : “CH4”, “v5” : “CH3SH”, “v6” : “C2H4”, “p1” : “PM2”, “p2” : “PM10”, “p3” : “PM1”, “p4” : “PM100”, “temp” : “Temperature”, “hum” : “Humidity”, “t” : “TimeStamp”, “leq” : “NoiseAverage”, “lmin” : “MinNoise”, “lmax” : “MaxNoise”, “rain” : “RainFall”, “light” : “VisibleLight”, “flood” : “FloodLevel”, “uv” : “UVIndex”, “ws” : “WindSpeed”, “wd” : “WindDirection”, “pr” : “Pressure”}

fc = 1

CO2 - ppm All Gas - ppb Dust - ug/m3

O2 - %

Temp - deg C Hum - % Pressure - HPa

Wind Speed - m/s Wind Direction - deg Rain - mm

deviceId = 'OZTEST001'
hmi = None
lastCal = '13/08/2023'
version = '1.0'
hmi_port = '/dev/ttyAMA2'
hmi_baud = 115200
timezone = 'Asia/Kolkata'
debug = 0
heatingInterval = 2
lat = '23.456789 N'
lon = '73.456789 N'
once = True
nmOnce = True
url = ''
response = None
payloaddata = None
sTime = 10
displayCount = -1
isRealtime = 0
isInternet = 0
isCharging = 0
currentTime = 0
prevTime = 0
network = None
__init__()[source]

Initialize OzHMI with default settings and empty key mappings.

Return type:

None

setup(hmiConfig)[source]

Configure the HMI display, build key mappings, and initialize status icons.

Parameters:

hmiConfig (dict) – Configuration dict with parameters, gpio, and settings sections.

Return type:

None

loop(hmi_queue)[source]

Continuously read payloads and update the HMI display with sensor data and icons.

Parameters:

hmi_queue (Queue) – Queue supplying sensor data payloads.

Return type:

None

run(hmiConfig, hmi_queue)[source]

Entry point: set up the HMI display and start the update loop if enabled.

Parameters:
  • hmiConfig (dict) – Configuration dict with ‘en’ enable flag.

  • hmi_queue (Queue) – Queue supplying sensor data payloads.

Return type:

None

Calibration & Special

OzOGS – Odor Gas Sensor

Odor/gas sensor (OGS) allocation wrapper for electrochemical and reference analyzers.

Manages a multiplexed array of gas sensors (ADS122U04, Winsen, Cubic, Semeatech, NevadaNano, HORIBA, Serinus) accessed through UART multiplexer GPIO selection, providing unified read/calibrate/publish for NO2, O3, CO, SO2, H2S, NO, and O2.

OzWrapper.OzOGS.OzOGS.context_logger = <utils.oizom_logger.OizomLogger object>

201, sendCode: g3 O3: partNo: 203, sendCode: g5 CO: partNo: 202, sendCode: g2 SO2: partNo: 204, sendCode: g8 H2S: partNo: 205, sendCode: g6 NO: partNo: 206, sendCode: g7

Type:

NO2

Type:

partNo

class OzWrapper.OzOGS.OzOGS.OzOGSParam[source]

Bases: object

Container for a single OGS sensor’s configuration and driver reference.

Variables:
  • partNo – Part number identifying the sensor type (101-109).

  • port – UART serial port path.

  • baud – Baud rate for the serial connection.

  • address – Multiplexer channel address within an IC.

  • ic – Multiplexer IC index (0 or 1).

  • pga – Programmable gain amplifier setting for ADS122U04.

  • ogs_port – Sensor driver instance (ADS122U04, WinsenO2, etc.), or None.

Parameters:
pga = 0
ogs_port = None
__init__(partNo, port, baud, address, ic)[source]

Initialize OGS parameter container.

Parameters:
  • partNo (int) – Part number for this sensor.

  • port (str) – UART serial port path.

  • baud (int) – Baud rate for serial communication.

  • address (int) – Multiplexer channel address.

  • ic (int) – Multiplexer IC index.

Return type:

None

partNo = 0
port = '/dev/ttyAMA0'
baud = 115200
address = -1
ic = -1
setOGS(ogs_port)[source]

Assign the sensor driver instance.

Parameters:

ogs_port (ADS122U04 | WinsenO2 | CubicGeneric | Semeatech | SemeatechA4 | NEVADA | HORIBA | Serinus) – Initialized sensor driver object for this OGS channel.

Return type:

None

class OzWrapper.OzOGS.OzOGS.OzOGS[source]

Bases: GenericSensor

Multiplexed gas sensor wrapper supporting multiple electrochemical and reference analyzers.

Manages a UART multiplexer (2 ICs x 4 channels) to address up to 8 gas sensors, handling initialization, GPIO-based channel selection, reading, calibration-aware averaging, and payload assembly.

Variables:
  • AVERAGE_COUNT – Number of readings to average per cycle.

  • GPIO_A – GPIO pin A for multiplexer address selection.

  • GPIO_B – GPIO pin B for multiplexer address selection.

  • GPIO_ENABLE_1 – GPIO enable pin for multiplexer IC 0.

  • GPIO_ENABLE_2 – GPIO enable pin for multiplexer IC 1.

  • SENSOR_PER_IC – Number of sensor channels per multiplexer IC.

  • configuration – Gas sensor configuration list from the Gateway.

  • v_ogs – Nested list of per-sensor, per-parameter accumulated values.

  • p_ogs – List of OzOGSParam instances (one per configured sensor).

AVERAGE_COUNT = 1
GPIO_A = 24
GPIO_B = 25
GPIO_ENABLE_1 = 27
GPIO_ENABLE_2 = 17
SENSOR_PER_IC = 4
__init__()[source]

Initialize OzOGS with empty configuration and sensor lists.

Return type:

None

updateTempForADS(sensor)[source]

Append an internal temperature parameter to ADS122U04 sensor config if missing.

Parameters:

sensor (dict) – Sensor configuration dict whose parameters list may be extended.

Return type:

None

updateTempHumForSemeatech(sensor)[source]

Append temperature and humidity parameters to Semeatech sensor config if missing.

Parameters:

sensor (dict) – Sensor configuration dict whose parameters list may be extended.

Return type:

None

initialize(config, init_value)[source]

Initialize all configured gas sensors and set up GPIO multiplexer pins.

Parameters:
  • config (dict) – List of OGS sensor configuration dicts from the Gateway.

  • init_value (dict) – Dict to populate with per-sensor initialization flags.

Return type:

bool

Returns:

True if all sensors were iterated without fatal error.

initializeSensor(sensor)[source]

Initialize a single gas sensor based on its part number.

Creates the appropriate driver, selects the multiplexer channel, and takes initial readings for each configured parameter.

Part numbers:

101 = ADS122U04, 102 = Winsen, 103 = Cubic, 104 = Semeatech, 105 = SemeatechA4, 106 = NevadaNano, 107 = HORIBA, 109 = Serinus.

Parameters:

sensor (dict) – Configuration dict with part number, gpio, and parameters.

Return type:

int

Returns:

1 on success, 0 on failure.

findKeyinList(keys, sensor_list)[source]

Check if any sensor parameter send-code matches the provided calibration keys.

Parameters:
  • keys (list) – List of calibration key prefixes to match.

  • sensor_list (dict) – Sensor configuration dict with a ‘parameters’ list.

Return type:

bool

Returns:

True if at least one parameter matches a calibration key.

getSensorReading(calibrationKeys=None)[source]

Read all initialized gas sensors and accumulate values.

Parameters:

calibrationKeys (list[str] | None) – Optional list of send-code prefixes to restrict which sensors are read (empty = read all).

Return type:

dict

Returns:

Dict mapping send-codes to their latest raw or calibrated values.

putSensorValue(value, calibrationKeys=None)[source]

Transfer accumulated gas sensor readings into the output payload and reset.

Parameters:
  • value (dict) – Shared output dict to populate with OGS time-series data.

  • calibrationKeys (list[str] | None) – Optional list of send-code prefixes to restrict output.

Return type:

dict

Returns:

The updated output dict with gas sensor data added.

putInitvalues(value)[source]

Add OGS sensor initialization flags to the init payload.

Parameters:

value (<module ‘json’ from ‘/opt/buildhome/.asdf/installs/python/3.12.12/lib/python3.12/json/__init__.py’>) – Shared init payload dict.

Return type:

<module ‘json’ from ‘/opt/buildhome/.asdf/installs/python/3.12.12/lib/python3.12/json/__init__.py’>

Returns:

The updated init payload with an ‘ogs’ key listing init statuses.

PrintException()[source]

Log the current exception with file name and line number context.

Return type:

None

OzOSP – Outdoor Sensor Package

Oizom Sensor Protocol (OSP) wrapper for Modbus RTU sensor integration.

Reads sensor data from external Modbus RTU slave devices over a shared serial bus, supporting configurable function codes, register addresses, endianness, and multi-register float parsing.

class OzWrapper.OzOSP.OzOSP.OzOSP[source]

Bases: GenericSensor

Modbus RTU client wrapper for reading external sensor slaves.

Creates a shared Modbus RTU serial client and reads holding/input registers from multiple slave devices, applying sensitivity and correction factors to raw register values.

Variables:
  • configuration – OSP sensor configuration dict from the Gateway.

  • client – PyModbus serial client instance, or None before initialization.

  • OSP_data – Dict of accumulated sensor readings keyed by send-code.

  • debug – Whether verbose debug logging is enabled.

__init__()[source]

Initialize OzOSP with empty configuration and data stores.

initialize(config, init_value)[source]

Initialize the Modbus RTU client and probe all configured slave sensors.

Parameters:
  • config (dict) – OSP configuration dict with gpio, sensors, and debug settings.

  • init_value (dict) – Dict to populate with per-sensor initialization flags.

Return type:

bool

Returns:

True if at least one sensor initialized successfully.

initializeSensor(sensor)[source]

Probe a Modbus slave sensor by reading all its configured parameters.

Parameters:

sensor (dict) – Sensor configuration dict with slave_id and parameters.

Return type:

None

Returns:

True if at least one parameter returned a valid reading.

getSensorData(modbus_client, slave_id, config)[source]

Read a single parameter from a Modbus slave register.

Parameters:
  • modbus_client – PyModbus client instance.

  • slave_id – Modbus slave/unit ID.

  • config – Parameter configuration dict with register, fn_code, count, endian, cr (correction), and se (sensitivity).

Returns:

Corrected sensor value as float, or None on error.

getSensorReading(calibrationKeys=[])[source]

Read all configured Modbus slave sensors and accumulate values.

Parameters:

calibrationKeys – Optional list of send-codes to restrict which sensors are read (empty = read all).

Return type:

dict

Returns:

Dict mapping send-codes to their accumulated value lists.

putSensorValue(value, calibrationKeys=[])[source]

Transfer accumulated OSP sensor readings into the output payload.

Parameters:
  • value (dict) – Shared output dict to populate with OSP data.

  • calibrationKeys (list[str] | None) – Optional list of send-codes to restrict output.

Returns:

The updated output dict with OSP sensor data added.

putInitvalues(value)[source]

Add OSP sensor initialization flags to the init payload.

Parameters:

value (dict) – Shared init payload dict.

Return type:

dict

Returns:

The updated init payload with an ‘OSP’ key listing init statuses.

OzAlert – Automation Alerts

Alert and automation wrapper for threshold-based sensor alerts.

Monitors sensor readings against configurable upper/lower thresholds and triggers GPIO outputs (buzzer, light, relay), email/SMS notifications, or MQTT messages when thresholds are breached.

class OzWrapper.OzAlert.OzAlert.OzAlert[source]

Bases: object

Threshold-based alert handler for sensor automation.

Evaluates incoming sensor data against configured thresholds and activates the appropriate output channel (GPIO relay, buzzer/light, email, SMS, or MQTT).

Variables:
  • output1_pin – GPIO pin number for relay output 1.

  • output2_pin – GPIO pin number for relay output 2.

  • buzzer_pin – GPIO pin number for the audible buzzer.

  • light_pin – GPIO pin number for the alert indicator light.

  • minInterval – Minimum polling interval (seconds) across all alerts.

  • alerts (list[dict[str, Any]]) – List of alert configuration dicts from the Gateway.

  • manager – Manager instance for sending email/SMS via the Gateway.

  • MCP – MCP230XX I/O expander instance (used when pin >= 100).

  • mqtt_send_queue (Queue | None) – Queue for publishing MQTT alert payloads.

Parameters:

manager (Manager)

output1_pin = 19
output2_pin = 20
buzzer_pin = 16
light_pin = 26
minInterval = 100000
__init__(manager)[source]

Initialise the OzAlert handler.

Parameters:

manager (Manager) – Manager instance used to dispatch email/SMS alerts through the Gateway API.

Return type:

None

setup(alertConfig)[source]

Configure GPIO pins and load alert rules from the Gateway config.

Sets up output pins (direct GPIO or MCP230XX expander) for buzzer, light, and relay channels, then loads the list of alert rules.

Parameters:

alertConfig (dict) – Alert configuration dict containing gpio pin overrides and an alert list of threshold rules.

Return type:

None

loop(alertqueue)[source]

Run the alert evaluation loop, blocking on the queue for sensor data.

Continuously reads sensor payloads from the queue, compares each value against its upper/lower thresholds, and triggers the corresponding alert channel. Also handles timed alert resets.

Parameters:

alertqueue (Queue) – Queue supplying sensor data dicts for evaluation.

Return type:

None

setAlert(output, status, config=None, data=None, threshold=None, operator=None)[source]

Activate or deactivate an alert on the specified output channel.

Channel mapping:

0 – relay output 1 (GPIO/MCP) 1 – relay output 2 (GPIO/MCP) 2 – buzzer + light (GPIO/MCP) 3 – email notification via Gateway 4 – SMS notification via Gateway 5 – MQTT message via send queue

Parameters:
  • output (int) – Output channel number (0-5).

  • status (int) – Desired state (1 = active, 0 = inactive).

  • config (dict[str, Any] | None) – Alert rule dict (required for email/SMS/MQTT channels).

  • data (dict[str, Any] | None) – Current sensor data payload.

  • threshold (int | float | None) – Threshold value that was breached.

  • operator (str | None) – Comparison operator string (">" or "<").

Return type:

None

run(alertConfig, alertqueue, mqttqueue)[source]

Entry point: set up alerts and start the evaluation loop.

Checks if alerts are enabled in the config, stores the MQTT queue, then delegates to setup() and loop().

Parameters:
  • alertConfig (dict) – Full alert/automation configuration from the Gateway.

  • alertqueue (Queue) – Queue supplying sensor data payloads.

  • mqttqueue (Queue) – Queue for outbound MQTT alert messages.

Return type:

None