Created
March 1, 2019 23:29
-
-
Save lamlion/7f5c726634e2a887a99641e64522cf86 to your computer and use it in GitHub Desktop.
Sample Flask app to read DHT22 temperature
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import Flask | |
| import Adafruit_DHT | |
| app = Flask(__name__) | |
| @app.route('/hello') | |
| def helloWorldHandler(): | |
| return 'Hello World from Flask running on the PI!' | |
| @app.route('/hello2') | |
| def helloWorldHandler2(): | |
| return 'Hello WorldI2!' | |
| @app.route('/temp') | |
| def TemperatureHumidityHandler(): | |
| humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 4) | |
| humidity = round(humidity, 2) | |
| temperature = round(temperature, 2) | |
| return 'Temperatuur: '+str(temperature)+'Vochtigheid: '+str(humidity) | |
| #return 'Hallo\nFeisal' | |
| app.run(host='0.0.0.0', port= 8090) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment