Guten Abend allerseits,
Ich versuche ein ganz normales python script über eine php zu öffnen, doch es funktioniert nicht.
Ich benutze den apache2 Webserver.
Lokal und über eine SSH Verbindung funktioniert das .py script super, aber wie gesagt sobald ich es über den Webserver versuche Klappt es nicht.
Hätte jemand ne Idee ?
Danke im Voraus
PHP: script.php
<?php
echo shell_exec('sudo python /var/www/html/ledschule.py');
header("Location:index.html");
?>
Python: ledschule.php
#!/usr/bin/env python
# coding=utf-8
import RPi.GPIO as GPIO
import time
from random import randint
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT) #16 pin
GPIO.setup(22, GPIO.OUT) #15 pin
GPIO.setup(27, GPIO.OUT) #13
a = 0
while a<=1:
random = randint(1, 3)
if random == 1:
for i in range(1):
GPIO.output(27, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(27, GPIO.LOW)
time.sleep(0.5)
elif random == 2:
for i in range(1):
GPIO.output(22, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(22, GPIO.LOW)
time.sleep(0.5)
else:
for i in range(1):
GPIO.output(23, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(23, GPIO.LOW)
time.sleep(0.5)
a=a+1
GPIO.cleanup()
Alles anzeigen