Skip to content
Permalink
Browse files

GPIO Extender Client now functions

  • Loading branch information...
NEMS Tools
NEMS Tools committed Jul 7, 2019
1 parent 8697df1 commit 4c2e1d66893cd31667dce7e4165216d08344e965
Showing with 10 additions and 4 deletions.
  1. +10 −4 gpio-extender/gpioe-client
@@ -10,10 +10,15 @@
}
// Can be an IP address or FQDN
$serverIP = '127.0.0.1'; // to be overridden with config file later
$serverIP = '10.0.0.116'; // to be overridden with config file later
if (file_exists('/usr/local/bin/nems-info')) {
$thisIP = trim(shell_exec('/usr/local/bin/nems-info ip'));
} else {
$thisIP = getHostByName(getHostName());
}
$url = $serverIP . ':9595'; // need to specify the port of the GPIOE Server
if ($serverIP == '127.0.0.1' || $serverIP == trim(shell_exec('/usr/local/bin/nems-info ip'))) {
if ($serverIP == '127.0.0.1' || $serverIP == $thisIP) {
// You can't run the client on the same server as the server... you'd then have two GPIO daemons controlling the GPIO
die('Cannot run a NEMS Tools GPIO Extender Client on this server.' . PHP_EOL . 'You need a NEMS Tools client device. Please read the docs.' . PHP_EOL);
}
@@ -26,14 +31,15 @@
curl_close($curl);
$GPIO = json_decode($data);
if (json_last_error() === 0) {
echo 'Connection successful.';
echo 'GPIO Extension to ' . $serverIP . ' successful. ';
if ($hardware == 0) {
die(' However, no Raspberry Pi GPIO detected.' . PHP_EOL);
}
echo PHP_EOL;
foreach ($GPIO as $pin=>$state) {
if ($hardware != 0) shell_exec('/usr/local/bin/gpio -g write ' . $pin . ' ' . $state);
echo '(Pin ' . $pin . ': ' . $state . ') ';
}
echo PHP_EOL;
} else {
echo 'Could not find a running NEMS Tools GPIO Extender Server at ' . $serverIP . PHP_EOL;
exit();

0 comments on commit 4c2e1d6

Please sign in to comment.
You can’t perform that action at this time.