RPiDataClient

class lsst.ts.ess.csc.RPiDataClient(config: SimpleNamespace, topics: lsst.ts.salobj.controller.Controller | types.SimpleNamespace, log: Logger, simulation_mode: int = 0)

Bases: ControllerDataClient

Get environmental data from a Raspberry Pi with custom hat.

Parameters:
namestr
configtypes.SimpleNamespace

The configuration, after validation by the schema returned by get_config_schema and conversion to a types.SimpleNamespace.

topicssalobj.Controller or types.SimpleNamespace

The telemetry topics this data client can write, as a struct with attributes such as tel_temperature.

loglogging.Logger

Logger.

simulation_modeint, optional

Simulation mode; 0 for normal operation.

Attributes Summary

connected

Methods Summary

configure()

Store device configurations.

connect()

Connect to the RPi and configure it.

descr()

Return a brief description, without the class name.

disconnect()

Disconnect from the RPi.

get_config_schema()

Get the config schema as jsonschema dict.

get_telemetry_dispatch_dict()

get_telemetry_schema()

perform_pre_read_loop_tasks()

Perform any tasks before starting the read loop.

process_csat3b_telemetry(sensor_name, ...)

Process CSAT3B 3-D anemometer telemetry.

process_hx85a_telemetry(sensor_name, ...)

Process HX85A humidity sensor telemetry.

process_hx85ba_telemetry(sensor_name, ...)

Process HX85BA humidity sensor telemetry.

process_telemetry(sensor_name, timestamp, ...)

Process the sensor telemetry.

process_temperature_telemetry(sensor_name, ...)

Process temperature telemetry.

process_windsonic_telemetry(sensor_name, ...)

Process Gill Windsonic sensor telemetry.

read()

Read and unmarshal a json-encoded dict.

read_data()

Read and process data from the RPi.

read_loop()

Call the read_data function in a loop and allow for max_timeouts timeouts before raising a TimeoutError.

run()

Read data from the server and publish it as ESS telemetry.

run_command(command, **parameters)

Write a command.

start()

Call disconnect, connect, and start the run task.

stop()

Stop reading and publishing data.

write_humidity_etc(sensor_name, timestamp, ...)

Write relative humidity and related quantities.

Attributes Documentation

connected

Methods Documentation

configure() None

Store device configurations.

This provides easy access when processing telemetry.

async connect() None

Connect to the RPi and configure it.

Raises:
RuntimeError

If already connected.

descr() str

Return a brief description, without the class name.

This should be just enough information to distinguish one instance of this client from another. For example RPiDataClient should return something like:

f"host={self.config.host}, port={self.config.port}"
async disconnect() None

Disconnect from the RPi.

Always safe to call, though it may raise asyncio.CancelledError if the writer is currently being closed.

classmethod get_config_schema() dict[str, Any]

Get the config schema as jsonschema dict.

get_telemetry_dispatch_dict() dict[str, Callable]
classmethod get_telemetry_schema() dict[str, Any]
async perform_pre_read_loop_tasks() None

Perform any tasks before starting the read loop.

async process_csat3b_telemetry(sensor_name: str, timestamp: float, response_code: int, sensor_data: Sequence[float]) None

Process CSAT3B 3-D anemometer telemetry.

Accumulate a specified number of samples before writing the telemetry topic.

Parameters:
sensor_namestr

The name of the sensor.

timestampfloat

The timestamp of the data.

response_codeint

The ResponseCode.

sensor_dataeach of type float

A Sequence of float representing the sensor telemetry data.

async process_hx85a_telemetry(sensor_name: str, timestamp: float, response_code: int, sensor_data: Sequence[float]) None

Process HX85A humidity sensor telemetry.

Parameters:
sensor_namestr

The name of the sensor.

timestampfloat

The timestamp of the data.

response_codeint

The ResponseCode

sensor_dataeach of type float

A Sequence of floats representing the sensor telemetry data:

  • relative humidity (%)

  • air temperature (C)

  • dew point (C)

