platypush.plugins.gpio

class platypush.plugins.gpio.GpioPlugin(pins: Optional[Dict[str, int]] = None, mode: str = 'board', **kwargs)[source]

Plugin to handle raw read/write operation on the Raspberry Pi GPIO pins.

Requires:
  • RPi.GPIO (pip install RPi.GPIO)
__init__(pins: Optional[Dict[str, int]] = None, mode: str = 'board', **kwargs)[source]
Parameters:
  • mode – Specify ‘board’ if you want to use the board PIN numbers, ‘bcm’ for Broadcom PIN numbers (default: ‘board’)
  • pins – Configuration for the GPIO PINs as a name -> pin_number map.

Example:

{
    "LED_1": 14,
    "LED_2": 15,
    "MOTOR": 16,
    "SENSOR": 17
}
cleanup()[source]

Cleanup the state of the GPIO and resets PIN values.

read(pin: Union[int, str], name: Optional[str] = None) → Dict[str, Any][source]

Reads a value from a PIN.

Parameters:
  • pin – PIN number or configured name.
  • name – Optional name for the read value (e.g. “temperature” or “humidity”)

Response:

output = {
    "name": <pin number or pin/metric name>,
    "pin": <pin>,
    "value": <value>,
    "method": "read"
}
read_all()[source]

Reads the values from all the configured PINs and returns them as a list. It will raise a RuntimeError if no PIN mappings were configured.

write(pin: Union[int, str], value: int, name: Optional[str] = None) → Dict[str, Any][source]

Write a byte value to a pin.

Parameters:
  • pin – PIN number or configured name
  • name – Optional name for the written value (e.g. “temperature” or “humidity”)
  • value – Value to write

Response:

output = {
    "name": <pin or metric name>,
    "pin": <pin>,
    "value": <value>,
    "method": "write"
}