【发布时间】:2016-04-18 11:24:46
【问题描述】:
在我的第三个 if 语句中,当我按下按钮时,我想在树莓派上运行一个 C 程序。我不知道该怎么做。
现在 C 程序只会点亮一个 LED,如果我只运行编译后的程序,它就可以工作,但我不知道如何通过 PHP 来实现。
我在某处读过使用“exec”,但我不知道该怎么做(我对编程比较陌生)。
<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 c raspberry-pi exec