Created
June 19, 2012 15:35
-
-
Save kane-thornwyrd/2954840 to your computer and use it in GitHub Desktop.
Basic com between Resperry Pie and Arduino in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//(c) Lucas Lombard | |
$error = "No Sockets"; | |
$list = shell_exec("screen -ls"); | |
if (strpos($list, $error) !== FALSE) { | |
exec('screen -dmS arduino /dev/ttyAMA0 115200'); | |
sleep(1); | |
exec('screen -p 0 -S arduino -X eval \'stuff \"2\"\''); | |
header('Location: '.$_SERVER['PHP_SELF']); | |
} | |
elseif ($_GET['pin']) { | |
$allowed = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"); | |
if (in_array($_GET['pin'], $allowed)) { | |
exec('screen -p 0 -S arduino -X eval \'stuff \"'.$_GET['pin'].'\"\''); | |
header('Location: '.$_SERVER['PHP_SELF']); | |
} | |
else { | |
echo "Caractere non pris en charge.<br />"; | |
} | |
} | |
else { | |
exec('screen -p 0 -S arduino -X eval \'stuff \"1\"\''); | |
exec('screen -p 0 -S arduino -X hardcopy /var/www/status.txt'); | |
$serial = exec('tail -1 /var/www/status.txt'); | |
$status = explode(";", $serial); | |
$on="ON"; | |
$off="OFF"; | |
$checked_pin = 0; | |
foreach ($status as $actual_pin) { | |
if($actual_pin == 1){$text[$checked_pin]=$off;}else{$text[$checked_pin]=$on;} | |
$checked_pin++; | |
} | |
$pin = 2; | |
$checked_pin = 0; | |
$pins_order = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"); | |
$device = array("PIN 02", "PIN 03", "PIN 04", "PIN 05", "PIN 06", "PIN 07", "PIN 08", "PIN 09", "PIN 10", "PIN 11", "PIN 12", "PIN 13"); | |
foreach ($text as $actual_pin) { | |
echo $device[$checked_pin].": ".$status[$checked_pin]." <a href=\"?pin=".$pins_order[$checked_pin]."\">". $actual_pin ."</a><br />"; | |
$checked_pin++; | |
$pin++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment