I have spent two days on this and have tried nearly everything I could find. I am using an apache server (2.4.10).
I have two files in a folder called
testPythonPHP that is located in the root folder of my server (
/var/www/html). The files are
pythonReturn.py. I call the python script from the PHP script using the exec command. Everything works fine before I try to use the
RPi.GPIO module in the python script. Before using the
RPi.GPIO module, I get the desired output.
Here is the PHP code:
<?php exec(" python /var/www/html/testPythonPHP/pythonReturn.py" , $status, $return ); echo( $status ." is status and ".$return." is return and user is "); echo exec( "whoami"); ?>
Here is my python code:
import RPi.GPIO as GPIO import time butPin = 25 ledPin = 24 GPIO.setmode (GPIO.BCM) #GPIO.setup (ledPin, GPIO.OUT) #GPIO.setup (butPin, GPIO.IN, pull_up_down = GPIO.PUD_DOWN) #GPIO.output (ledPin, GPIO.LOW) def bullspit(): cat = "3" dog = "4" catDog = cat + dog GPIO.cleanup() return catDog if __name__ == '__main__': print bullspit()
Here is the output to the browser:
34 is status and 0 is return and user is www-data
Once I un-comment any of the code in the python script, my output becomes:
is status and 1 is return and user is www-data
I no longer get the returned value from the python script and I now get the 1 return status (indicating something went wrong). I have tried changing permissions and using different commands (not that I can guarantee those were done correctly).
I feel like I am on the right track but cannot get this to work. Does anyone know what my mistake is or if there is another GPIO module I can use that will work with python and read analog values?
My goal is to use python to read in an analog value from a MCP3008 chip and return the value to the PHP script where I will dictate different GPIO pins to write high or low depending on the returned value. I tested a variation of the python file in the terminal and was able to print different return values based on an input button being high or low.
I would settle for reading in analog values from the PHP script, but it still seems like a permission issue and I will likely run into the same problem.