Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ieee802154-radio-eval
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
cm-projects
ieee802154-radio-eval
Commits
fbd85052
Commit
fbd85052
authored
3 years ago
by
Torben Petersen
Browse files
Options
Downloads
Patches
Plain Diff
Adds first prototype of temperature controller Script
parent
196a86af
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
software/temp-controller.py
+130
-0
130 additions, 0 deletions
software/temp-controller.py
with
130 additions
and
0 deletions
software/temp-controller.py
0 → 100644
+
130
−
0
View file @
fbd85052
#!/usr/bin/env python3
import
paho.mqtt.client
as
paho
import
paho.mqtt.publish
as
publish
from
time
import
sleep
,
time
import
socket
import
struct
import
configparser
from
threading
import
Event
import
os
CHAMBER_ONE_NAME
=
"
lctc-c01
"
CHAMBER_TWO_NAME
=
"
lctc-c04
"
# vars for setting the chamber temp
DELTA
=
0.5
CHAMBER_ONE_TARGET_TEMP
=
10
CHAMBER_TWO_TARGET_TEMP
=
10
client_one
=
paho
.
Client
(
client_id
=
"
temp_logger_
"
+
CHAMBER_ONE_NAME
,
clean_session
=
True
)
client_two
=
paho
.
Client
(
client_id
=
"
temp_logger_
"
+
CHAMBER_TWO_NAME
,
clean_session
=
True
)
CHAMBER_ONE_TEMPERATURE_TOPIC
=
"
ds1820/lctc-c01/28-000007fb4c59/temp
"
CHAMBER_TWO_TEMPERATURE_TOPIC
=
"
ds1820/lctc-c04/28-000007fbfbcb/temp
"
#logging vars
temp_chamber_one
=
0
temp_chamber_two
=
0
#event flags
temperature_chamber_one_reached
=
Event
()
temperature_chamber_two_reached
=
Event
()
def
on_message
(
client
,
userdata
,
msg
):
global
temp_chamber_one
global
temp_chamber_two
if
msg
.
topic
==
CHAMBER_ONE_TEMPERATURE_TOPIC
:
temp
,
=
struct
.
unpack
(
"
d
"
,
msg
.
payload
)
temp_chamber_one
=
temp
if
abs
(
temp
-
CHAMBER_ONE_TARGET_TEMP
)
<
DELTA
:
temperature_chamber_one_reached
.
set
()
elif
msg
.
topic
==
CHAMBER_TWO_TEMPERATURE_TOPIC
:
temp
,
=
struct
.
unpack
(
"
d
"
,
msg
.
payload
)
temp_chamber_two
=
temp
if
abs
(
temp
-
CHAMBER_TWO_TARGET_TEMP
)
<
DELTA
:
temperature_chamber_two_reached
.
set
()
else
:
print
(
"
[on_message] {} {}
"
.
format
(
msg
.
payload
,
msg
.
topic
)
)
print
(
"
{:0>5} | {:0>5}
"
.
format
(
temp_chamber_one
,
temp_chamber_two
))
def
on_disconnect
(
client
,
userdata
,
rc
):
print
(
"
[on_disconnect] {}
"
.
format
(
rc
))
def
on_connect
(
client
,
userdata
,
flags
,
rc
):
if
userdata
==
CHAMBER_ONE_NAME
:
client
.
subscribe
(
CHAMBER_ONE_TEMPERATURE_TOPIC
,
qos
=
2
)
print
(
"
Subscribed to topic: {}
"
.
format
(
CHAMBER_ONE_TEMPERATURE_TOPIC
))
elif
userdata
==
CHAMBER_TWO_NAME
:
client
.
subscribe
(
CHAMBER_TWO_TEMPERATURE_TOPIC
,
qos
=
2
)
print
(
"
Subscribed to topic: {}
"
.
format
(
CHAMBER_TWO_TEMPERATURE_TOPIC
))
else
:
print
(
"
Connected to unknwon broker!
"
)
def
set_temp_chamber_one
(
temp
):
client_one
.
publish
(
"
chamber/
"
+
CHAMBER_ONE_NAME
+
"
/temp
"
,
struct
.
pack
(
"
d
"
,
temp
),
qos
=
2
)
temperature_chamber_one_reached
.
clear
()
#Set Event flag to false and Block until set is called
def
set_temp_chamber_two
(
temp
):
client_two
.
publish
(
"
chamber/
"
+
CHAMBER_TWO_NAME
+
"
/temp
"
,
struct
.
pack
(
"
d
"
,
temp
),
qos
=
2
)
temperature_chamber_two_reached
.
clear
()
#Set Event flag to false and Block until set is called
if
__name__
==
"
__main__
"
:
SERVERNAME
=
"
{}.ibr.cs.tu-bs.de
"
.
format
(
CHAMBER_ONE_NAME
)
print
(
SERVERNAME
)
client_one
.
connect
(
SERVERNAME
,
port
=
1883
,
keepalive
=
5
)
client_one
.
user_data_set
(
CHAMBER_ONE_NAME
)
client_one
.
on_connect
=
on_connect
client_one
.
on_message
=
on_message
client_one
.
on_disconnect
=
on_disconnect
client_one
.
loop_start
()
SERVERNAME
=
"
{}.ibr.cs.tu-bs.de
"
.
format
(
CHAMBER_TWO_NAME
)
print
(
SERVERNAME
)
client_two
.
connect
(
SERVERNAME
,
port
=
1883
,
keepalive
=
5
)
client_two
.
user_data_set
(
CHAMBER_TWO_NAME
)
client_two
.
on_connect
=
on_connect
client_two
.
on_message
=
on_message
client_two
.
on_disconnect
=
on_disconnect
client_two
.
loop_start
()
#init arrays with temps for both chambers
chamber_one_temperature_values
=
[
10
,
25
,
40
]
chamber_two_temperature_values
=
[
10
,
25
,
40
]
while
True
:
for
chamber_one_numerator
in
range
(
0
,
len
(
temperature_values
)):
for
chamber_two_numerator
in
range
(
0
,
len
(
temperature_values
)):
CHAMBER_ONE_TARGET_TEMP
=
temperature_values
[
chamber_one_numerator
]
CHAMBER_TWO_TARGET_TEMP
=
temperature_values
[
chamber_two_numerator
]
print
(
"
Target temps for the chambers: {} | {}
"
.
format
(
CHAMBER_ONE_TARGET_TEMP
,
CHAMBER_TWO_TARGET_TEMP
))
set_temp_chamber_one
(
CHAMBER_ONE_TARGET_TEMP
)
set_temp_chamber_two
(
CHAMBER_TWO_TARGET_TEMP
)
#wait until both temperatures are reached
while
not
(
temperature_chamber_one_reached
.
wait
()
and
temperature_chamber_one_reached
.
wait
()
)
pass
#wait for 30 Minutes
time
.
sleep
(
60
*
15
)
#invert array for chamber two
chamber_two_temperature_values
=
chamber_two_temperature_values
[::
-
1
]
#invert array for chamber one
chamber_one_temperature_values
=
chamber_one_temperature_values
[::
-
1
]
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