So I have been working on a project to turn on/off LED lights remotely through my Raspberry Pi but I have run into an issue.
My index.html code should work properly but when I press the on or off button, nothing happens. The issue is not with the actual commands (sudo python /var/www/html/scripts/lights/lampon.py or sudo python /var/www/html/scripts/lights/lampoff.py) because when I run the same command directly in the raspberry pi terminal, it works. And the rest of my code also seems to be correct... So I don't know what the problem is.
The code looks like this:
<html>
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<?php
if (isset($_POST['LightON']))
{
exec("sudo python /var/www/html/scripts/lights/lampon.py");
}
if (isset($_POST['LightOFF']))
{
exec("sudo python /var/www/html/scripts/lights/lampoff.py");
}
?>
<form method="post">
<button class="btn" name="LightON">Light ON</button>
<button class="btn" name="LightOFF">Light OFF</button><br><br>
</form>
</html>
Any help would be appreciated. Thanks in advance.
NOTE: I am able to run the sudo command above as a normal user and the lights work but when I press the button, it doesn't work (webpage seems to load - so its doing something... but the lights do not turn on).
You can do it just like this:
But you need to install Wiring Pi on Raspberry Pi first, to install it :
I hope that i was useful :)