Created
September 10, 2018 15:40
-
-
Save JeffreySkid/1d408c0fdcbea97f6a1d0a36f1b17748 to your computer and use it in GitHub Desktop.
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
| import Adafruit_DHT | |
| import time | |
| import json | |
| from flask import Flask | |
| app = Flask(__name__) | |
| while 1: | |
| print('test') | |
| humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302, 4) | |
| if humidity is not None and temperature is not None: | |
| jsonobj = { | |
| 'temperature': '{0:0.1f}'.format(temperature), | |
| 'humidity': '{0:0.1f}'.format(humidity) | |
| } | |
| with open('info.json', 'w') as file: | |
| file.write(json.dumps(jsonobj).encode()) | |
| time.sleep(5) | |
| break | |
| @app.route("/") | |
| def index(): | |
| with open('info.json') as f: | |
| data = json.load(f) | |
| return data['temperature'] + '°C' + ' / ' + data['humidity'] + '%' | |
| 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