def __init__(self): # Load configuration with open('config/config.json') as f: config = json.load(f) self._config = config # Do logger self._setup_logger() logger.info('HardwareID={}'.format(get_cpu_id())) # GPIOs GPIO.setmode(GPIO.BCM) self._go = False self._temp_sensors = Max31850Sensors(self._config['temperature']) self._blower_fan = BlowerFan(self._config['fan']) # Our MQTT client self._client = mqtt_client.Client(client_id=get_cpu_id()) # Data logger self._data_logger = DataLogger(config['data_logger']['path'], get_cpu_id()) # IController self._controller = TempController(self._config, self._temp_sensors, self._blower_fan, self._client, self._data_logger) self._commands = Commands(self._config, self._client, self._data_logger)
def initialise(self): # Initialise peripherals self._temp_sensors.initialise() self._blower_fan.initisalise() # Subscribe to topics topic = self._config['mqtt']['root_topic'] + get_cpu_id( ) + "/controller/config/desired" self._client.message_callback_add(topic, self._message_config) logger.info('Subscribed to {}'.format(topic)) # Subscribe to topics topic = self._config['mqtt']['root_topic'] + get_cpu_id( ) + "/controller/state/desired" self._client.message_callback_add(topic, self._message_state) logger.info('Subscribed to {}'.format(topic)) # Set pid params initially self._update_pid_params()
def _on_connect(self, client, userdata, flags, rc): logger.info('MQTT Connected with result code ' + str(rc)) # Subscribe to our control topics now that we have a connection root_topic = self._config['mqtt']['root_topic'] + get_cpu_id() + "/#" client.subscribe(root_topic)
def topic(self): root_topic = self._config['mqtt']['root_topic'] + get_cpu_id() return root_topic
def init(self): # Setup command topic topic = self._config['mqtt']['root_topic'] + get_cpu_id() + "/commands" self._client.message_callback_add(topic, self._handle_message) logger.info('Subscribed to {}'.format(topic))