-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiotest.php
More file actions
35 lines (27 loc) · 959 Bytes
/
iotest.php
File metadata and controls
35 lines (27 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
define('__ROOT__', dirname(__FILE__));
require_once(__ROOT__.'/config.php');
$getPinstatus = 'undefined';
$status = (object) array('status' => 'error', 'message' => '');
// set port and status
$pin = 17;
$state = 0;
// Set I/O mode for pin
trim(@shell_exec("gpio -g mode $pin out"));
// write out status to gpio port
$string = "gpio -g write $pin $state";
$val = trim(@shell_exec("$string"));
// read status of gpio port
exec("gpio read $gpioConnectors[$pin]", $pinStatus);
// error handling of read command
if(is_array($pinStatus) && isset($pinStatus[0])) {
$getPinstatus = intval($pinStatus[0]);
$status->status = 'success';
$status->message = 'state changed';
$status->touchedpin = $pin;
}
// return result as json object
$status->hardwarestatus = $getPinstatus;
echo json_encode ($status, true);
exit(0);
?>