Hallo, mittlerweile habe ich es hinbekommen meinen GPIO 17 per Web anszusteuern.
Dies gelingt mir über Webiopi.
Das ganze ist jedoch nur kopiert und eingefügt, bzw abgeschrieben.
Nun habe ich versucht einen zweiten Button einzufügen und diesen auf einen anderen Pin zu legen.
Nur leider scheint hier irgendwas nicht ganz stimmig zu sein.
Der zweite Button erscheint leider nicht in den eingegeben Farben und führt auch keine Aktion am GPIO aus.
Vielleicht könnt ihr mir ja weiterhelfen.
Der hinzugefügte Button soll ähnlich die Funktion des erstens haben nur am GPIO 22 und nicht 17.
HTML Code:
HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hausautomation</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">
webiopi().ready(function() {
// Create a "Light" labeled button for GPIO 17
var button = webiopi().createGPIOButton(17, "GPIO 17");
var button2 = webiopi().createGPIOButton(22, "GPIO22");
// Append button to HTML element with ID="controls" using jQuery
$("#controls").append(button);
$("#controls").append(button2);
// Refresh GPIO buttons
// pass true to refresh repeatedly of false to refresh once
webiopi().refreshGPIO(true);
});
</script>
<style type="text/css">
button {
display: block;
margin:10px 1280px 10px 10px;
width: 160px;
height: 45px;
font-size: 25pt;
font-weight: bolder;
color: BLUE;
}
#gpio17.LOW {
background-color: RED;
}
#gpio17.HIGH {
background-color: GREEN;
}
button2 {
display: block;
margin:10px 10x 10px 10px;
width: 160px;
height: 45px;
font-size: 25pt;
font-weight: bolder;
color: Green;
}
#gpio22.LOW {
background-color: RED;
}
#gpio22.HIGH {
background-color: GREEN;
}
</style>
</head>
<body>
<div id="controls" align="center"></div>
</body>
</html>
Alles anzeigen
Pythonscript:
Code
import webiopi
import datetime
GPIO = webiopi.GPIO
LIGHT = 17 # GPIO pin using BCM numbering
LIGHT2 = 22
HOUR_ON = 8 # Turn Light ON at 08:00
HOUR_OFF = 18 # Turn Light OFF at 18:00
# setup function is automatically called at WebIOPi startup
def setup():
# set the GPIO used by the light to output
GPIO.setFunction(LIGHT, GPIO.OUT)
GPIO.setFunction(LIGHT2, GPIO.OUT)
# retrieve current datetime
now = datetime.datetime.now()
# test if we are between ON time and tun the light ON
if ((now.hour >= HOUR_ON) and (now.hour < HOUR_OFF)):
GPIO.digitalWrite(LIGHT, GPIO.HIGH)
# loop function is repeatedly called by WebIOPi
def loop():
# retrieve current datetime
now = datetime.datetime.now()
# toggle light ON all days at the correct time
if ((now.hour == HOUR_ON) and (now.minute == 0) and (now.second == 0)):
if (GPIO.digitalRead(LIGHT) == GPIO.LOW):
GPIO.digitalWrite(LIGHT, GPIO.HIGH)
# toggle light OFF
if ((now.hour == HOUR_OFF) and (now.minute == 0) and (now.second == 0)):
if (GPIO.digitalRead(LIGHT) == GPIO.HIGH):
GPIO.digitalWrite(LIGHT, GPIO.LOW)
# gives CPU some time before looping again
webiopi.sleep(0.5)
# destroy function is called at WebIOPi shutdown
def destroy():
GPIO.digitalWrite(LIGHT, GPIO.LOW)
GPIO.digitalWrite(LIGHT2, GPIO.LOW)
Alles anzeigen