-
Notifications
You must be signed in to change notification settings - Fork 2
/
gpio.php
23 lines (23 loc) · 823 Bytes
/
gpio.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!-- This page is requested by the JavaScript, it updates the pin's status and then print it -->
<?php
//Getting and using values
if (isset ($_GET["pin"]) && isset($_GET["status"]) ) {
$pin = strip_tags($_GET["pin"]);
$status = strip_tags($_GET["status"]);
//Testing if values are numbers
if ( (is_numeric($pin)) && (is_numeric($status)) && ($status == "0") || ($status == "1") ) {
//set the gpio's mode to output
system("gpio mode ".$pin." out");
//set the gpio to high/low
if ($status == "0" ) { $status = "1"; }
else if ($status == "1" ) { $status = "0"; }
system("gpio write ".$pin." ".$status );
//reading pin's status
exec ("gpio read ".$pin, $status, $return );
//printing it
echo ( $status[0] );
}
else { echo ("fail"); }
} //print fail if cannot use values
else { echo ("fail"); }
?>