Ich möchte Webiopi verwenden, um mehrere Schaltflächen im Browser anzuzeigen und mehrere Gruppenrichtlinienobjekte für Himbeerkuchen ein- und auszuschalten, aber das funktioniert nicht. Insbesondere möchte ich GPIO12 und 13 mit den Schaltflächen im Browser ein- und ausschalten. Wenn ich ein Programm wie unten gezeigt erstelle, zeigt der Browser "Auf diese Site kann nicht zugegriffen werden" an. Wenn Sie die 7. Zeile "LIGHT2 = 13", die 14. Zeile "GPIO.setFunction (LIGHT2, GPIO.OUT)" und die letzte Zeile "GPIO.digitalWrite (LIGHT2, GPIO.LOW)" von script.py löschen, greift der Browser darauf zu. Sie können nur GPIO12 bedienen. Wie kann ich GPIO13 auch betriebsbereit machen? Vielen Dank.
index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>WebIOPi | Light Control</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">
webiopi().ready(function() {
var content,button;
content=$("#content");
// Create a "Light" labeled button for GPIO 12
button = webiopi().createGPIOButton(12, "ranp1");
// Append button to HTML element with ID="controls" using jQuery
$("#controls").append(button);
button = webiopi().createGPIOButton(13, "Light2");
$("#controls").append(button);
// 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: 5px 5px 5px 5px;
width: 160px;
height: 45px;
font-size: 24pt;
font-weight: bold;
color: white;
}
#gpio12.LOW {
background-color: Black;
}
#gpio12.HIGH {
background-color: Blue;
}
#gpio13.LOW {
background-color: Black;
}
#gpio13.HIGH {
background-color: Blue;
}
</style>
</head>
<body>
<div id="controls" align="center"></div>
</body>
</html>
script.py
#! /usr/bin/env /usr/bin/python3
#_*_ cording:utf-8 _*_
import webiopi
import datetime
GPIO = webiopi.GPIO
LIGHT = 12 # GPIO pin using BCM numbering
LIGHT2 = 13
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(1)
# destroy function is called at WebIOPi shutdown
def destroy():
GPIO.digitalWrite(LIGHT, GPIO.LOW)
GPIO.digitalWrite(LIGHT2, GPIO.LOW)
Recommended Posts