Wed Mar 02, 2016 7:21 am
Thanks major tom. Now I wish i new even more about coding so i could run all of this together because the light switch code runs in a loop, it overrides the web page script. The simple solution would be 2 sets of relays and wire them like a 3 way switch.
If anyone wants to take this on I would appreciate it. If you take this on you will notice in my code that 5 relays are coded for an easy all on or off plus on their own along with other relays on their own. the light switch code needs to work with the all lights code in the web page everything else will be done via the web page. Thanks again.
index.php for web interface
[code]<?php
$ctl = $_POST['ctl'];
$command = "sudo python lights_c.py $ctl";
$result = shell_exec($command);
echo($result);
?>
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<title>Arena light control</title>
<body><p class="head">Arena light system!</p>
<p class="title"> Control the lights from here </p>
<table align="center" border="1">
<tr>
<td>
<form action="" method="POST" name="form">
<p class="title">All Lights </p>
<p class="form">
<input type="submit" id="on" value="ON">
<input type="hidden" name="ctl" value="1">
</form></p>
<form action="" method="POST" name="form">
<p class="lol">
<input type="submit" id="off" value="OFF">
<input type="hidden" name="ctl" value="0">
</form>
</td>
<td>
<form action="" method="POST" name="form">
<p class="title"> NE Lights </p>
<p class="form">
<input type="submit" id="on" value="ON">
<input type="hidden" name="ctl" value="11">
</form></p>
<form action="" method="POST" name="form">
<p class="lol">
<input type="submit" id="off" value="OFF">
<input type="hidden" name="ctl" value="22">
</form>
</td>
<td>
<form action="" method="POST" name="form">
<p class="title"> NW Lights </p>
<p class="form">
<input type="submit" id="on" value="ON">
<input type="hidden" name="ctl" value="33">
</form></p>
<form action="" method="POST" name="form">
<p class="lol">
<input type="submit" id="off" value="OFF">
<input type="hidden" name="ctl" value="44">
</form>
</td>
</tr>
<tr>
<td>
<form action="" method="POST" name="form">
<p class="title">Gate Lights </p>
<p class="form">
<input type="submit" id="on" value="ON">
<input type="hidden" name="ctl" value="55">
</form></p>
<form action="" method="POST" name="form">
<p class="lol">
<input type="submit" id="off" value="OFF">
<input type="hidden" name="ctl" value="66">
</form>
</td>
<td>
<form action="" method="POST" name="form">
<p class="title"> SE Lights </p>
<p class="form">
<input type="submit" id="on" value="ON">
<input type="hidden" name="ctl" value="77">
</form></p>
<form action="" method="POST" name="form">
<p class="lol">
<input type="submit" id="off" value="OFF">
<input type="hidden" name="ctl" value="88">
</form>
</td>
<td>
<form action="" method="POST" name="form">
<p class="title"> SW Lights </p>
<p class="form">
<input type="submit" id="on" value="ON">
<input type="hidden" name="ctl" value="99">
</form></p>
<form action="" method="POST" name="form">
<p class="lol">
<input type="submit" id="off" value="OFF">
<input type="hidden" name="ctl" value="1010">
</form>
</td>
</tr>
<tr>
<td>
<form action="" method="POST" name="form">
<p class="title"> Cattle Lights </p>
<p class="form">
<input type="submit" id="on" value="ON">
<input type="hidden" name="ctl" value="1020">
</form></p>
<form action="" method="POST" name="form">
<p class="lol">
<input type="submit" id="off" value="OFF">
<input type="hidden" name="ctl" value="1030">
</form>
</td>
<td>
<form action="" method="POST" name="form">
<p class="title"> Saloon Lights </p>
<p class="form">
<input type="submit" id="on" value="ON">
<input type="hidden" name="ctl" value="1040">
</form></p>
<form action="" method="POST" name="form">
<p class="lol">
<input type="submit" id="off" value="OFF">
<input type="hidden" name="ctl" value="1050">
</form>
</td>
<td>
<form action="" method="POST" name="form">
<p class="title"> Crows Nest </p>
<p class="form">
<input type="submit" id="on" value="ON">
<input type="hidden" name="ctl" value="1060">
</form></p>
<form action="" method="POST" name="form">
<p class="lol">
<input type="submit" id="off" value="OFF">
<input type="hidden" name="ctl" value="1070">
</form>
</td>
</tr>
</table>
</p>
</body></html>
[/code]
script that index reads
[code]#!/usr/bin/python
import sys
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
args = sys.argv
pin = [11, 12, 13, 15, 16, 18, 22, 7, 3, 5, 24, 26, 19, 21, 23, 29]
#relay 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#location
#NE= 11 NW=12 Gate=13 SE=15 SW=16
ctl = args[1] #Argument 1 for ON/OFF
if (int(ctl) == 1):
GPIO.setup(11, GPIO.OUT)
GPIO.output(11,GPIO.LOW)
time.sleep(.5)
GPIO.setup(12, GPIO.OUT)
GPIO.output(12,GPIO.LOW)
time.sleep(.5)
GPIO.setup(13, GPIO.OUT)
GPIO.output(13,GPIO.LOW)
time.sleep(.5)
GPIO.setup(15, GPIO.OUT)
GPIO.output(15,GPIO.LOW)
time.sleep(.5)
GPIO.setup(16, GPIO.OUT)
GPIO.output(16,GPIO.LOW)
if (int(ctl) == 0):
GPIO.setup(16, GPIO.OUT)
GPIO.output(16,GPIO.HIGH)
time.sleep(.5)
GPIO.setup(15, GPIO.OUT)
GPIO.output(15,GPIO.HIGH)
time.sleep(.5)
GPIO.setup(13, GPIO.OUT)
GPIO.output(13,GPIO.HIGH)
time.sleep(.5)
GPIO.setup(12, GPIO.OUT)
GPIO.output(12,GPIO.HIGH)
time.sleep(.5)
GPIO.setup(11, GPIO.OUT)
GPIO.output(11,GPIO.HIGH)
if (int(ctl) == 11):
GPIO.setup(11, GPIO.OUT)
GPIO.output(11,GPIO.LOW)
if (int(ctl) == 22):
GPIO.setup(11, GPIO.OUT)
GPIO.output(11, GPIO.HIGH)
if (int(ctl) == 33):
GPIO.setup(12, GPIO.OUT)
GPIO.output(12,GPIO.LOW)
if (int(ctl) == 44):
GPIO.setup(12, GPIO.OUT)
GPIO.output(12, GPIO.HIGH)
if (int(ctl) == 55):
GPIO.setup(13, GPIO.OUT)
GPIO.output(13,GPIO.LOW)
if (int(ctl) == 66):
GPIO.setup(13, GPIO.OUT)
GPIO.output(13, GPIO.HIGH)
if (int(ctl) == 77):
GPIO.setup(15, GPIO.OUT)
GPIO.output(15,GPIO.LOW)
if (int(ctl) == 88):
GPIO.setup(15, GPIO.OUT)
GPIO.output(15, GPIO.HIGH)
if (int(ctl) == 99):
GPIO.setup(16, GPIO.OUT)
GPIO.output(16,GPIO.LOW)
if (int(ctl) == 1010):
GPIO.setup(16, GPIO.OUT)
GPIO.output(16, GPIO.HIGH)
if (int(ctl) == 1020):
GPIO.setup(18, GPIO.OUT)
GPIO.output(18,GPIO.LOW)
if (int(ctl) == 1030):
GPIO.setup(18, GPIO.OUT)
GPIO.output(18, GPIO.HIGH)
if (int(ctl) == 1040):
GPIO.setup(22, GPIO.OUT)
GPIO.output(22,GPIO.LOW)
if (int(ctl) == 1050):
GPIO.setup(22, GPIO.OUT)
GPIO.output(22, GPIO.HIGH)
if (int(ctl) == 1060):
GPIO.setup(7, GPIO.OUT)
GPIO.output(7,GPIO.LOW)
if (int(ctl) == 1070):
GPIO.setup(7, GPIO.OUT)
GPIO.output(7, GPIO.HIGH)
[/code]
and the above code for the light switch
[code]import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
GPIO.setup(12, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
GPIO.setup(16, GPIO.OUT)
GPIO.setup(37,GPIO.IN, pull_up_down=GPIO.PUD_UP)
# input of the switch will change the state of the LED
while True:
time.sleep(.5)
GPIO.output(11,GPIO.input(37))
time.sleep(.5)
GPIO.output(12,GPIO.input(37))
time.sleep(.5)
GPIO.output(13,GPIO.input(37))
time.sleep(.5)
GPIO.output(15,GPIO.input(37))
time.sleep(.5)
GPIO.output(16,GPIO.input(37))
time.sleep(.5)
[/code]