0

I am on a raspberry pi. The permissions of all the files including the python script which looks like this:

#!/usr/bin/python
from time import sleep
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
GPIO.output(11, False)
sleep(0.4)
GPIO.output(11, True)
sleep(1.6)
GPIO.output(11, False)
sleep(1)

is all owned by www-data and all the files are set to 777 (Yes, I know this is not smart but I'm trying to fix it this.) It is run using sudo and my visudo file is here:

www-data ALL=(ALL) NOPASSWD: /var/www/gateopener.py /usr/bin/python /bin/chmod

And here is the PHP...

<?php
if (($_POST["safe2"]) != "good") {
    header("Location: http://xx.xxx.xx.xxx/index.html");
}
ignore_user_abort(true);
set_time_limit(0);
`/usr/bin/sudo /var/www/gateopener.py`;
?>

Now someone tell me why the hell this isn't working? I have tried different variations of it (EI moving the file around, using different permissions.). I have tried using php's exec() function as well...Help me please.

6
  • how do you know it isnt working? why not put a print at the top of your python file or create a file ... to see if its getting called ... Commented Jun 27, 2014 at 21:41
  • Did you tried this? stackoverflow.com/questions/4168179/… Commented Jun 27, 2014 at 21:43
  • Have you made the python file executable? Commented Jun 27, 2014 at 21:43
  • @JoranBeasley Because I'm using the GPIO and I have been working with this for over an hour...I've tried many things/ Commented Jun 27, 2014 at 21:45
  • Yes The python file is an executable that I can call from the command line. @EL3PHANTEN Commented Jun 27, 2014 at 21:45

1 Answer 1

0

run_me_as_daemon.py

#!/usr/bin/python
from time import sleep
import RPi.GPIO as GPIO
import os
while True:
   if not os.path.exists("open_gate.txt"):continue
   os.remove("open_gate.txt")   # FILE DELETE !!! so we dont re-enter
   with open("log.txt","w") as f:
     print >>f,"Opening GATE @ %s"%(time.strftime("%x %X"),)
     GPIO.setmode(GPIO.BOARD)
     print >>f, "Set Mode To %s"%(GPIO.BOARD,)
     GPIO.setup(11, GPIO.OUT)
     print >>f, "SET 11 to %s"%(GPIO.OUT) 
     GPIO.output(11, False)
     print >> f,"output low signal 11"
     sleep(0.4)
     GPIO.output(11, True)
     print >> f,"output high signal to 11"
     sleep(1.6)
     GPIO.output(11, False)
     print >> f,"output low signal 11"
     sleep(1)
     print >> f,"Competed TASK"

index.php

<?php
if (($_POST["safe2"]) != "good") {
    header("Location: http://xx.xxx.xx.xxx/index.html");
}
file_put_contents("open_gate.txt"," ");
?>

is one possible solution

Sign up to request clarification or add additional context in comments.

7 Comments

Okey. But should the file not be deleted after the script has run?
it deletes it as soon as it encounters it ... but it may be smart to move it to the end in case the user refreshed the php page
How would i launch this as a daemon? and thank you so much I can't wait to try this and see if it works! :) @JoranBeasley
I just tried this...It did not work. Maybe i did something wrong i dont know.
it should work ... did the output log.txt file show up? did open_gate.txt show up ... you may want to use an absolute path for open_gate.txt in both scripts in case they are looking in different directories... to run it as daemon just invoke it from your startup script to run in the background or manually call it # python my_script.py and watch as it runs ...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.