#!/usr/bin/python3.8 # from enum import Enum from flask import Flask as f from flask import Response import RPi.GPIO as GPIO import os import time from threading import Thread #import re #import json #import req as r class TreeState(Enum): OFF = 1 BUZZ = 2 GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) #GPIO.setup(17, GPIO.OUT) #GPIO.output(17, GPIO.LOW) #time.sleep(1) #GPIO.output(17, GPIO.HIGH) app = f(__name__) state = TreeState.OFF def loop(): global state while True: time.sleep(1) print ("loop") if (state == TreeState.BUZZ): print ("buzz") GPIO.output(17, GPIO.LOW) time.sleep(2) GPIO.output(17, GPIO.HIGH) state = TreeState.OFF @app.route('/buzz', methods = ['GET']) def rbuzz(): #global state #state = TreeState.BUZZ #GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.OUT) GPIO.output(17, GPIO.LOW) time.sleep(2) GPIO.output(17, GPIO.HIGH) return "{\"status\":0}" @app.route('/') def index(): return open("index.html", "r").read() if __name__ == '__main__': # Run Server #Thread(name="backgroundLoop", target=loop).start() app.run(host='0.0.0.0', port=80, debug=True)