Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
- <script type="text/javascript">
- $(function(){
- setInterval(function(){
- $.ajax({
- url: "status.php",
- type: "POST",
- dataType: "text",
- success: function(data){
- $("#status_div").html('The Garage Door Status is: ' + data);
- }
- })
- }, 5000);
- });
- </script>
- </head>
- <body>
- Somethign on the web page. Normally this would be the main website while the DIV tag waits to load.
- <div id="status_div"></div>
- </body>
- </html>
- <?php
- // Call Python script which gives me the status of my garage door in a text string.
- $output = shell_exec('python /home/blah/garage_door/myq-garage.py status');
- //I am NOT including lots of parsing of the $output. Eventually I get the $output trimmed down to the to the $status PHP variable.
- $status[1] = "Closed" //values here can be either 'Closed' or 'Open'
- ?>
- <!-- // Style info for table(s) -->
- <style type="text/css">
- .tg {border-collapse:collapse;border-spacing:0;}
- .tg td{font-family:Arial, sans-serif;font-size:14px;padding:7px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
- .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$
- .tg .tg-baqh{text-align:center;vertical-align:top}
- .tg .tg-yw4l{vertical-align:center;text-align:left}
- </style>
- <!-- // 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 -->
- <center>
- <table class="tg">
- <tr>
- <th class="tg-baqh">
- <div class="garage_status">
- <?php
- //Stuff unrelated to OP question here. Dynamically displaying an image based on garage door status.
- ?>
- </div>
- </th>
- <th class="tg-yw4l">
- <?php
- // Command button to open door.
- if (isset($_POST['button_open'])){
- if ($status[1] = "Closed"){
- shell_exec('python /home/blah/garage_door/myq-garage.py open "Garage Door"');
- }
- }
- // Command button to close door.
- if (isset($_POST['button_close'])){
- if ($status[1] = "Open"){
- shell_exec('python /home/blah/garage_door/myq-garage.py close "Garage Door"');
- echo "<script>alert ("cmd button works")</script>";
- }
- }
- ?>
- <form method="post">
- <p>
- <button name="button_open">Open Door</button>
- <button name="button_close">Close Door</button>
- </p>
- </form>
- </th>
- </tr>
- </table>
- </center>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement