So I've a Raspberry Pi 4, and I've connected a push button to it's GPIO, and the python file is works fine if I execute it from the Terminal.
I get NULL if I execute my Python file from the web site.
So far, I want to achieve that; I want to execute the Python program if I push the button on the webpage, and if I push the button which is connected to the GPIO I want the result on the web page "The time was: %s, when the button was pushed."
Here is the python code:
#!/usr/bin/env python
import sys
import datetime
time=datetime.datetime.now()
import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
def button_callback(channel):
print("The time was: %s, when the button was pushed." % (time))
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.add_event_detect(10,GPIO.RISING,callback=button_callback)
message =raw_input("Press Enter to exit.\n\n")
And I have made a PHP file, which looks like this:
<html>
<body>
<head>
<title>
Webpage
</title>
</head>
<form method="post">
<input type="submit" value="go" name="go">
</form>
</body>
</html>
<?php
if(isset($_POST['go']))
{
$output = shell_exec("python sudo /var/www/html/button.py");
var_dump($output);
}
?>
Thanks for all of the advices.