Exemplo n.º 1
0
  def __init__(self):

    # Default system units
    self.__units = {'temperature' : 'C',
                    'distance'    : 'cm',
                    'humidity'    : '%',
                    'moisture'    : '%',
                    'conductivity': 'mS',
                    'ph'          : 'Ph',
                    'light'       :  ''}

    # List of queues for websocket communication
    self.subscribed_queues = []

    self.device = ''
    regex = r"product: (?P<device>.*)"
    hw=os.popen("lshw -c system 2>/dev/null")
    for line in hw.readlines():
      matches = re.search(regex, line)
      if matches:
        self.device = matches.group('device')
        break
    hw.close()

    # Default power usage for a PI
    self.pi_power_wattage = 5

    self.environment = None

    # Load config
    logger.info('Loading terrariumPI config')
    self.config = terrariumConfig()
    logger.info('Done Loading terrariumPI config')

    logger.info('Setting terrariumPI authentication')
    self.set_authentication(self.config.get_admin(),self.config.get_password())
    logger.info('Done setting terrariumPI authentication')

    # Load data collector for historical data
    logger.info('Loading terrariumPI collector')
    self.collector = terrariumCollector(self.config.get_system()['version'])
    logger.info('Done loading terrariumPI collector')

    # Set the Pi power usage (including usb devices directly on the PI)
    logger.info('Loading terrariumPI PI power setting')
    self.pi_power_wattage = float(self.config.get_pi_power_wattage())
    logger.info('Done loading terrariumPI PI power setting')

    # Set the system temperature indicator
    logger.info('Loading terrariumPI PI temperature indicator')
    self.set_temperature_indicator(self.config.get_temperature_indicator())
    logger.info('Done loading terrariumPI PI temperature indicator')

    # Set the system distance indicator
    logger.info('Loading terrariumPI PI distance indicator')
    self.set_distance_indicator(self.config.get_distance_indicator())
    logger.info('Done loading terrariumPI PI distance indicator')

    # Load Weather part
    logger.info('Loading terrariumPI weather data')
    self.weather = terrariumWeather(self.config.get_weather_location(),
                                    self.config.get_weather_windspeed(),
                                    self.__unit_type,
                                    self.get_weather)
    logger.info('Done loading terrariumPI weather data')

    # Load humidity and temperature sensors
    self.__load_sensors()

    # Load Powerswitches part
    self.__load_power_switches()

    # Load doors from config
    self.__load_doors()

    # Load the environment system. This will controll the lights, sprayer and heaters
    logger.debug('Loading terrariumPI environment system')
    self.environment = terrariumEnvironment(self.sensors, self.power_switches, self.weather, self.is_door_open, self.config.get_environment)
    logger.debug('Done loading terrariumPI environment system')

    # Load webcams from config
    self.__load_webcams()

    # Load audio system
    self.__audio_player = terrariumAudioPlayer(self.config.get_audio_playlists(),
                                               self.config.get_active_soundcard(),
                                               any(self.power_switches[switchid].is_pwm_dimmer() for switchid in self.power_switches),
                                               self.get_audio_playing)

    # Start system update loop
    self.__running = True
    thread.start_new_thread(self.__engine_loop, ())
    thread.start_new_thread(self.__log_tail, ())
    logger.info('TerrariumPI engine is running')
Exemplo n.º 2
0
    def __init__(self):
        # List of queues for websocket communication
        self.subscribed_queues = []
        # Default power usage for a PI
        self.pi_power_wattage = 5

        self.environment = None

        # Load config
        logger.info('Loading terrariumPI config')
        self.config = terrariumConfig()
        logger.info('Done Loading terrariumPI config')

        logger.info('Setting terrariumPI authentication')
        self.set_authentication(self.config.get_admin(),
                                self.config.get_password())
        logger.info('Done setting terrariumPI authentication')

        # Load data collector for historical data
        logger.info('Loading terrariumPI collector')
        self.collector = terrariumCollector(
            self.config.get_system()['version'])
        logger.info('Done loading terrariumPI collector')

        # Set the Pi power usage (including usb devices directly on the PI)
        logger.info('Loading terrariumPI PI power setting')
        self.pi_power_wattage = float(self.config.get_pi_power_wattage())
        logger.info('Done loading terrariumPI PI power setting')

        # Set the system temperature indicator
        logger.info('Loading terrariumPI PI temperature indicator')
        self.temperature_indicator = self.config.get_temperature_indicator()

        logger.info('Done loading terrariumPI PI temperature indicator')

        # Load Weather part
        logger.info('Loading terrariumPI weather data')
        self.weather = terrariumWeather(self.config.get_weather_location(),
                                        self.config.get_weather_windspeed(),
                                        self.get_temperature_indicator,
                                        self.get_weather)
        logger.info('Done loading terrariumPI weather data')

        # Load humidity and temperature sensors
        self.__load_sensors()

        # Load Powerswitches part
        self.__load_power_switches()

        # Load doors from config
        self.__load_doors()

        # Load the environment system. This will controll the lights, sprayer and heaters
        logger.debug('Loading terrariumPI environment system')
        self.environment = terrariumEnvironment(self.sensors,
                                                self.power_switches,
                                                self.weather,
                                                self.is_door_open,
                                                self.config.get_environment)
        logger.debug('Done loading terrariumPI environment system')

        # Load webcams from config
        self.__load_webcams()

        # Load audio system
        self.__audio_player = terrariumAudioPlayer(
            self.config.get_audio_playlists(),
            self.config.get_active_soundcard(),
            any(self.power_switches[switchid].is_pwm_dimmer()
                for switchid in self.power_switches), self.get_audio_playing)

        # Start system update loop
        thread.start_new_thread(self.__engine_loop, ())
        thread.start_new_thread(self.__log_tail, ())
        logger.info('TerrariumPI engine is running')