Пример #1
0
 def __init__(self):
     self._wLog = WeatherLogger()
     self._wLog.logDebugMessage("initialize class system state")
     self._configuration = Configuration()
     self._configuration.getConfigurationFiles()
     self._systemConfig = self._configuration.getSystemConfig()
     self._serverConfig = self._configuration.getServerConfig()
     self.initHandler()
Пример #2
0
 def __init__(self, SystemState):
     self._wLog = WeatherLogger()
     self._systemState = SystemState
     self._wetterDataVals = []
     self._wetterDataVals.append({
         'maxPressure': 0.0,
         'minPressure': 0.0,
         'avgPressure': 0.0,
         'avgPressureCount': 0,
         b'maxhumi': 0.0,
         b'minhumi': 0.0,
         'avghumi': 0.0,
         'avghumiCount': 0,
         b'maxtemp': 0.0,
         'mintemp': 0.0,
         'avgtemp': 0.0,
         'avgtempCount': 0,
         'maxwindSpeed': 0.0,
         'minwindSpeed': 0.0,
         'avgwindSpeed': 0.0,
         'avgwindSpeedCount': 0,
         'maxpulse': 0.0,
         'minpulse': 0.0,
         'avgpulse': 0.0,
         'avgpulseCount': 0,
         'maxillum': 0.0,
         'minillum': 0.0,
         'avgillum': 0.0,
         'avgillumCount': 0
     })
Пример #3
0
 def __init__(self, configuration):
     self.wLog = WeatherLogger()
     self._config = configuration
Пример #4
0
 def __init__(self):
     self._wLog = WeatherLogger()
Пример #5
0
class Configuration():
    _wLog = ""
    _conn = ""
    _updateIntervall = 0
    _sensorList = None
    _systemConfig = None
    _serverConfig = None
    _displayConfig = None
    _textConfig = None
    _sensorConfig = None

    def __init__(self):
        self._wLog = WeatherLogger()

    def getLogger(self):
        return self._wLog

    def getSystemConfig(self):
        return self._systemConfig

    def getServerConfig(self):
        return self._serverConfig

    def getLocaleConfig(self):
        return self._textConfig

    def getDisplayConfig(self):
        return self._displayConfig

    def getSensorConfig(self):
        return self._sensorConfig

    def getConfigurationFiles(self):
        self._systemConfig = ConfigParser.RawConfigParser()
        self._systemConfig.read(const._cfg_system)
        self._wLog.logDebugMessage("read " + const._cfg_system)

        self._serverConfig = ConfigParser.RawConfigParser()
        self._serverConfig.read(const._cfg_server)
        self._wLog.logDebugMessage("read " + const._cfg_server)

        self._textConfig = ConfigParser.RawConfigParser()
        self._textConfig.read(const._cfg_locales_de)
        self._wLog.logDebugMessage("read " + const._cfg_locales_de)

        self._displayConfig = ConfigParser.RawConfigParser()
        self._displayConfig.read(const._cfg_display)
        self._wLog.logDebugMessage("read " + const._cfg_display)

        self._sensorConfig = ConfigParser.RawConfigParser()
        self._sensorConfig.read(const._cfg_sensor)
        self._wLog.logDebugMessage("read " + const._cfg_sensor)

        self._updateIntervall = int(
            self._serverConfig.get(const._cfg_section_database,
                                   const._cfg_entry_databaseupdIntervall))

    def setSensorConfiguratuion(self):
        self._sensorList = []
        _sensor = None
        # loop over the configured sensors
        for section in self._sensorConfig.sections():
            _sensor = Sensor(self._sensorConfig)
            _sensor.setConfiguration(section)

            if _sensor._sensorCategory == const._temperature:
                tempSens = TempSensor(self._sensorConfig)
                tempSens.setConfiguration(section)
                self._sensorList.append(tempSens)
            elif _sensor._sensorCategory == const._anemometer:
                anemoSens = AnemometerSensor(self._sensorConfig)
                anemoSens.setConfiguration(section)
                self._sensorList.append(anemoSens)
            elif _sensor._sensorCategory == const._illum:
                illumSens = IlluminationSensor(self._sensorConfig)
                illumSens.setConfiguration(section)
                self._sensorList.append(illumSens)
        return self._sensorList
Пример #6
0
class SystemState():
    
    _fallbackConn = None
    _currConnection = None
    _defaultAdapter = None
    _adapter = None
    _systemConfig = ConfigParser.RawConfigParser()
    _serverConfig = ConfigParser.RawConfigParser()
    _sensorList = []
    _disp = None
    
    def __init__(self):
        self._wLog = WeatherLogger()
        self._wLog.logDebugMessage("initialize class system state")
        self._configuration = Configuration()
        self._configuration.getConfigurationFiles()
        self._systemConfig = self._configuration.getSystemConfig()
        self._serverConfig = self._configuration.getServerConfig()
        self.initHandler()
        
    def getNetworkState(self):
        return self.get_ip_address()
    
    def initHandler(self):            
        self._disp = DisplayHandler(self._configuration)
        self._disp.setSystemState(self.check_network_connection())
        
    def refreshSystemConfig(self):    
        self.getNetworkAdapter()
        self.setSensorConfiguratuion()        
        self.setDatabaseUpdateIntervall()
        self.initHandler()
        self._adapter = self._systemConfig.get(const._cfg_section_Network,const._cfg_entry_Adapter )
        self._defaultAdapter = self._systemConfig.get(const._cfg_section_Network,self._adapter)        
    
    def getConfiguration(self):
        return self._configuration
        
    def setConfiguration(self):
        self._configuration.getConfigurationFiles()
        self._sensorList = self._configuration.setSensorConfiguratuion()
        self._systemConfig = self._configuration.getSystemConfig()
        self._serverConfig = self._configuration.getServerConfig()
        self.setNetworkConfiguration()
        
    def getNetworkAdapter(self):
        self._adapter = self._systemConfig.get(const._cfg_section_Network,const._cfg_entry_Adapter )
        self._defaultAdapter = self._systemConfig.get(const._cfg_section_Network,self._adapter)    
        
    def setDatabaseUpdateIntervall(self):
        self._updateIntervall = int(self._serverConfig.get(const._cfg_section_database, const._cfg_entry_databaseupdIntervall))        
        
    def setNetworkConfiguration(self):
        self.getNetworkAdapter()
        self._networkConnectionExists = self.check_network_connection()
        if self._networkConnectionExists != True:
           self._wLog.logErrorMessage(const._err_no_connection)
           
    def check_network_connection(self):
        _avl_interfaces = netifaces.interfaces()
        
        for _avlIntf in _avl_interfaces:
            if self._defaultAdapter == _avlIntf:
                self._currConnection = _avlIntf
                addr = netifaces.ifaddresses(self._defaultAdapter)
                return netifaces.AF_INET in addr  
        return False
    
    def get_ip_address(self):
        if self.check_network_connection():
            if self._defaultAdapter !=None:
                s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                return socket.inet_ntoa(fcntl.ioctl(
                    s.fileno(),
                    0x8915,  # SIOCGIFADDR
                    struct.pack('256s', self._defaultAdapter[:15])
                )[20:24])
        else:
            return '0.0.0.0'
Пример #7
0
 def __init__(self, anemoSens):
     self._wLog = WeatherLogger()
     self._sensorConfig = anemoSens
     self._windPin = int(anemoSens._sensor_pin)
     self.initVars()