Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- /*
- * using PHPSerial (https://github.com/Xowap/PHP-Serial) on Beaglebone Black to send ON/OFF to Arduino's LED
- * and read LM35 sensor temperature. See Arduino code here: http://pastebin.com/J6fCNguP
- * almost all code is by: http://paolosarteschi.altervista.org/wp/?p=375
- * to connect Arduino & Beaglebone Black use:
- * www.instructables.com/id/How-to-make-a-BeagleBone-and-an-Arduino-communicat/?ALLSTEPS
- *
- */
- error_reporting(E_ALL);
- ini_set("display_errors", 1);
- define("PORT","/dev/ttyO2");
- include "php_serial.class.php";
- $serial = new phpSerial;
- $serial->deviceSet(PORT);
- $serial->confBaudRate(9600);
- $serial->confParity("none");
- $serial->confCharacterLength(8);
- $serial->confStopBits(1);
- $serial->confFlowControl("none");
- $serial->deviceOpen();
- $title = "";
- global $temperatura, $statoled;
- $serial->sendMessage("r");
- sleep(0.2);
- $serialread = $serial->readPort();
- if($serialread==""){
- //echo "errore - valori assenti";
- header ('Location:' . $_SERVER['PHP_SELF']);
- }
- elseif(strlen($serialread)!=3){
- //echo "errore - valori non coerenti";
- header ('Location:' . $_SERVER['PHP_SELF']);
- }
- else{
- $statoled = substr($serialread,0,1);
- $temperatura = substr($serialread, 1,2);
- if ($statoled == 1){
- $title = "SPEGNI LED";
- //echo $title;
- }
- else {
- $title = "ACCENDI LED";
- //echo $title;
- }
- }
- if (isset($_GET['action'])) {
- if ($_GET['action'] == "on") {
- $serial->sendMessage("a");
- header ('Location:' . $_SERVER['PHP_SELF']);
- }
- else if ($_GET['action'] == "off") {
- $serial->sendMessage("s");
- header ('Location:' . $_SERVER['PHP_SELF']);
- }
- $read = $serial->readPort();
- }
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>TEST LED - <?=$title?></title>
- </head>
- <body>
- <?
- if ($statoled == 1){
- ?>
- <a href="<?=$_SERVER['PHP_SELF'] . "?action=off" ?>">
- <button style="color: red;width:250px"><h1>SPEGNI LED</h1></button></a>
- <?
- }
- else if ($statoled == 0){
- ?>
- <a href="<?=$_SERVER['PHP_SELF'] . "?action=on" ?>">
- <button style="color: green;width:250px"><h1>ACCENDI LED</h1></button></a>
- <?
- }
- ?>
- <h2 style="font-family:arial;color: darkblue">
- Temperatura:
- <?
- echo "$temperatura° C";
- ?>
- </h2>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement