Python and PHP using Raspberry GPIO
<p>With a little Python script I'm able to detect a button state that is connected in my Raspberry board. This is the script:</p>
<pre><code>#!/usr/bin/env python

import os
import RPi.GPIO as GPIO
import time

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)

GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

try:
    while True:
        if(GPIO.input(12) == 1):
            print 'Btn on'
            os.system('date')
            time.sleep(5)
        else:
            os.system('clear')
            print 'Waiting'
    time.sleep(2)

except KeyboardInterrupt:
    GPIO.cleanup()  
</code></pre>
<p>In this way, using PuTTY, or directly in the Raspberry terminal, I can easily detect the state of this button.</p>
<p>Now I would create the same thing but in PHP. I need to create a PHP web page that will be in the <code>var/www/html</code> directory of my Raspberry, and should just show me the same thing. When I press the button, I will get a simple echo &quot;Btn on&quot; with the timestamp, and if not pressed just another echo with &quot;Waiting&quot;.. Is it possible? I tried directly <code>exec</code> the Python script, in PHP, in this way:</p>
<pre><code>$command = escapeshellcmd('sudo -u www-data python btn.py');
$output = shell_exec($command);
echo $output;
</code></pre>
<p>but it's not working.</p>