Commit ed17e334 authored by Kristian Tan's avatar Kristian Tan

Record the usage in db entry

parent aa0aad97
......@@ -2,7 +2,7 @@ from flask import Flask, render_template
import RPi.GPIO as GPIO
from flask_sqlalchemy import SQLAlchemy
import os
import datetime
from datetime import datetime
# from daily_usage import DailyUsage
app = Flask(__name__)
......@@ -74,13 +74,17 @@ def toggle_pin(change_pin):
message = "Turned " + device_name
if GPIO.input(change_pin) == 0:
message += " off."
uptime = datetime.now() - pins[change_pin]['on_time']
d = DailyUsage(date=pins[change_pin]['on_time'], hours=uptime)
db.session.add(d)
db.session.commit()
pins[change_pin]['on_time'] = None
print("==========")
print(DailyUsage.query.all())
print("==========")
else:
message += " on."
pins[change_pin]['on_time'] = datetime.datetime.now()
print("==================")
print("HERE IS THE PIN DATA: ")
print(pins[change_pin])
print("==================")
pins[change_pin]['on_time'] = datetime.now()
for pin in pins:
pins[pin]['state'] = GPIO.input(pin)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment