Advertisement
Guest User

Untitled

a guest
Mar 31st, 2014
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
  4.  
  5. </head>
  6. <body>
  7. <div id="status" style="width: 400px; height: 300px; border:#000 1px solid;"></div>
  8. <?php
  9. echo date("H:i")."<br>";
  10.  
  11. $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  12. // Se conecta ao IP e Porta:
  13. socket_connect($sock,"192.168.0.852", 80);
  14.  
  15. // Executa a ação correspondente ao botão apertado.
  16. if(isset($_POST['bits'])) {
  17. $msg = $_POST['bits'];
  18. if(isset($_POST['Fora'])){ if($msg[0]=='1') { $msg[0]='0'; } else { $msg[0]='1'; }}
  19. if(isset($_POST['Quarto1'])){ if($msg[1]=='1') { $msg[1]='0'; } else { $msg[1]='1'; }}
  20. if(isset($_POST['Quarto2'])){ if($msg[2]=='1') { $msg[2]='0'; } else { $msg[2]='1'; }}
  21. if(isset($_POST['Sala' ])){ if($msg[3]=='1') { $msg[3]='0'; } else { $msg[3]='1'; }}
  22. if(isset($_POST['Pequeno'])){ $msg = 'P#'; }
  23. if(isset($_POST['Grande' ])){ $msg = 'G#'; }
  24. socket_write($sock,$msg,strlen($msg));
  25. }
  26.  
  27.  
  28.  
  29. socket_write($sock,'R#',2); //Requisita o status do sistema.
  30.  
  31. // Espera e lê o status e define a cor dos botões de acordo.
  32. $status = socket_read($sock,6);
  33. echo $status;
  34. if (($status[4]=='L')&&($status[5]=='#')) {
  35. if ($status[0]=='0') $cor1 = lightcoral;
  36. else $cor1 = lightgreen;
  37. if ($status[1]=='0') $cor2 = lightcoral;
  38. else $cor2 = lightgreen;
  39. if ($status[2]=='0') $cor3 = lightcoral;
  40. else $cor3 = lightgreen;
  41. if ($status[3]=='0') $cor4 = lightcoral;
  42. else $cor4 = lightgreen;
  43.  
  44. echo "<form method =\"post\" action=\"alarme.php\">";
  45. echo "<input type=\"hidden\" name=\"bits\" value=\"$status\">";
  46. echo "<button style=\"width:70; background-color: $cor1 ;font: bold 14px Arial\" type = \"Submit\" Name = \"Fora\">Alarme</button></br></br>";
  47. echo "<button style=\"width:70; background-color: $cor2 ;font: bold 14px Arial\" type = \"Submit\" Name = \"Quarto1\">Quarto1</button></br></br>";
  48. echo "<button style=\"width:70; background-color: $cor3 ;font: bold 14px Arial\" type = \"Submit\" Name = \"Quarto2\">Quarto2</button></br></br>";
  49. echo "<button style=\"width:70; background-color: $cor4 ;font: bold 14px Arial\" type = \"Submit\" Name = \"Sala\">Sala</button></br></br></br>";
  50. echo "<button style=\"width:90;font: bold 14px Arial\" type = \"Submit\" Name = \"Pequeno\">Portao Pequeno</button></br></br>";
  51. echo "<button style=\"width:90;font: bold 14px Arial\" type = \"Submit\" Name = \"Grande\">Portao Grande</button></br></br>";
  52. echo "</form>";
  53. }
  54. // Caso ele não receba o status corretamente, avisa erro.
  55. else { echo "Falha ao receber status da casa."; }
  56. socket_close($sock);
  57. ?>
  58.  
  59. </body>
  60. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement