Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Removed tag 'pi', which is for π, the ratio of a circle's circumference to its diameter.
Link
Pang
  • 10.2k
  • 146
  • 87
  • 126

I'm trying to set up a system that when a number is inputted ontowill be given input into a web page, it triggerswill trigger a timer and turns on a GPIOGPIO pin of RPI for a few seconds then turns off.

I need to passpass a numbernumber that is submitted into a HTML formHTML form, into my python scriptpython script to work with.

I thought I found a solution but I'm not sure why its not working. I'm running apache2 on a Pi zeroPi zero W with PHP7PHP7.

Here are the two files I have in the /var/www/html/ directory (Many apologies for incredible inefficiency, I just needed to get it working)/var/www/html/ directory:

I'm trying to set up a system that when a number is inputted onto a web page, it triggers a timer and turns on a GPIO pin for a few seconds then turns off. I need to pass a number that is submitted into a HTML form, into my python script to work with. I thought I found a solution but I'm not sure why its not working. I'm running apache2 on a Pi zero W with PHP7. Here are the two files I have in the /var/www/html/ directory (Many apologies for incredible inefficiency, I just needed to get it working):

I'm trying to set up a system that when a number will be given input into a web page, it will trigger a timer and turns on a GPIO pin of RPI for a few seconds then turns off.

I need to pass a number that is submitted into a HTML form, into my python script to work with.

I thought I found a solution but I'm not sure why its not working. I'm running apache2 on a Pi zero W with PHP7.

Here are the two files I have in the /var/www/html/ directory:

Source Link
Bradderz
  • 21
  • 1
  • 8

Passing a single variable from HTML to Python script using PHP

I'm trying to set up a system that when a number is inputted onto a web page, it triggers a timer and turns on a GPIO pin for a few seconds then turns off. I need to pass a number that is submitted into a HTML form, into my python script to work with. I thought I found a solution but I'm not sure why its not working. I'm running apache2 on a Pi zero W with PHP7. Here are the two files I have in the /var/www/html/ directory (Many apologies for incredible inefficiency, I just needed to get it working):

index.php:

<form action="index.php" method="post">
 <input type="text" name="seconds"/>
 <input type="submit" name="SubmitSeconds" /><br/>
</form>
<?php
if(isset($_POST['SubmitSeconds'])) {
 shell_exec('/usr/bin/python /var/www/html/script.py'.$seconds);
}
?>

script.py:

#!/usr/bin/python
from datetime import datetime
from threading import Timer
import RPi.GPIO as GPIO
import time, cgi, sys
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)
def GPIOTimer():
 GPIO.output(23, 1)
 time.sleep(10)
 GPIO.output(23, 0)
 
def ten_seconds():
 global x
 global y
 x = datetime.today()
 y = x.replace(day=(x.day), hour=(x.hour), minute=(x.minute), second=(x.second+10), microsecond=0)
def five_mins():
 global x
 global y
 x = datetime.today()
 y = x.replace(day=(x.day), hour=(x.hour), minute=(x.minute+5), second=(x.second), microsecond=0)
def ten_mins():
 global x
 global y
 x = datetime.today()
 y = x.replace(day=(x.day), hour=(x.hour), minute=(x.minute+10), second=(x.second), microsecond=0)
def thirty_mins():
 global x
 global y
 x = datetime.today()
 y = x.replace(day=(x.day), hour=(x.hour), minute=(x.minute+30), second=(x.second), microsecond=0)
def one_hour():
 global x
 global y
 x = datetime.today()
 y = x.replace(day=(x.day), hour=(x.hour+1), minute=(x.minute), second=(x.second), microsecond=0)
def three_hours():
 global x
 global y
 x = datetime.today()
 y = x.replace(day=(x.day), hour=(x.hour+3), minute=(x.minute), second=(x.second), microsecond=0)
def TimerMain():
 global x
 global y
 global delta_t
 global secs
 global t
 delta_t=y-x
 secs = delta_t.seconds+1
 t = Timer(secs, GPIOTimer)
 t.start()
def TimerSequence(z):
 if (z==1):
 ten_seconds() 
 elif (z==2):
 five_mins
 elif (z==3):
 ten_mins()
 elif (z==4):
 thirty_mins()
 elif (z==5):
 one_hour()
 elif (z==6):
 three_hours()
 else:
 print("InputError")
 TimerMain()
result = int(sys.argv[1])
TimerSequence(result)
default

AltStyle によって変換されたページ (->オリジナル) /