from flask import Flask from flask_admin import Admin from flask_admin import BaseView, expose from flask_admin.contrib.peewee import ModelView from flask import * import model import time import json class MyView(BaseView): @expose('/smarthome') def index(self): return self.render('temp.html') app = Flask(__name__) app.config['SECRET_KEY'] = '20150333' app.config['MODEL'] = model.DHTData() admin = Admin(app, name='SQLite Sensors', template_mode='bootstrap3') admin.add_view(ModelView(model.DHTSensor)) admin.add_view(ModelView(model.SensorReading)) if __name__ == '__main__': app.run(debug=True)
# This code will use the Peewee ORM to simplfiy access to a SQLite database. # The functionality is exactly the same as in pt. 1, but notice how much simpler # the code is by using a data model abstraction and the ORM. # Author: Tony DiCola # License: Public Domain import datetime import time #import Adafruit_DHT import model # Create an instance of our data model access layer object. # This object takes care of all the Peewee ORM and DB access so our code in this # file is very simple and just calls function on the model access layer object. data = model.DHTData() # Define which sensors we expect to be connected to the Pi. data.define_sensor('DHT1', 10, 18) #Adafruit_DHT.DHT22 data.define_sensor('DHT2', 10, 25) # from gpiozero import CPUTemperature # import time # # cpu = CPUTemperature() # def getTemp(): # time.sleep(1) # return cpu.temperature # Main loop to take sensor readings every two seconds. try: