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
3b88970e
Commit
3b88970e
authored
Nov 12, 2019
by
Kristian Tan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed unneccesary on/off parameter
parent
d52c0ff8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
12 deletions
+17
-12
app.py
app.py
+15
-10
main.html
templates/main.html
+2
-2
No files found.
app.py
View file @
3b88970e
...
@@ -30,21 +30,26 @@ def main():
...
@@ -30,21 +30,26 @@ def main():
# The function below is executed when someone requests a URL with the pin number and action in it:
# The function below is executed when someone requests a URL with the pin number and action in it:
@
app
.
route
(
"/<change_pin>
/<action>
"
)
@
app
.
route
(
"/<change_pin>"
)
def
action
(
change_pin
,
action
):
def
action
(
change_pin
,
action
):
change_pin
=
int
(
change_pin
)
change_pin
=
int
(
change_pin
)
device_name
=
pins
[
change_pin
][
'name'
]
device_name
=
pins
[
change_pin
][
'name'
]
print
(
"Input value before change: "
+
str
(
GPIO
.
input
(
change_pin
)))
print
(
"Input value before change: "
+
str
(
GPIO
.
input
(
change_pin
)))
if
action
==
"on"
:
# if action == "on":
GPIO
.
output
(
change_pin
,
GPIO
.
HIGH
)
# GPIO.output(change_pin, GPIO.HIGH)
message
=
"Turned "
+
device_name
+
" on."
# message = "Turned " + device_name + " on."
if
action
==
"off"
:
# if action == "off":
GPIO
.
output
(
change_pin
,
GPIO
.
LOW
)
# GPIO.output(change_pin, GPIO.LOW)
message
=
"Turned "
+
device_name
+
" off."
# message = "Turned " + device_name + " off."
if
action
==
"toggle"
:
# if action == "toggle":
GPIO
.
output
(
change_pin
,
not
GPIO
.
input
(
change_pin
))
GPIO
.
output
(
change_pin
,
not
GPIO
.
input
(
change_pin
))
message
=
"Toggled "
+
device_name
+
"."
message
=
"Turned "
+
device_name
if
GPIO
.
input
(
change_pin
)
==
0
:
message
+=
"off."
else
:
message
+=
"on."
for
pin
in
pins
:
for
pin
in
pins
:
pins
[
pin
][
'state'
]
=
GPIO
.
input
(
pin
)
pins
[
pin
][
'state'
]
=
GPIO
.
input
(
pin
)
...
...
templates/main.html
View file @
3b88970e
...
@@ -9,9 +9,9 @@
...
@@ -9,9 +9,9 @@
{% for pin in pins %}
{% for pin in pins %}
<p>
The {{ pins[pin].name }}
<p>
The {{ pins[pin].name }}
{% if pins[pin].state == true %}
{% if pins[pin].state == true %}
is currently on (
<a
href=
"/{{pin}}
/off
"
>
turn off
</a>
)
is currently on (
<a
href=
"/{{pin}}"
>
turn off
</a>
)
{% else %}
{% else %}
is currently off (
<a
href=
"/{{pin}}
/on
"
>
turn on
</a>
)
is currently off (
<a
href=
"/{{pin}}"
>
turn on
</a>
)
{% endif %}
{% endif %}
</p>
</p>
{% endfor %}
{% endfor %}
...
...
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