I am trying to run 'lightled.py'(button RON) and 'lightledoff.py'(button ROFF) through PHP. Both programs include GPIO library and needs root access. Button 'ON' and 'OFF' directly switches the led on and off. Button ON and OFF works properly but RON and ROFF doesn't. How do i run python or c++ programs that need root access?
<!doctype html>
<html>
<head>
<title>LED Test</title>
<meta charset="UTF-8"/>
</head>
<body>
<h1>Light Led</h1>
<form method=GET action="index.php">
<h3>Radio Led</h3>
<input name="button" type="submit" value="RON">
<input name="button" type="submit" value="ROFF">
<h3>On Board Led for Test</h3>
<input name="button" type="submit" value="ON">
<input name="button" type="submit" value="OFF">
</form>
<?php
if ($_GET["button"] == "RON") {
system("echo raspberry | sudo -S python ./lightled.py");
};
if ($_GET["button"] == "ROFF") {
system("echo raspberry | sudo -S python ./lightledoff.py");
};
if ($_GET["button"] == "ON") {
system("gpio -g mode 17 out");
system("gpio -g write 17 1");
};
if ($_GET["button"] == "OFF") {
system("gpio -g mode 17 out");
system("gpio -g write 17 0");
};
?>
</body>
</html>