Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IoTSmartMeter
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kristian.tan
IoTSmartMeter
Commits
ed17e334
Commit
ed17e334
authored
Nov 13, 2019
by
Kristian Tan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Record the usage in db entry
parent
aa0aad97
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
6 deletions
+10
-6
app.py
app.py
+10
-6
No files found.
app.py
View file @
ed17e334
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment