Commit a80a855a authored by Kristian Tan's avatar Kristian Tan

Display device details

parent 1d14a9d5
...@@ -4,6 +4,7 @@ from flask_sqlalchemy import SQLAlchemy ...@@ -4,6 +4,7 @@ from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import asc, desc from sqlalchemy import asc, desc
import os import os
from datetime import datetime, date, timedelta from datetime import datetime, date, timedelta
# from daily_usage import DailyUsage # from daily_usage import DailyUsage
app = Flask(__name__) app = Flask(__name__)
...@@ -56,8 +57,8 @@ def create_entry(change_pin): ...@@ -56,8 +57,8 @@ def create_entry(change_pin):
start_date = pins[change_pin]['on_date'] start_date = pins[change_pin]['on_date']
# Formula to calculate kWh based on time and wattage # Formula to calculate kWh based on time and wattage
kwh = pins[change_pin]['Wattage'] * (elapsed / 3600) / 1000 kwh = pins[change_pin]['wattage'] * (elapsed / 3600) / 1000
print(pins[change_pin]['Wattage']) print(pins[change_pin]['wattage'])
print(elapsed) print(elapsed)
print(kwh) print(kwh)
print("LATEST ENTRY: ") print("LATEST ENTRY: ")
...@@ -109,19 +110,17 @@ todays_cost = get_todays_cost() ...@@ -109,19 +110,17 @@ todays_cost = get_todays_cost()
# Create dictionary to store pin info # Create dictionary to store pin info
pins = { pins = {
25: {'name': 'Light', 'state': GPIO.LOW, 'on_time': None, 'on_date': None, 'Wattage': 15}, 25: {'name': 'Light', 'state': GPIO.LOW, 'on_time': None, 'on_date': None, 'wattage': 15},
8: {'name': None, 'state': GPIO.LOW, 'on_time': None, 'on_date': None, 'Wattage': 0}, 8: {'name': None, 'state': GPIO.LOW, 'on_time': None, 'on_date': None, 'wattage': 0},
7: {'name': None, 'state': GPIO.LOW, 'on_time': None, 'on_date': None, 'Wattage': 0}, 7: {'name': None, 'state': GPIO.LOW, 'on_time': None, 'on_date': None, 'wattage': 0},
12: {'name': None, 'state': GPIO.LOW, 'on_time': None, 'on_date': None, 'Wattage': 0} 12: {'name': None, 'state': GPIO.LOW, 'on_time': None, 'on_date': None, 'wattage': 0}
} }
# Setup each pin # Setup each pin
for pin in pins: for pin in pins:
GPIO.setup(pin, GPIO.OUT) GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, GPIO.LOW) GPIO.output(pin, GPIO.LOW)
labels, values, max = generate_graph_data() labels, values, max = generate_graph_data()
...@@ -217,7 +216,7 @@ def handle_new_device(): ...@@ -217,7 +216,7 @@ def handle_new_device():
for key in pins: for key in pins:
if pins[key]['name'] is None: if pins[key]['name'] is None:
pins[key]['name'] = new_name pins[key]['name'] = new_name
pins[key]['Wattage'] = new_wattage pins[key]['wattage'] = new_wattage
break break
template_data = { template_data = {
...@@ -238,7 +237,7 @@ def delete_pin(delete_pin): ...@@ -238,7 +237,7 @@ def delete_pin(delete_pin):
for key in pins: for key in pins:
if key == delete_pin: if key == delete_pin:
pins[delete_pin]['name'] = None pins[delete_pin]['name'] = None
pins[delete_pin]['Wattage'] = None pins[delete_pin]['wattage'] = None
break break
template_data = { template_data = {
......
...@@ -6,24 +6,29 @@ ...@@ -6,24 +6,29 @@
</head> </head>
<div class="heading"> <div class="heading">
<h1 >IoT Smart Meter and Lighting Control</h1> <h1>IoT Smart Meter and Lighting Control</h1>
</div> </div>
<body> <body>
<div class="containerRows"> <div class="containerRows">
<div class="device_list"> <div class="device_list">
<h3 class="device_list_title">Device Listing and Status</h3> <h3 class="device_list_title">Device Listing and Status</h3>
{% for pin in pins %} {% for pin in pins %}
{% if pins[pin].name != None %} {% if pins[pin].name != None %}
<p> <p>
{{ pins[pin].name }} : {{ pins[pin].name }} :
{% if pins[pin].state == true %} {% if pins[pin].state == true %}
(<a href="/toggle/{{pin}}">turn off</a>) (<a href="/toggle/{{ pin }}">turn off</a>)
(<a href="/remove/{{pin}}">remove</a>) (<a href="/remove/{{ pin }}">remove</a>)
{% else %} {% else %}
(<a href="/toggle/{{pin}}">turn on</a>) (<a href="/toggle/{{ pin }}">turn on</a>)
(<a href="/remove/{{pin}}">remove</a>) (<a href="/remove/{{ pin }}">remove</a>)
</p>
<p>
<ul>
<li>Last turned on: {{ pins[pin].on_date }} {{ pins[pin].on_time }}</li>
<li>Device Wattage: {{ pins[pin].wattage }} </li>
</ul>
</p> </p>
{% endif %} {% endif %}
{% endif %} {% endif %}
...@@ -49,7 +54,7 @@ ...@@ -49,7 +54,7 @@
<div class="smart_meter"> <div class="smart_meter">
<div class="smart_meter_info"> <div class="smart_meter_info">
{# Implement some way to display "No devices" message if none are in use#} {# Implement some way to display "No devices" message if none are in use#}
<p> Cost per kWh: £{{ cost_per_kWh }} <a href="/update_info/kWh"> (Update)</a></p> <p> Cost per kWh: £{{ cost_per_kWh }} <a href="/update_info/kWh"> (Update)</a></p>
<p> Total energy used today: {{ daily_total }} kWh.</p> <p> Total energy used today: {{ daily_total }} kWh.</p>
<p> Total cost of today's energy usage: £{{ todays_cost }}</p> <p> Total cost of today's energy usage: £{{ todays_cost }}</p>
...@@ -63,22 +68,22 @@ ...@@ -63,22 +68,22 @@
{% endfor %} {% endfor %}
</ul> </ul>
{# <div class="chart">#} {# <div class="chart">#}
<h3 class="chart_title">Energy usage for the last 7 days</h3> <h3 class="chart_title">Energy usage for the last 7 days</h3>
<canvas id="chart" class="chart" ></canvas> <canvas id="chart" class="chart"></canvas>
<script> <script>
// bar chart data // bar chart data
var barData = { var barData = {
labels : [ labels: [
{% for item in labels %} {% for item in labels %}
"{{ item }}", "{{ item }}",
{% endfor %} {% endfor %}
], ],
datasets : [{ datasets: [{
fillColor: "rgba(151,187,205,0.2)", fillColor: "rgba(151,187,205,0.2)",
strokeColor: "rgba(151,187,205,1)", strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)", pointColor: "rgba(151,187,205,1)",
data : [ data: [
{% for item in values %} {% for item in values %}
"{{ item }}", "{{ item }}",
{% endfor %} {% endfor %}
...@@ -97,16 +102,16 @@ ...@@ -97,16 +102,16 @@
scaleStepWidth: Math.ceil(max / steps), scaleStepWidth: Math.ceil(max / steps),
scaleStartValue: 0, scaleStartValue: 0,
scaleShowVerticalLines: true, scaleShowVerticalLines: true,
scaleShowGridLines : true, scaleShowGridLines: true,
barShowStroke : true, barShowStroke: true,
scaleShowLabels: true scaleShowLabels: true
} }
); );
</script> </script>
{# </div>#} {# </div>#}
</div>
</div> </div>
</div> </div>
</div>
</body> </body>
</html> </html>
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