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

Temp_FLow_Controller subscribes to chamber state now. Code still needs to be tested though

parent cfedc676
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@ class tempFlowController:
self.chamber_name = chamber_name
self.delta = delta
self.chamber_temperature_topic = "chambercontroller/"+chamber_name+"/current_temp"
self.chamber_state_topic = "chambercontroller/"+chamber_name+"/state"
self.temperature_reached = Event() #set event flag to false
self.client = paho.Client(client_id="chamber_controller_" + socket.gethostname(), clean_session=True)
......@@ -47,6 +48,16 @@ class tempFlowController:
temp, = struct.unpack("d", msg.payload)
if abs(temp - self.target_temperature) < self.delta:
self.temperature_reached.set() #set the event flag to true
elif msg.topic == self.chamber_state_topic:
state, = struct.unpack("i", msg.payload)
if state == 0:
self.logger.info("[on_message] connection to chamber lost")
elif state == 1:
self.logger.info("[on_message] connection to chamber established")
#republish target temp
self.client.publish("chamber/"+self.chamber_name+"/temp", struct.pack("d", self.target_temperature), qos=2)
else:
self.logger.info("[on_message] {} {}".format(msg.payload, msg.topic))
......@@ -56,6 +67,7 @@ class tempFlowController:
def on_connect (self, client, userdata, flags, rc):
self.logger.info("Connection established")
client.subscribe(self.chamber_temperature_topic, qos=2)
client.subscribe(self.chamber_state_topic, qos=2)
def set_temp (self, temp):
self.client.publish("chamber/"+self.chamber_name+"/temp", struct.pack("d", temp), qos=2)
......
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