diff --git a/relay_rpc/main.py b/relay_rpc/main.py index 688f4fa..5d22be0 100644 --- a/relay_rpc/main.py +++ b/relay_rpc/main.py @@ -25,6 +25,12 @@ def switch_relay(relay: int, state: bool): log.info("switching relay %s (pin %s) %s", relay, pin, state) GPIO.output(pin, not state) +def get_relay_state(relay: int) -> bool: + pin = int(GPIOS[relay - 1]) + state = GPIO.input(pin) + log = logging.getLogger() + log.info("Relay state of relay %s (pin %s) %s", relay, pin, state) + return state def init_relays(): """Init relays""" @@ -47,6 +53,7 @@ def main(): server = SimpleXMLRPCServer((HOST, PORT), allow_none=True) server.register_function(switch_relay, 'switch_relay') + server.register_function(get_relay_state, 'get_relay_state') log.info('Control-c to quit') server.serve_forever()