from flask import Flask
from time import sleep
import pifacedigitalio

DOOR_PULSE = 0.25  # seconds

def toggle_door():
    pifacedigital.leds[0].turn_on()
    pifacedigital.relays[0].turn_on()
    sleep(DOOR_PULSE)
    pifacedigital.leds[0].turn_off()
    pifacedigital.relays[0].turn_off()
    return

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

@app.route("/toggle")
def toggle():
    toggle_door()
    return "true"

if __name__ == "__main__":
    pifacedigital = pifacedigitalio.PiFaceDigital()
    pifacedigital.leds[7].turn_on()

    app.run(host='0.0.0.0', port=8000, debug=True)
@@ -40,16 +40,17 @@
 t sleep%0A
+%0A
 import p
@@ -63,16 +63,28 @@
 igitalio
+%0Aimport json
 %0A%0ADOOR_P
@@ -107,16 +107,286 @@
 econds%0A%0A
+JSON = %22%22%22%0A    %7B%0A        %22door_pulse%22: 0.25,%0A        %22doors%22: %7B%0A            %220%22: %7B%0A                %22id%22: %22foo%22%0A            %7D,%0A            %221%22: %7B%0A                %22id%22: %22bar%22%0A            %7D%0A        %7D%0A    %7D%0A%22%22%22%0A%0Aconfig = json.loads(JSON)%0A%0ADOOR_PULSE = config%5B%22door_pulse%22%5D%0A%0A
 def togg
@@ -393,16 +393,18 @@
 le_door(
+id
 ):%0A    p
@@ -413,33 +413,34 @@
 acedigital.leds%5B
-0
+id
 %5D.turn_on()%0A    
@@ -452,33 +452,34 @@
 edigital.relays%5B
-0
+id
 %5D.turn_on()%0A    
@@ -519,17 +519,18 @@
 al.leds%5B
-0
+id
 %5D.turn_o
@@ -559,17 +559,18 @@
 .relays%5B
-0
+id
 %5D.turn_o
@@ -570,24 +570,25 @@
 .turn_off()%0A
+%0A
     return%0A%0A
@@ -585,16 +585,47 @@
   return
+ %22Toggled Door: %7B0%7D%22.format(id)
 %0A%0Aapp = 
@@ -710,16 +710,31 @@
 route(%22/
+door/%3Cdoor_id%3E/
 toggle%22)
@@ -752,16 +752,73 @@
 ():%0A    
+if door_id == config%5B%22doors%22%5D%5B%220%22%5D%5B%22id%22%5D:%0A        return 
 toggle_d
@@ -825,27 +825,135 @@
 oor(
-)
+0)%0A
 %0A    
-return %22true%22
+if door_id == config%5B%22doors%22%5D%5B%220%22%5D%5B%22id%22%5D:%0A        return toggle_door(0)%0A%0A    return %22Unknown Door: %7B0%7D%22.format(door_id)
 %0A%0Aif

Add Config