Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save IamTails/f95cbcdc8a12f6c15c394654347b52f3 to your computer and use it in GitHub Desktop.

Select an option

Save IamTails/f95cbcdc8a12f6c15c394654347b52f3 to your computer and use it in GitHub Desktop.
import Adafruit_DHT
from flask import Flask, jsonify, abort
app = Flask(__name__)
@app.route("/")
def index():
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302, 4)
if humidity is not None and temperature is not None:
return jsonify(data=temperature,humidity=humidity)
eles:
return abort(500)
if __name__ == '__main__':
app.run(port=80)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment