Skip to content
Snippets Groups Projects
Commit 69fa026a authored by Torben Petersen's avatar Torben Petersen
Browse files

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
......@@ -9,47 +9,54 @@ import socket
import struct
from threading import Event
CHAMBER_NAME = "lctc-c0X"
TARGET_TEMPERATURE = 10.0
CHAMBER_NAME = "lctc-c01"
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( "localhost", port=1883, keepalive=5 )
client.connect( "lctc-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 )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment