I am making a project that uses a web-server and a basic PHP script to turn on a GPIO pin.
Here is my code:
<html>
<head>
<meta name= "viewport" content="width=device-width" />
<title> LED Control </title>
</head>
<body>
LED Control:
<form method= "get" action = "gpio.php">
<input type="submit" value="ON" name="on">
<input type="submit" value="OFF" name="off">
</form>
<?php
$setmode17 = shell_exec("/usr/local/bin/gpio -g mode 17 out")
if (isset($_GET['on'])){
$gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 1")
echo "LED is on";
}
else if (isset($_GET['off'])){
$gpio_on = shell_exec("/usr/local/bin/gpio -g write 17 0")
}
?>
</body>
</html>
The GPIO pin does not turn on. I am also using the wiring pi library. What is the problem?
Here is my update code:
<html>
<head>
<meta name= "viewport" content="width=device-width" />
<title> LED Control </title>
</head>
<body>
LED Control:
<form method= "get" action = "gpio.php">
<input type="submit" value="ON" name="on">
<input type="submit" value="OFF" name="off">
</form>
<?php
$setmode17 = shell_exec("/usr/bin/sudo/gpio -g mode 17 out")
if (isset($_GET['on'])){
$gpio_on = shell_exec("/usr/bin/sudo/gpio -g write 17 1")
echo "LED is on";
}
else if (isset($_GET['off'])){
$gpio_on = shell_exec("/usr/bin/sudo/gpio -g write 17 0")
}
?>
</body>
</html>
and added this line to visudo: www-data ALL=(ALL) NOPASSWD: /usr/local/bin/gpio