async process_hx85ba_telemetry(sensor_name: str, timestamp: float, response_code: int, sensor_data: Sequence[float]) None

Process HX85BA humidity sensor telemetry.

Parameters:
sensor_namestr

The name of the sensor.

timestampfloat

The timestamp of the data.

response_codeint

The ResponseCode

sensor_dataeach of type float

A Sequence of floats representing the sensor telemetry data:

  • relative humidity (%)

  • air temperature (C)

  • air pressure (mbar)

  • dew point (C)

async process_telemetry(sensor_name: str, timestamp: float, response_code: int, sensor_data: Sequence[float | int | str]) None

Process the sensor telemetry.

Parameters:
sensor_namestr

The name of the sensor.

timestampfloat

The timestamp of the data.

response_codeint

The response code.

sensor_dataeach of type float

A Sequence of float representing the sensor telemetry data.

Raises:
RuntimeError

If the response code is common.ResponseCode.DEVICE_READ_ERROR

async process_temperature_telemetry(sensor_name: str, timestamp: float, response_code: int, sensor_data: Sequence[float]) None

Process temperature telemetry.

Parameters:
sensor_namestr

The name of the sensor.

timestampfloat

The timestamp of the data.

response_codeint

The ResponseCode

sensor_dataeach of type float

A Sequence of float representing the sensor telemetry data.

async process_windsonic_telemetry(sensor_name: str, timestamp: float, response_code: int, sensor_data: Sequence[float | int]) None

Process Gill Windsonic sensor telemetry.

Parameters:
sensor_namestr

The name of the sensor.

timestampfloat

The timestamp of the data.

response_codeint

The ResponseCode

sensor_dataeach of type float

A Sequence of floats representing the sensor telemetry data:

  • wind speed (m/s)

  • wind direction (deg)

async read() dict

Read and unmarshal a json-encoded dict.

This may be a command acknowedgement or telemetry data.

Time out if reading takes longer than COMMUNICATE_TIMEOUT seconds.

Returns:
datadict

The read data, after json-decoding it.

Raises:
RuntimeError

In case of not being connected. In case parsing gthe JSON data fails.

async read_data() None

Read and process data from the RPi.

async read_loop() None

Call the read_data function in a loop and allow for max_timeouts timeouts before raising a TimeoutError.

async run() None

Read data from the server and publish it as ESS telemetry.

This is called once after connect and it should keep running until cancelled. See the Raises section for exceptions subclasses should raise.

Raises:
ConnectionError

If the connection to the data server is lost.

asyncio.TimeoutError

If data is not received in reasonable time.

Exception

(or any subclass) if any other serious problem occurs.

async run_command(command: str, **parameters: Any) None

Write a command. Time out if it takes too long.

Parameters:
commandstr

The command to write.

**parametersdict

Command parameters, as name=dict. For example:

configuration = {"devices": self.config.devices}
Raises:
ConnectionError

If not connected.

asyncio.TimeoutError

If it takes more than COMMUNICATE_TIMEOUT seconds to acquire the lock or write the data.

async start() None

Call disconnect, connect, and start the run task.

Raises the same exceptions as connect. If disconnect raises, this logs the exception and continues.

async stop() None

Stop reading and publishing data.

This is alway safe to call, whether connected or not. This should raise no exceptions except asyncio.CancelledError. If disconnect raises, this logs the exception and continues.

async write_humidity_etc(sensor_name: str, timestamp: float, dew_point: float | None, pressure: float | None, relative_humidity: float | None, temperature: float | None, isok: bool) None

Write relative humidity and related quantities.

Parameters:
sensor_namestr

Sensor name

timestampfloat | None

Time at which the data was measured (TAI, unix seconds)

dew_pointfloat | None

Dew point (C)

pressurefloat | None

Parometric pressure (Pa)

relative_humidityfloat | None

Relative humidity (%)

temperaturefloat | None

Air temperature (C)

isokbool

Is the data valid?