I'm trying to execute a python script from PHP... But I'm getting a wierd output... In my Python script there is GPIO statements to control the relay and a print statement... Now the wierd thing is the print statement gets executed but not the GPIO statement... No errors are there... I have also provided execute permission for my python file... I don't know what's the problem... Python gets executed not the ""GPIO"" :( :( The Python code(relay.py) I used is:
import sys
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
pin=11
GPIO.setup(pin,GPIO.OUT)
i=sys.argv[1]
n=int(i)
if(n==0):
print(n)
GPIO.output(pin,GPIO.LOW)
if(n==1):
print(n)
GPIO.output(pin,GPIO.HIGH)
The PHP(lightonoff.php) code is:
<form method="post" action="php.php">
<input type="submit" value="on">
<input type="hidden" name="ct1" value="1">
</form>
<form method="post" action="php.php">
<input type="submit" value="off">
<input type="hidden" name="ct1" value="0">
</form>
The php.php file is:
<?php
$i=$_POST['ct1'];
$r=exec("/var/www/html/relay.py $i");
echo $r;
?>