troubleshooting Question

PHP with Raspberry Pi

Avatar of dynamicOne
dynamicOne asked on
ProgrammingPHPPersonal ElectronicsHome SecurityRaspberry Pi
7 Comments3 Solutions1381 ViewsLast Modified:
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">
  <meta name="generator" content=
  "HTML Tidy for Linux (vers 6 November 2007), see">
  <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('submitPressed');
        buttonOff.onClick = relayOff;

  function relayOff(){

        hidden = document.getElementById("total");
        hidden.value = "pressed";

        form = document.getElementById("relay");
        form.method = "GET";
        form.action = "remote.php";
  </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.getElementById(btn);
   if (window.getComputedStyle(property).backgroundColor == 'rgb(244, 113, 33)') {;
    else { = "#2159F4";
  </script><!--End code to color button when pressed-->

  <form id="relay" action="remote.php" method="get">
    <input type="button" id="submitPressed" style=
    "border:1px solid #000; font-size:80px;" value="Open/Close"
    <input type="hidden" name="total" id="total" value="">
  </form><!--Begin code to open and close garage door-->

          exec("gpio -g mode 17 out");
          $state = $_GET["total"];

          if ($state == "off"){
                  exec("gpio -g write 17 1");
                  exec("gpio -g write 17 0");

  ?><!--End code to open and close garage door-->
  <!--Insert code for magnetic switch here.-->
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 3 Answers and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros