panoptes.pocs.sensor package

Submodules

panoptes.pocs.sensor.power module

Power board sensor interface for relays and current/voltage readings.

Provides PowerBoard, a serial-connected reader/controller for the PANOPTES power relay board (Arduino + relay shield), and a small Relay data class for labels/states. Includes helpers to toggle relays and to parse/aggregate telemetry into rolling means and status dictionaries.

class panoptes.pocs.sensor.power.PinState(*values)[source]

Bases: IntEnum

Represents a HIGH or LOW state for a digital output pin.

HIGH = 1
LOW = 0
OFF = 0
ON = 1
class panoptes.pocs.sensor.power.PowerBoard(port: str = None, name: str = 'Power Board', relays: dict[str, dict] = None, reader_callback: Callable[[dict], dict] = None, mean_interval: int | None = 5, arduino_board_name: str = 'power_board', *args, **kwargs)[source]

Bases: PanBase

Power distribution and monitoring.

This represents a “trucker” board for PANOPTES, which is a combination of an Arduino Uno and an Infineon 24V relay shield.

The relay shield has three PROFETs on them that are capable of sensing the current through the relay. RELAY_4 has a dedicated PROFET. The other two PROFETs can switch between two relays depending on the status of the appropriate DSEL pin.

This class uses panoptes.utils.device.serial.SerialDevice for threaded (async) reading of the values from the Arduino Uno connected to the power board, which are parsed by the default callback and appended to a deque whose size can be controlled. A custom callback can be passed that should accept a single string parameter and return a dictionary.

Pin names specified above correspond to Infineon terminology. See manual: https://bit.ly/2IGgWLQ.

change_relay_state(relay: Relay, new_state_command: TruckerBoardCommands)[source]

Changes the relay to the new state.

cycle_relay(label)[source]

Cycle the relay with a default 5-second delay.

default_reader_callback(data)[source]

Parse a JSON line from the Arduino into a list for DataFrame append.

Parameters:

data (str) – JSON string produced by the Arduino firmware, containing keys for relay states and readings along with ac_ok/battery_low.

Returns:

A list of values in the order [timestamp, ac_ok, battery_low,

<relay readings…>] suitable for constructing/appending to a pandas DataFrame, or None if the reading is ignored/invalid.

Return type:

list | None

classmethod lookup_port(vendor_id=9025, product_id=67, **kwargs)[source]

Tries to guess the port hosting the power board arduino.

The default vendor_id is for official Arduino products. The default product_id is for an Uno Rev 3.

https://github.com/arduino/Arduino/blob/1.8.0/hardware/arduino/avr/boards.txt#L51-L58

property readings

Return the rolling mean of the readings.

record(collection_name: str = None)[source]

Record the rolling mean of the power readings in the database.

Parameters:

collection_name (str) – Where to store the results in the db. If None (the default), then use arduino_board_name.

relay_labels: dict[str, Relay]
relays: list[Relay]
setup_relays(relays: dict[str, dict])[source]

Setup the relays.

property status

Summarize relay states and latest readings.

Returns:

Mapping of relay name to a dict with label, state, and reading,

plus top-level ‘ac_ok’ and ‘battery_low’ booleans if available.

Return type:

dict

to_dataframe(**kwargs)[source]

Make a dataframe from the latest readings.

toggle_relay(label)[source]

Toggle relay from OFF<->ON

turn_off(label)[source]

Turns off the relay with the given label.

turn_on(label)[source]

Turns on the relay with the given label.

class panoptes.pocs.sensor.power.Relay(name: str, relay_index: TruckerRelayIndex, label: str | None, state: PinState | None = PinState.OFF, default_state: PinState | None = PinState.OFF)[source]

Bases: object

Relay data class

cycle_relay()[source]

Cycle this relay (toggle with a small delay), as supported by firmware.

default_state: PinState | None = 0
label: str | None
name: str
relay_index: TruckerRelayIndex
state: PinState | None = 0
toggle_relay()[source]

Toggle this relay from OFF to ON or vice versa.

turn_off()[source]

Turn this relay OFF (helper bound by PowerBoard.setup_relays).

turn_on()[source]

Turn this relay ON (helper bound by PowerBoard.setup_relays).

class panoptes.pocs.sensor.power.TruckerBoardCommands(*values)[source]

Bases: IntEnum

The Trucker Board can accept a series of commands for controlling the relays

CYCLE_DELAY = 3
OFF = 0
ON = 1
TOGGLE = 2
class panoptes.pocs.sensor.power.TruckerRelayIndex(*values)[source]

Bases: IntEnum

The available relays on the Trucker Board

RELAY_0 = 0
RELAY_1 = 1
RELAY_2 = 2
RELAY_3 = 3
RELAY_4 = 4

panoptes.pocs.sensor.remote module

HTTP-based remote sensor reader for PANOPTES.

Provides RemoteMonitor to poll a JSON endpoint and optionally store the latest reading in the local PANOPTES database.

class panoptes.pocs.sensor.remote.RemoteMonitor(endpoint_url: str = None, sensor_name: str = None, *args, **kwargs)[source]

Bases: PanBase

Does a pull request on an endpoint to obtain a JSON document.

capture(store_result: bool = True) dict[source]

Read JSON from endpoint url and capture data.

Note

Currently this doesn’t do any processing or have a callback.

Returns:

Dictionary of sensors keyed by sensor name.

Return type:

sensor_data (dict)

disconnect()[source]

Placeholder to stop polling/cleanup for a remote sensor.

Currently this only logs; provided for symmetry with other drivers.

panoptes.pocs.sensor.weather module

Module contents