Je souhaite utiliser webiopi pour afficher plusieurs boutons sur le navigateur et activer / désactiver plusieurs GPIO pour la tarte aux framboises, mais cela ne fonctionne pas. Plus précisément, je voudrais activer et désactiver GPIO12 et 13 avec les boutons du navigateur, respectivement. Lorsque je crée un programme comme indiqué ci-dessous, le navigateur affiche «Ce site n'est pas accessible». Si vous supprimez la 7ème ligne "LIGHT2 = 13", la 14ème ligne "GPIO.setFunction (LIGHT2, GPIO.OUT)" et la dernière ligne "GPIO.digitalWrite (LIGHT2, GPIO.LOW)" de script.py, le navigateur accédera. Vous ne pouvez utiliser que GPIO12. Comment puis-je rendre GPIO13 opérationnel également? Je vous remercie.
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