In my third if statement I want to run a C-program on the raspberry Pi when I press the button. I'm lost as how to do this.
Right now the C-program is just going to light up an LED and it works if I just run the compiled program, but I can't figure out how to do it through the PHP.
I've read somewhere to use "exec", but I don't know how to do that (I'm relatively new to programming).
<html>
<head>
</head>
<body>
<form method=GET action="index.php">
<input name="button" type="submit" value="Turnon">
<input name="button" type="submit" value="Turnoff">
<input name="button" type="submit" value="ON">
<input name="button" type="submit" value="OFF">
</form>
<?php
if ($_GET["button"] == "Turnon")
{
system ( "gpio mode 28 out" );
system ( "gpio write 28 1" );
};
if ($_GET["button"] == "Turnoff")
{
system ( "gpio mode 28 out" );
system ( "gpio write 28 0" );
};
if ($_GET["button"] == "ON")
{
system("sudo /home/pi/var/www/blink.exe >/dev/null 2>/dev/null & ");
};
if ($_GET["button"] == "OFF")
{
system ( "gpio mode 28 out" );
system ( "gpio write 28 0" );
};
?>
</body>
</html>
您是否在PHP中检查了shellexec()命令?
From the PHP docs
string exec ( string $command [, array &$output [, int &$return_var ]] )
in your code:
<?php
exec("gpio mode 28 out", $output);
print_r($output);
$output contains the result of your script
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.