Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
  4. <script type="text/javascript">
  5. $(function(){
  6. setInterval(function(){
  7. $.ajax({
  8. url: "status.php",
  9. type: "POST",
  10. dataType: "text",
  11. success: function(data){
  12. $("#status_div").html('The Garage Door Status is: ' + data);
  13. }
  14. })
  15.  
  16. }, 5000);
  17. });
  18. </script>
  19. </head>
  20. <body>
  21. Somethign on the web page. Normally this would be the main website while the DIV tag waits to load.
  22. <div id="status_div"></div>
  23. </body>
  24. </html>
  25.  
  26. <?php
  27.  
  28. // Call Python script which gives me the status of my garage door in a text string.
  29. $output = shell_exec('python /home/blah/garage_door/myq-garage.py status');
  30.  
  31. //I am NOT including lots of parsing of the $output. Eventually I get the $output trimmed down to the to the $status PHP variable.
  32. $status[1] = "Closed" //values here can be either 'Closed' or 'Open'
  33.  
  34. ?>
  35.  
  36. <!-- // Style info for table(s) -->
  37. <style type="text/css">
  38. .tg {border-collapse:collapse;border-spacing:0;}
  39. .tg td{font-family:Arial, sans-serif;font-size:14px;padding:7px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
  40. .tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:7px 7px;border-style:solid;border-width:1px;overflow:hidden;wor$
  41. .tg .tg-baqh{text-align:center;vertical-align:top}
  42. .tg .tg-yw4l{vertical-align:center;text-align:left}
  43. </style>
  44.  
  45. <!-- // HTML table to display garage door status info. Display the image of the door and door status in left cell, time/date and options in right -->
  46. <center>
  47. <table class="tg">
  48. <tr>
  49. <th class="tg-baqh">
  50. <div class="garage_status">
  51. <?php
  52. //Stuff unrelated to OP question here. Dynamically displaying an image based on garage door status.
  53. ?>
  54. </div>
  55. </th>
  56. <th class="tg-yw4l">
  57. <?php
  58. // Command button to open door.
  59. if (isset($_POST['button_open'])){
  60. if ($status[1] = "Closed"){
  61. shell_exec('python /home/blah/garage_door/myq-garage.py open "Garage Door"');
  62. }
  63. }
  64.  
  65. // Command button to close door.
  66. if (isset($_POST['button_close'])){
  67. if ($status[1] = "Open"){
  68. shell_exec('python /home/blah/garage_door/myq-garage.py close "Garage Door"');
  69. echo "<script>alert ("cmd button works")</script>";
  70. }
  71. }
  72.  
  73. ?>
  74. <form method="post">
  75. <p>
  76. <button name="button_open">Open Door</button>
  77. <button name="button_close">Close Door</button>
  78. </p>
  79. </form>
  80. </th>
  81. </tr>
  82. </table>
  83. </center>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement