Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
testbed-software
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
Container Registry
Model registry
Operate
Environments
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
Show more breadcrumbs
Robert Hartung
testbed-software
Commits
69fa026a
Commit
69fa026a
authored
6 years ago
by
Torben Petersen
Browse files
Options
Downloads
Patches
Plain Diff
Changes Chamber Adress to lctc-c01 and adds ctach while trying to set temp
parent
ffd6e972
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/chamber.py
+23
-16
23 additions, 16 deletions
examples/chamber.py
with
23 additions
and
16 deletions
examples/chamber.py
+
23
−
16
View file @
69fa026a
...
...
@@ -9,47 +9,54 @@ import socket
import
struct
from
threading
import
Event
CHAMBER_NAME
=
"
lctc-c0
X
"
TARGET_TEMPERATURE
=
10
.0
CHAMBER_NAME
=
"
lctc-c0
1
"
TARGET_TEMPERATURE
=
5
.0
DELTA
=
0.5
TIMEOUT
=
60.0
CHAMBER_TEMPERATURE_TOPIC
=
"
sht21/
"
+
CHAMBER_NAME
+
"
/temp
"
temperature_reached
=
Event
()
temperature_reached
=
Event
()
#set event flag to flase
client
=
paho
.
Client
(
client_id
=
"
chamber_controller_
"
+
socket
.
gethostname
(),
clean_session
=
True
)
def
on_message
(
client
,
userdata
,
msg
):
if
msg
.
topic
==
CHAMBER_TEMPERATURE_TOPIC
:
temp
,
=
struct
.
unpack
(
"
d
"
,
msg
.
payload
)
if
abs
(
temp
-
TARGET_TEMPERATURE
)
<
DELTA
:
temperature_reached
.
set
()
temperature_reached
.
set
()
#set the event flag to true
else
:
print
(
"
[on_message] {} {}
"
.
format
(
msg
.
payload
,
msg
.
topic
)
)
print
(
"
[on_message] {} {}
"
.
format
(
msg
.
payload
,
msg
.
topic
)
)
def
on_disconnect
(
client
,
userdata
,
rc
):
print
(
"
[on_disconnect] {}
"
.
format
(
rc
))
print
(
"
[on_disconnect] {}
"
.
format
(
rc
))
def
on_connect
(
client
,
userdata
,
flags
,
rc
):
client
.
subscribe
(
CHAMBER_TEMPERATURE_TOPIC
,
qos
=
2
)
def
set_temp
(
temp
):
client
.
publish
(
"
chamber/
"
+
CHAMBER_NAME
+
"
/temp
"
,
struct
.
pack
(
"
d
"
,
temp
),
qos
=
2
)
temperature_reached
.
clear
()
temperature_reached
.
clear
()
#Set Event flag to false and Block until set is called
if
__name__
==
"
__main__
"
:
client
.
connect
(
"
l
ocalhost
"
,
port
=
1883
,
keepalive
=
5
)
client
.
connect
(
"
l
ctc-c01.dyn.ibr.cs.tu-bs.de
"
,
port
=
1883
,
keepalive
=
5
)
client
.
on_connect
=
on_connect
client
.
on_message
=
on_message
client
.
on_disconnect
=
on_disconnect
client
.
loop_start
()
while
True
:
set_temp
(
TARGET_TEMPERATURE
)
# Wait until temperature has been reached
if
temperature_reached
.
wait
(
TIMEOUT
):
print
(
"
timeout reached.
"
)
# Do something here for 1 minute
time
.
sleep
(
60.0
)
# Increase target temperature
TARGET_TEMPERATURE
+=
1.0
try
:
set_temp
(
TARGET_TEMPERATURE
)
# Wait until temperature has been reached
if
not
temperature_reached
.
wait
(
TIMEOUT
):
#wait until flag is set or TIMEOUT
print
(
"
timeout reached.
"
)
else
:
print
(
"
reached Temp
"
)
# Do something here for 1 minute
print
(
"
Entering sleep
"
)
time
.
sleep
(
60.0
)
# Increase target temperature
#TARGET_TEMPERATURE += 1.0
except
KeyboardInterrupt
:
set_temp
(
None
)
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