I want to turn on a gpio output and receive input from a gpio input. This is all initiated from a webpage. I am making an ajax call to a php file which itself runs the python script. It does not work. When I click on the button nothing happens. I can run the php file with php script.php and it all works. If I hash out all the references to gpio in the python script then the python runs. As a test I can make it write a string to a text file. I can also make it work by having the php write a string to a text file and having the python read the file and then access the gpio. Here is some code:-
<?php header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); $status = "onn"; // $stet = "lkjhgfdsa"; $tmp = exec("python oneshot.py $status"); echo $tmp; file_put_contents("/home/pi/boiler/function.pick" , $status); ?>
#!/usr/bin/env python import sys import RPi.GPIO as GPIO from time import sleep #import sys GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.setup(12, GPIO.OUT) GPIO.output(12, 1) mode= sys.argv print mode f = open('/home/pi/boiler/edom.pick', 'w') f.seek(0) f.write(mode) f.close() print (mode) if mode == ('onn'): GPIO.output(12, 0) elif mode == ('off'): GPIO.output(12, 1)
Any help would be much appreciated.