Weather Monitoring Station Interface
This module provides the interface to a Weather Station.
- class WeatherStation(hostname, port, logger, config_file='')
Class to implement the Modbus interface to a Weather Station.
- Parameters:
hostname (str)
port (int)
logger (logging.Logger)
config_file (str)
- configure_poll_sensors(sensors_to_poll)
Configure the subset of sensors to poll.
- Parameters:
sensors – List of sensors to poll.
sensors_to_poll (list[SensorEnum])
- Return type:
- subscribe_data(data_callback, error_callback=None)
Subscribe to data updates and error notifications.
- unsubscribe_data(subscription_id)
Unsubscribe from all updates.
- connect()
Connect to the device.
- Raises:
ValueError if the configuration could not be loaded or is invalid. ConnectionError if connecting failed.
- Return type:
- start_polling(timeout=2.0)
Start polling the weather station data.
Will block until the polling has started successfully.
- enum SensorEnum(value)
Enumeration type for Sensors.
Valid values are as follows:
- WINDSPEED = <SensorEnum.WINDSPEED: 'windSpeed'>
- WINDDIRECTION = <SensorEnum.WINDDIRECTION: 'windDirection'>
- TEMPERATURE = <SensorEnum.TEMPERATURE: 'temperature'>
- PRESSURE = <SensorEnum.PRESSURE: 'pressure'>
- HUMIDITY = <SensorEnum.HUMIDITY: 'humidity'>
- RAINFALL = <SensorEnum.RAINFALL: 'rainfall'>
- enum InputSignalStatusEnum(value)
Possible channel status values.
- Member Type:
Valid values are as follows:
- IN_RANGE = <InputSignalStatusEnum.IN_RANGE: 0>
- OVER_RANGE = <InputSignalStatusEnum.OVER_RANGE: 1>
- UNDER_RANGE = <InputSignalStatusEnum.UNDER_RANGE: 2>
- enum ModbusExceptionType(value)
Enumeration of Modbus exception types.
This enumeration includes both standard Modbus exception codes and exceptions raised by the pymodbus library.
Valid values are as follows:
- IllegalFunction = <ModbusExceptionType.IllegalFunction: <ExcCodes.ILLEGAL_FUNCTION: 1>>
- IllegalAddress = <ModbusExceptionType.IllegalAddress: <ExcCodes.ILLEGAL_ADDRESS: 2>>
- IllegalValue = <ModbusExceptionType.IllegalValue: <ExcCodes.ILLEGAL_VALUE: 3>>
- SlaveFailure = <ModbusExceptionType.SlaveFailure: <ExcCodes.DEVICE_FAILURE: 4>>
- Acknowledge = <ModbusExceptionType.Acknowledge: <ExcCodes.ACKNOWLEDGE: 5>>
- SlaveBusy = <ModbusExceptionType.SlaveBusy: <ExcCodes.DEVICE_BUSY: 6>>
- NegativeAcknowledge = <ModbusExceptionType.NegativeAcknowledge: <ExcCodes.NEGATIVE_ACKNOWLEDGE: 7>>
- MemoryParityError = <ModbusExceptionType.MemoryParityError: <ExcCodes.MEMORY_PARITY_ERROR: 8>>
- GatewayNoResponse = <ModbusExceptionType.GatewayNoResponse: <ExcCodes.GATEWAY_NO_RESPONSE: 11>>
- ModbusIOException = <ModbusExceptionType.ModbusIOException: 12>
- ParameterException = <ModbusExceptionType.ParameterException: 13>
- NoSuchSlaveException = <ModbusExceptionType.NoSuchSlaveException: 14>
- ConnectionException = <ModbusExceptionType.ConnectionException: 15>
- InvalidMessageReceivedException = <ModbusExceptionType.InvalidMessageReceivedException: 16>
- MessageRegisterException = <ModbusExceptionType.MessageRegisterException: 17>
- Unknown = <ModbusExceptionType.Unknown: 18>
- class DatapointDict
Bases:
TypedDictDictionary representation of a WMSDatapoint.
- Attributes:
value (float): The measured value from the weather station.
unit (str): The unit of the measured value (e.g., “Celsius”, “m/s”).
timestamp (datetime): The timestamp when the datapoint was recorded.
low_current_value (float): The low current value associated with the datapoint.
adc_value (int): The raw ADC (Analog-to-Digital Converter) value.
input_signal_status (
InputSignalStatusEnum): The status of the input signal.
- class ErrorDict
Bases:
TypedDictDictionary representation of a WMSError.
- Atributes:
modbus_exception (
ModbusExceptionType): The type of Modbus exception that occurred.message (str): A message describing the error.
timestamp (datetime): The timestamp when the error occurred.
- load_weather_station_configuration(config_path)
Load and validate a weather station configuration YAML file.
- Parameters:
config_path (
str) – path to the configuration file.- Return type:
WeatherStationDict- Returns:
validated configuration dictionary.
- Raises:
OSError if the file cannot be opened.
- Raises:
UnicodeDecodeError if the file cannot be decoded.
- Raises:
YAMLError if the YAML cannot be loaded.
- Raises:
ValueError if the configuration is invalid.