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
a217470b
Commit
a217470b
authored
Nov 12, 2019
by
Kristian Tan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create model for daily_usage table
parent
8dd4df0e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
1 deletion
+17
-1
app.py
app.py
+6
-0
daily_usage.py
daily_usage.py
+10
-0
main.html
templates/main.html
+1
-1
No files found.
app.py
View file @
a217470b
from
flask
import
Flask
,
render_template
from
flask
import
Flask
,
render_template
import
RPi.GPIO
as
GPIO
import
RPi.GPIO
as
GPIO
from
flask_sqlalchemy
import
SQLAlchemy
from
flask_sqlalchemy
import
SQLAlchemy
from
.daily_usage
import
DailyUsage
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
app
.
config
[
'SQLALCHEMY_DATABASE_URI'
]
=
'sqlite:///energyUsage'
app
.
config
[
'SQLALCHEMY_DATABASE_URI'
]
=
'sqlite:///energyUsage'
db
=
SQLAlchemy
(
app
)
db
=
SQLAlchemy
(
app
)
SQLAlchemy
.
create_all
()
db
.
create_all
()
db
.
create_all
()
GPIO
.
setmode
(
GPIO
.
BCM
)
GPIO
.
setmode
(
GPIO
.
BCM
)
GPIO
.
setwarnings
(
False
)
GPIO
.
setwarnings
(
False
)
test
=
DailyUsage
(
"12/11/2019"
,
5
)
db
.
session
.
add
(
test
)
db
.
session
.
commit
()
# Create dictionary to store pin info
# Create dictionary to store pin info
pins
=
{
pins
=
{
25
:
{
'name'
:
'Light'
,
'state'
:
GPIO
.
LOW
}
25
:
{
'name'
:
'Light'
,
'state'
:
GPIO
.
LOW
}
}
}
# Setup each pin
# Setup each pin
for
pin
in
pins
:
for
pin
in
pins
:
GPIO
.
setup
(
pin
,
GPIO
.
OUT
)
GPIO
.
setup
(
pin
,
GPIO
.
OUT
)
...
...
daily_usage.py
0 → 100644
View file @
a217470b
from
.app
import
db
class
DailyUsage
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
,
autoincrement
=
True
)
date
=
db
.
Column
(
db
.
String
(
80
),
unique
=
True
,
nullable
=
False
)
hours
=
db
.
Column
(
db
.
Integer
(
120
),
unique
=
False
)
def
__repr__
(
self
):
return
'<User
%
r>'
%
self
.
username
\ No newline at end of file
templates/main.html
View file @
a217470b
...
@@ -38,7 +38,7 @@
...
@@ -38,7 +38,7 @@
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
</p>
</p>
{# Implement some way to display "No devices" message if none are in use#}
<p>
Used today:
<p>
Used today:
</p>
</p>
...
...
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