dynamicOne
asked on
PHP with Raspberry Pi
I am controlling my garage door using a Raspberry Pi. I want to add a magnetic switch to tell if the door is open or closed.
Any idea where to start?
Here is what I have so far:
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="generator" content=
"HTML Tidy for Linux (vers 6 November 2007), see www.w3.org">
<meta charset="utf-8">
<title>Garage Remote</title>
<!--Begin code to open and close garage door-->
<script type="text/javascript">
window.onload = function(){
buttonOff = document.getElementById('s ubmitPress ed');
buttonOff.onClick = relayOff;
}
function relayOff(){
hidden = document.getElementById("t otal");
hidden.value = "pressed";
form = document.getElementById("r elay");
form.method = "GET";
form.action = "remote.php";
form.submit();
}
</script><!--End code to open and close garage door-->
<!--Begin code to color button when pressed-->
<script type="text/javascript">
function setColor(btn,color){
var property=document.getEleme ntById(btn );
if (window.getComputedStyle(p roperty).b ackgroundC olor == 'rgb(244, 113, 33)') {
property.style.backgroundC olor=color ;
}
else {
property.style.backgroundC olor = "#2159F4";
}
}
</script><!--End code to color button when pressed-->
</head>
<body>
<form id="relay" action="remote.php" method="get">
<input type="button" id="submitPressed" style=
"border:1px solid #000; font-size:80px;" value="Open/Close"
onclick="relayOff();setCol or('submit Pressed',' #fff200'); ">
<input type="hidden" name="total" id="total" value="">
</form><!--Begin code to open and close garage door-->
<?php
exec("gpio -g mode 17 out");
$state = $_GET["total"];
if ($state == "off"){
exec("gpio -g write 17 1");
sleep(1);
exec("gpio -g write 17 0");
}
?><!--End code to open and close garage door-->
<!--Insert code for magnetic switch here.-->
</body>
</html>
Any idea where to start?
Here is what I have so far:
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="generator" content=
"HTML Tidy for Linux (vers 6 November 2007), see www.w3.org">
<meta charset="utf-8">
<title>Garage Remote</title>
<!--Begin code to open and close garage door-->
<script type="text/javascript">
window.onload = function(){
buttonOff = document.getElementById('s
buttonOff.onClick = relayOff;
}
function relayOff(){
hidden = document.getElementById("t
hidden.value = "pressed";
form = document.getElementById("r
form.method = "GET";
form.action = "remote.php";
form.submit();
}
</script><!--End code to open and close garage door-->
<!--Begin code to color button when pressed-->
<script type="text/javascript">
function setColor(btn,color){
var property=document.getEleme
if (window.getComputedStyle(p
property.style.backgroundC
}
else {
property.style.backgroundC
}
}
</script><!--End code to color button when pressed-->
</head>
<body>
<form id="relay" action="remote.php" method="get">
<input type="button" id="submitPressed" style=
"border:1px solid #000; font-size:80px;" value="Open/Close"
onclick="relayOff();setCol
<input type="hidden" name="total" id="total" value="">
</form><!--Begin code to open and close garage door-->
<?php
exec("gpio -g mode 17 out");
$state = $_GET["total"];
if ($state == "off"){
exec("gpio -g write 17 1");
sleep(1);
exec("gpio -g write 17 0");
}
?><!--End code to open and close garage door-->
<!--Insert code for magnetic switch here.-->
</body>
</html>
Where is the web server that is running PHP?
ASKER
It is running on the Pi.
Interesting, didn't realize that Raspberry Pi could run all that. I have never used PHP to control hardware. I suggest you click on "Request Attention" above to get others to look at your question.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
On another note, please use the code tags when you post code in your posts as it makes it tons easier to read.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.