执行shell命令PHP和raspberry-pi
我下面是:。。。乌尔树莓/ 目标是按照教程中的指导打开和关闭管脚,但 这里我不能使用:system(),exec(),因为它不执行 命令在树莓皮。页面加载准确,但当我 按按钮仅更改图像(开/关),但不执行命令。 我有连接良好的继电器,用于我所需的GPIO引脚号 我使用的工具有:PHP、Javascript、Lighttpd Web服务器,我的设备是安装了raspian Jessie的Pi3 model B 因此,我决定使用“shell_exec”来执行命令,但在将其实现到 程序在我的程序中没有效果,它什么也不显示。在我做错的地方需要帮助执行shell命令PHP和raspberry-pi,php,gpio,Php,Gpio,我下面是:。。。乌尔树莓/ 目标是按照教程中的指导打开和关闭管脚,但 这里我不能使用:system(),exec(),因为它不执行 命令在树莓皮。页面加载准确,但当我 按按钮仅更改图像(开/关),但不执行命令。 我有连接良好的继电器,用于我所需的GPIO引脚号 我使用的工具有:PHP、Javascript、Lighttpd Web服务器,我的设备是安装了raspian Jessie的Pi3 model B 因此,我决定使用“shell_exec”来执行命令,但在将其实现到 程序在我的程序中没有效
gpio.php
<?php
//This page is requested by the JavaScript, it updates the pin's status and then print it
//Getting and using values
$pin = array(4,17,18,27,22,23,24,25);
if (isset ( $_GET["pic"] )) {
$pic = strip_tags ($_GET["pic"]);
//test if value is a number
if ( (is_numeric($pic)) && ($pic <= 7) && ($pic >= 0) ) {
//set the gpio's mode to output
shell_exec("/usr/local/bin/gpio -g mode $pin[$pic] out");
//reading pin's status
shell_exec("/usr/local/bin/gpio -g read $pin[$pic] $status $return ");
//set the gpio to high/low
if ($status[0] == "0" ) { $status[0] = "1"; }
else if ($status[0] == "1" ) { $status[0] = "0"; }
shell_exec("/usr/local/bin/gpio -g write $pin[$pic] $status[0]");
//reading pin's status
shell_exec ("/usr/local/bin/gpio -g read $pin[$pic] $status $return");
//print it to the client on the response
echo($status[0]);
}
else { echo ("fail"); }
} //print fail if cannot use values
else { echo ("fail"); }
?>
index.php
<!DOCTYPE html>
<!--TheFreeElectron 2015, http://www.instructables.com/member/TheFreeElectron/ -->
<html>
<head>
<meta charset="utf-8" />
<title>Raspberry Pi Gpio</title>
</head>
<body style="background-color: black;">
<!-- On/Off button's picture -->
<?php
$val_array = array(0,0,0,0,0,0,0,0);
$pin = array(4,17,18,27,22,23,24,25);
//this php script generate the first page in function of the file
for ( $i= 0; $i<8; $i++) {
//set the pin's mode to output and read them
shell_exec("/usr/local/bin/gpio -g mode $pin[$pic] out");
shell_exec("/usr/local/bin/gpio -g read $i, $val_array[$i],$status $return ");
}
//for loop to read the value
$i =0;
for ($i = 0; $i < 8; $i++) {
//if off
if ($val_array[$i][0] == 0 ) {
echo ("<img id='button_".$i."' src='data/img/red/red_".$i.".jpg' onclick='change_pin (".$i.");'/>");
}
//if on
if ($val_array[$i][0] == 1 ) {
echo ("<img id='button_".$i."' src='data/img/green/green_".$i.".jpg' onclick='change_pin (".$i.");'/>");
}
}
?>
<!-- javascript -->
<script src="script.js"></script>
</body>
</html>
gpio.php
请附加适当的链接并正确设置问题的格式是否为数组?如果是这样,正如所写的,它会破坏您的shell\u exec
stringyes。我知道我在读取PIN时犯了一些错误,我猜:(我对此一无所知,但如果它是数组$status$return”);
是错误的,您需要类似$status[0]$return]的东西代码>