Skip to content

Instantly share code, notes, and snippets.

@lamlion
Created March 1, 2019 23:29
Show Gist options
  • Select an option

  • Save lamlion/7f5c726634e2a887a99641e64522cf86 to your computer and use it in GitHub Desktop.

Select an option

Save lamlion/7f5c726634e2a887a99641e64522cf86 to your computer and use it in GitHub Desktop.
Sample Flask app to read DHT22 temperature
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