Hi everyone I am trying to run a python script on my raspberry pi 2 via web server running apache2, php, and raspbian jessie. What my plan is to do is have a timelapse camera using python (code below) and when I go to a webpage it and click a button and it will start to run the script below.
import time
import picamera
import RPi.GPIO as GPIO
from subprocess import call
from datetime import datetime
import math
import os
green = 16 #Running
red = 20 #wating for sunset
startBut = 21 #button to start every thing
GPIO.setmode(GPIO.BCM)
GPIO.setup(startBut, GPIO.IN, GPIO.PUD_UP) #push button
GPIO.setup(green, GPIO.OUT)
GPIO.setup(red, GPIO.OUT)
d = datetime.now()
initYear = "%04d" % (d.year)
initMonth = "%02d" % (d.month)
initDate = "%02d" % (d.day)
initSec = "%02s" % (d.second)
initMin = "%02s" % (d.minute)
folderToSave = "/media/TIMELAPS/timelapse_" + str(initYear) + "_" + str(initMonth) + "_" + str(initDate) + "_" + str(initMin) + "_" + str(initSec) + "/"
#folderToSave2 = "timelapse_" + str(initYear) + "_" + str(initMonth) + "_" + str(initDate) + "_" + str(initSec) + "/"
os.mkdir(folderToSave)
#GPIO.wait_for_edge(startBut, GPIO.FALLING)
with picamera.PiCamera() as camera:
#GPIO.output(green, GPIO.HIGH)
var = 1
fileNum = 0
while var == 1 : # This constructs an infinite loop
if fileNum <= 9:
fileName = "0" + str(fileNum)
print("file name = " + fileName)
else:
fileName = "" + str(fileNum)
print("file name = " + fileName)
camera.capture(folderToSave + fileName + ".jpg") #takes the photo to the flashdrive
#camera.capture(folderToSave2 + fileName) #takes the photo and saves to the apple timecaplse disk
fileNum = fileNum + 1
time.sleep(5)
print("Good Bye")
and here is my Html code
<!DOCTYPE html>
<html>
<head>
<title>Raspbery Pi Timelapse camera</title>
<script>
function runPythonScript(file) {
if (file == "time") {
//run the Time_laps_camera.py
}
else if (file == "aperture") {
//run the pi_camera_aperture.py
}
}
</script>
</head>
<body>
<center>
<div style="padding: 20px 10px;" ></div>
<div>
<button type="button" onclick="runPythonScript('time')">TimeLapse Camera</button>
</div>
<div style="padding: 15px;">
<button type="button" onclick="runPythonScript('aperture')">TimeLapse Camera</button>
</div>
</center>
</body>
</html>
So basicly what I am trying to do is insted of me connecting to my pi via remote desktop and executing the script what I want to do is want to go to a webpage and hit a button and run the script.