I would like you to help me with a problem that I have with my code, which I have been reviewing a lot but I can not fix it, this is my program in php, which runs on an Apache server (using raspberry pi 3 B), I will also leave you my python program, the objective of the program is to control the rotation of an engine, and its speed, but I can not execute the python file, but if I execute it from the command terminal, and I place the following:
cd /var/www/html
python motorpwm.py 100 1 0 0
the led (first I'm testing it with a led) turns on, and if the number varies instead of 100, if it changes its intensity, but if I try to run from php, nothing happens physically with the led, even when I miss them if they print the corresponding values of 'x', 'y', 'z' and 'a'.
<?php
$x=$_GET['velocidad'];
if(isset($_GET['der'])){
$y=1;
$z=0;
$a=0;
}elseif(isset($_GET['izq'])){
$z=1;
$y=0;
$a=0;
}elseif(isset($_GET['alto'])){
$z=0;
$y=0;
$a=2;
}
$instruccion=("python /var/www/html/motorpwm.py ".$x." ".$y." ".$z." ".$a);
/*tambien lo probe quitando el /var/www/html ya que se encuentran en la misma carpeta*/
echo $instruccion;
$resultado=shell_exec($instruccion);
echo $resultado;
?>
'x' is the speed of the motor that the user inserts, 'der' is when the user presses the button that turns the motor to the right, 'left' the button on the left, and 'high' is the button to stop the engine. The echo $ instruction if it prints the value of $ instruction, and the echo $ result if it prints the values of 'x', and ',' z 'and' a '. here is my python program.
import RPi.GPIO as GPIO
import sys
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
pwm = GPIO.PWM(12, 100)
GPIO.setup(11, GPIO.OUT)
pwm2 = GPIO.PWM(11, 100)
pwm2.start(0)
vel= float(sys.argv[1])
p1= int(sys.argv[2])
p2=int(sys.argv[3])
p3=int(sys.argv[4])
print(vel)
print(p1)
print(p2)
print(p3)
while p3!=2:
if p1==1:
pwm.ChangeDutyCycle(vel)
pwm2.ChangeDutyCycle(0)
elif p2==1:
pwm.ChangeDutyCycle(0)
pwm2.ChangeDutyCycle(vel)
print("fin")
pwm.stop()
GPIO.cleanup()
I think my problem is not so much in the python file, since it does run from the command line, rather in the php file, which is the one that does not run the python file. I want to clarify that the python file is 'executable', and has the permissions of the user www: data, just like the folder where the two files are located, I also want to clarify that both the php and python files are located together in the address / var / www / html