Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
python-mqtt-gpio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Alexander Wellbrock
python-mqtt-gpio
Commits
1fedc25e
Commit
1fedc25e
authored
8 years ago
by
Ellis Percival
Browse files
Options
Downloads
Patches
Plain Diff
Don't assume that digital_inputs and digital_outputs config sections exist. #1
parent
742b1312
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pi_mqtt_gpio/server.py
+5
-5
5 additions, 5 deletions
pi_mqtt_gpio/server.py
with
5 additions
and
5 deletions
pi_mqtt_gpio/server.py
+
5
−
5
View file @
1fedc25e
...
@@ -59,7 +59,7 @@ if __name__ == "__main__":
...
@@ -59,7 +59,7 @@ if __name__ == "__main__":
client
.
username_pw_set
(
user
,
password
)
client
.
username_pw_set
(
user
,
password
)
def
on_conn
(
client
,
userdata
,
flags
,
rc
):
def
on_conn
(
client
,
userdata
,
flags
,
rc
):
for
output_config
in
config
[
"
digital_outputs
"
]
:
for
output_config
in
config
.
get
(
"
digital_outputs
"
,
[])
:
topic
=
"
%s/output/%s/set
"
%
(
topic_prefix
,
output_config
[
"
name
"
])
topic
=
"
%s/output/%s/set
"
%
(
topic_prefix
,
output_config
[
"
name
"
])
client
.
subscribe
(
topic
,
qos
=
1
)
client
.
subscribe
(
topic
,
qos
=
1
)
_LOG
.
info
(
"
Subscribed to topic: %r
"
,
topic
)
_LOG
.
info
(
"
Subscribed to topic: %r
"
,
topic
)
...
@@ -68,7 +68,7 @@ if __name__ == "__main__":
...
@@ -68,7 +68,7 @@ if __name__ == "__main__":
_LOG
.
info
(
"
Got message on topic %r: %r
"
,
msg
.
topic
,
msg
.
payload
)
_LOG
.
info
(
"
Got message on topic %r: %r
"
,
msg
.
topic
,
msg
.
payload
)
output_name
=
msg
.
topic
[
len
(
"
%s/output/
"
%
topic_prefix
):
-
4
]
output_name
=
msg
.
topic
[
len
(
"
%s/output/
"
%
topic_prefix
):
-
4
]
output_config
=
None
output_config
=
None
for
output
in
config
[
"
digital_outputs
"
]
:
for
output
in
config
.
get
(
"
digital_outputs
"
,
[])
:
if
output
[
"
name
"
]
==
output_name
:
if
output
[
"
name
"
]
==
output_name
:
output_config
=
output
output_config
=
output
if
output_config
is
None
:
if
output_config
is
None
:
...
@@ -98,7 +98,7 @@ if __name__ == "__main__":
...
@@ -98,7 +98,7 @@ if __name__ == "__main__":
install_missing_requirements
(
gpio_module
)
install_missing_requirements
(
gpio_module
)
GPIOS
[
gpio_config
[
"
name
"
]]
=
gpio_module
.
GPIO
(
gpio_config
)
GPIOS
[
gpio_config
[
"
name
"
]]
=
gpio_module
.
GPIO
(
gpio_config
)
for
input_config
in
config
[
"
digital_inputs
"
]
:
for
input_config
in
config
.
get
(
"
digital_inputs
"
,
[])
:
pud
=
None
pud
=
None
if
input_config
[
"
pullup
"
]:
if
input_config
[
"
pullup
"
]:
pud
=
PinPullup
.
UP
pud
=
PinPullup
.
UP
...
@@ -110,7 +110,7 @@ if __name__ == "__main__":
...
@@ -110,7 +110,7 @@ if __name__ == "__main__":
input_config
[
"
pin
"
],
PinDirection
.
INPUT
,
pud
,
input_config
)
input_config
[
"
pin
"
],
PinDirection
.
INPUT
,
pud
,
input_config
)
LAST_STATES
[
input_config
[
"
name
"
]]
=
None
LAST_STATES
[
input_config
[
"
name
"
]]
=
None
for
output_config
in
config
[
"
digital_outputs
"
]
:
for
output_config
in
config
.
get
(
"
digital_outputs
"
,
[])
:
gpio
=
GPIOS
[
output_config
[
"
module
"
]]
gpio
=
GPIOS
[
output_config
[
"
module
"
]]
gpio
.
setup_pin
(
gpio
.
setup_pin
(
output_config
[
"
pin
"
],
PinDirection
.
OUTPUT
,
None
,
output_config
)
output_config
[
"
pin
"
],
PinDirection
.
OUTPUT
,
None
,
output_config
)
...
@@ -120,7 +120,7 @@ if __name__ == "__main__":
...
@@ -120,7 +120,7 @@ if __name__ == "__main__":
try
:
try
:
while
True
:
while
True
:
for
input_config
in
config
[
"
digital_inputs
"
]
:
for
input_config
in
config
.
get
(
"
digital_inputs
"
,
[])
:
gpio
=
GPIOS
[
input_config
[
"
module
"
]]
gpio
=
GPIOS
[
input_config
[
"
module
"
]]
state
=
bool
(
gpio
.
get_pin
(
input_config
[
"
pin
"
]))
state
=
bool
(
gpio
.
get_pin
(
input_config
[
"
pin
"
]))
sleep
(
0.05
)
sleep
(
0.05
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment