Flask demo – webservice with python

#!/usr/bin/env python
from flask import Flask
from flask import request
import thread
import threading


class pins():
    gpio1 = 0
    gpio2 = 0
    gpio3 = 1




app = Flask(__name__)


@app.route('/method1')
# entry point of application
def index():
    param1 = request.args.get('param1', '')

    if param1 == "reset":
        with pins.lock:
            prev_value = pins.gpio1
            pins.gpio1 = 0

        return "prev_value = " + str(prev_value)

    else:
        return "wrong param1"


# loop to check pins
def run():
    while 1 == 1:
        with pins.lock:
            if pins.gpio1 == 999999999:
                pins.gpio1 = 0

            pins.gpio1 += 1







if __name__ == '__main__':

    # run pin check into external thread
    pins.lock = threading.Lock()
    thread.start_new_thread(run, ())

    app.run(host="127.0.0.1", port=int("5501"), debug=True)

Lascia un commento

Il tuo indirizzo email non sarĂ  pubblicato. I campi obbligatori sono contrassegnati *