#!/usr/bin/env python3 # Control relay using WiFi. # (c) 2018 Bradley Knockel # Usage: ./relayWiFi.py 1 <-- warning: will leave pin in output mode! # ./relayWiFi.py 0 # Either SSH into the Pi and call this function, # or have /var/www/html/index.php run this according to $_GET["state"] # using http://raspberrypi.local/?state=true relayPin = 21 # or pin that controls the transistor that controls a relay import sys if len(sys.argv)>1 and sys.argv[1]=="1": state = True else: state = False import RPi.GPIO as IO IO.setmode(IO.BCM) IO.setup(relayPin, IO.OUT) if state: IO.output(relayPin, 1) print("LED on") else: IO.output(relayPin, 0) IO.cleanup() print("LED off")