Witam. Udało mi się utworzyć button który wykonuje skrypt pythona
( uruchamia alarm). Problem który jeszcze pozostał to wyłączenie alarmu nie mogę wyjść z działania pętli podczas wciśnięcia przycisku off moglibyście coś zaradzić z tym temacie ?
Kod Pythona :
Zaloguj się, aby zobaczyć kod
import webiopi
import datetime
import RPi.GPIO as GPIO
import time
GPIO = webiopi.GPIO
#GPIO.setmode(GPIO.BCM)
PIR = 23
LED = 18
STOP = 21
GPIO.setup(PIR, GPIO.IN)
@webiopi.macro
def sendPiroff(STOP) :
STOP = True
@webiopi.macro
def sendPir():
localtime = time.asctime( time.localtime(time.time()) )
print ("Alarma ! ")
while True :
if STOP == True:
break
else :
if GPIO.input(PIR) :
GPIO.setup(LED, GPIO.OUT)
GPIO.output(LED, True)
print ("Wykrylem Ruch :", localtime )
time.sleep(2)
GPIO.setup(LED, GPIO.IN)
Zaloguj się, aby zobaczyć kod
Kod JavaScript :
Zaloguj się, aby zobaczyć kod
<!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">
<meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" />
<title>WebIOPi | Demo</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">
webiopi().ready(function() {
var content, button;
content = $("#content");
// create a button which call myMacroWithArgs with "1,2,3" as argument
button = webiopi().createMacroButton("macro", "Alarm ON ", "sendPir");
content.append(button); // append button to content div
// create a button which call myMacroWithoutArgs
button = webiopi().createMacroButton("macro", "Alarm Off", "sendPiroff");
content.append(button); // append button to content div
button = webiopi().createButton("test2", "Alarm Off 2", "sendPiroff");
content.append(button);
});
function callMacro() {
webiopi().callMacro("sendPiroff",args, macroCallback);
webiopi().callMacro("pirOn",args, macroCallback);
}
function macroCallback(macro, args, data) {
alert(macro + " returned with " + data);
}
</script>
<style type="text/css">
button {
display: block;
margin: 5px 5px 5px 5px;
width: 160px;
height: 45px;
font-size: 24pt;
font-weight: bold;
color: black;
}
input[type="range"] {
display: block;
width: 160px;
height: 45px;
}
#gpio7.LOW {
background-color: White;
}
#gpio7.HIGH {
background-color: Red;
}
</style>
</head>
<body>
<div id="content" align="center"></div>
</body>
</html>[code]
Zaloguj się, aby zobaczyć kod
0