Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>Documento sin título</title>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <style type="text/css">
- <!--
- .Estilo1 {font-family: Verdana, Arial, Helvetica, sans-serif}
- .Estilo2 {font-size: 60px}
- .Estilo3 {font-size: 50px}
- .Estilo4 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 50px; }
- -->
- </style>
- </head>
- <body>
- <div align="center">
- <h1 class="Estilo1 Estilo2">Contol de Riego </h1>
- <table width="688" border="2" cellpadding="3" cellspacing="2" bgcolor="#0099CC">
- <tr>
- <td width="320" class="Estilo4">Riego Exterior</td>
- <td width="171" class="Estilo4"><div align="center"><a href="<?=$_SERVER['PHP_SELF'] . "?action=on" ?>">ON</a></div></td>
- <td width="161" class="Estilo4"><div align="center"><a href="<?=$_SERVER['PHP_SELF'] . "?action=off" ?>">OFF</a></div></td>
- </tr>
- </table>
- <p class="Estilo1"><span class="Estilo3"><a href="control.php">Regresar</a></span></p>
- <p class="Estilo1"> </p>
- </div>
- </body>
- </html>
- <?php
- if (isset($_GET['action'])) {
- //Action required
- //Load the serial port class
- require("php_serial.class.php");
- //Initialize the class
- $serial = new phpSerial();
- //Specify the serial port to use... in this case COM1
- $serial->deviceSet("/dev/ttyACM0"); //SET THIS TO WHATEVER YOUR SERIAL DEVICE HAPPENS TO BE, YOU CAN FIND THIS UNDER THE ARDUINO SOFTWARE'S MENU
- //Set the serial port parameters. The documentation says 9600 8-N-1, so
- $serial->confBaudRate(9600); //Baud rate: 9600
- // $serial->confParity("none"); //Parity (this is the "N" in "8-N-1") ******THIS PART OF THE CODE WAS NOT NEEDED
- // $serial->confCharacterLength(8); //Character length (this is the "8" in "8-N-1") ******THIS PART OF THE CODE WAS NOT NEEDED
- // $serial->confStopBits(1); //Stop bits (this is the "1" in "8-N-1") ******THIS PART OF THE CODE WAS NOT NEEDED
- //$serial->confFlowControl("none"); //******THIS PART OF THE CODE WAS NOT NEEDED
- //Now we "open" the serial port so we can write to it
- $serial->deviceOpen();
- //Issue the appropriate command according to the Arduino source code 0=Green On, 1=Green Off, 2=Red On, 3=Red Off.
- if ($_GET['action'] == "on") {
- //to turn the GREEN LED ON, we issue the command
- $serial->sendMessage("z\r");
- } else if ($_GET['action'] == "off") {
- //to turn the GREEN LED OFF, we issue this command
- $serial->sendMessage("x\r");
- }
- //We're done, so close the serial port again
- $serial->deviceClose();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement