Пример #1
0
    def POST(self):
        OPTIONS_FILE = './ospy/data/options.db'
        i = web.input(uploadfile={})
        try:
            if i.uploadfile.filename == 'options.db':
                fout = open(OPTIONS_FILE, 'w')
                fout.write(i.uploadfile.file.read())
                fout.close()

                if os.path.isfile(
                        OPTIONS_FILE):  # exists options.db after upload?
                    if os.path.isfile(OPTIONS_FILE +
                                      '.bak'):  # exists old options.db.bak
                        os.remove(OPTIONS_FILE +
                                  '.bak')  # remove old options.db.bak
                    copyfile(
                        OPTIONS_FILE, OPTIONS_FILE +
                        '.bak')  # copy new options.db to old options.db.bak

                    log.debug(
                        'webpages.py',
                        'Upload, save, copy options.db file sucesfully, now restarting OSPy...'
                    )
                    restart(3)
                    return self.core_render.restarting(home_page)
            self._redirect_back()

        except Exception:
            self._redirect_back()
Пример #2
0
def create_default_graph():
    """Create default graph json file."""

    state = _(u'State')

    graph_data = [
       {"station": state, "balances": {}}
    ]
    write_graph_log(graph_data)
    log.debug(NAME, _(u'Creating default graph log files OK'))
Пример #3
0
def set_counter(i2cbus):
    try:
        if options['address']:
            addr = 0x51
        else:
            addr = 0x50 
        #i2cbus.write_byte_data(addr, 0x00, 0x20) # status registr setup to "EVENT COUNTER"
        #i2cbus.write_byte_data(addr, 0x01, 0x00) # reset LSB
        #i2cbus.write_byte_data(addr, 0x02, 0x00) # reset midle Byte
        #i2cbus.write_byte_data(addr, 0x03, 0x00) # reset MSB
        try_io(lambda: i2cbus.write_byte_data(addr, 0x00, 0x20)) # status registr setup to "EVENT COUNTER"
        try_io(lambda: i2cbus.write_byte_data(addr, 0x01, 0x00)) # reset LSB
        try_io(lambda: i2cbus.write_byte_data(addr, 0x02, 0x00)) # reset midle Byte
        try_io(lambda: i2cbus.write_byte_data(addr, 0x03, 0x00)) # reset MSB        
        log.debug(NAME, _(u'Setup PCF8583 as event counter is OK'))
        return 1  
    except:
        log.error(NAME, _(u'Water Meter plug-in') + ':\n' + _(u'Setup PCF8583 as event counter - FAULT'))
        log.error(NAME, _(u'Water Meter plug-in') + traceback.format_exc())
        return None
Пример #4
0
    def POST(self):
        OPTIONS_FILE = './ospy/data/options.db'
        i = web.input(uploadfile={})
        try:
            if i.uploadfile.filename == 'options.db':
               fout = open(OPTIONS_FILE,'w') 
               fout.write(i.uploadfile.file.read()) 
               fout.close() 

               if os.path.isfile(OPTIONS_FILE):                   # exists options.db after upload?
                 if os.path.isfile(OPTIONS_FILE + '.bak'):        # exists old options.db.bak
                    os.remove(OPTIONS_FILE + '.bak')              # remove old options.db.bak
                 copyfile(OPTIONS_FILE, OPTIONS_FILE + '.bak')    # copy new options.db to old options.db.bak

                 log.debug('webpages.py', 'Upload, save, copy options.db file sucesfully, now restarting OSPy...')
                 report_restarted()
                 restart(3)
                 return self.core_render.restarting(home_page)
            else:        
               errorCode = "pw_filename" 
               return self.core_render.options(errorCode)

        except Exception:
            return self.core_render.options()
Пример #5
0
 def GET(self):
     log.clear(NAME)
     cmd = "sudo systemctl start watchdog"
     log.debug(NAME, cmd)
     run_process(cmd)
     cmd = "sudo systemctl enable watchdog"
     log.debug(NAME, cmd)
     run_process(cmd)
     cmd = "sudo systemctl daemon-reload"
     log.debug(NAME, cmd)
     run_process(cmd)
     restart(3)
     return self.core_render.restarting(plugin_url(status_page))
Пример #6
0
    def run(self):
        Temperature = 0
        Humidity = 0  

        last_millis = 0 # timer for save log
        var1 = True     # Auxiliary variable for once on
        var2 = True     # Auxiliary variable for once off

        while not self._stop.is_set():
            try:
                if plugin_options['enabled']:  # if plugin is enabled   
                    try:
                       Temperature, Humidity = DHT11_read_data()
                    except:
                       self._sleep(0.3)                                     
                      
                    if Humidity and Temperature != 0:
                       log.clear(NAME)
                       self.status['temp'] = Temperature
                       self.status['humi'] = Humidity
                       log.info(NAME, datetime_string())
                       log.info(NAME, _('Temperature') + ' DHT: ' + u'%.1f \u2103' % Temperature)
                       log.info(NAME, _('Humidity') + ' DHT: ' + u'%.1f' % Humidity + ' %RH')
                       if plugin_options['enabled_reg']:
                          OT = _('ON') if self.status['outp'] is 1 else _('OFF') 
                          log.info(NAME, _('Output') + ': ' + u'%s' % OT)

                       if plugin_options['enable_log']:
                          millis = int(round(time.time() * 1000))
                          interval = (plugin_options['log_interval'] * 60000)
                          if (millis - last_millis) > interval:
                             last_millis = millis
                             update_log(self.status)

                       station = stations.get(plugin_options['control_output'])

                       if plugin_options['enabled_reg']:  # if regulation is enabled
                          if Humidity > (plugin_options['humidity_on'] + plugin_options['hysteresis']/2) and var1 is True:  
                             station.active = True
                             var1 = False
                             var2 = True
                             self.status['outp'] = 1
                             log.debug(NAME, _('Station output was turned on.'))
                             update_log(self.status)
                             
                          if Humidity < (plugin_options['humidity_off'] - plugin_options['hysteresis']/2) and var2 is True:  
                             station.active = False
                             var1 = True
                             var2 = False 
                             self.status['outp'] = 0
                             log.debug(NAME, _('Station output was turned off.'))
                             update_log(self.status)    

                       # Activate again if needed:
                       if station.remaining_seconds != 0:
                          station.active = True

 
                    if plugin_options['ds_enabled']:  # if in plugin is enabled DS18B20
                       try:
                          import smbus  
                          import struct

                          bus = smbus.SMBus(1 if get_rpi_revision() >= 2 else 0)  

                          temp_data = bus.read_i2c_block_data(0x03, 0)
                          #log.info(NAME, _('Data: ') + str(temp_data))

                          # Each float from the hw board is 5 bytes long.
                          pom=0
                          for i in range(0, plugin_options['ds_used']):
                            priznak=0
                            jed=0
                            des=0
                            sto=0
                            tis=0
                            soucet=0
                            jed = temp_data[pom+4]        # 4 byte
                            des = temp_data[pom+3]*10     # 3
                            sto = temp_data[pom+2]*100    # 2
                            tis = temp_data[pom+1]*1000   # 1  
                            priznak = temp_data[pom]      # 0 byte

                            pom += 5

                            soucet = tis+sto+des+jed

                            if(soucet > 1270):
                               priznak=255 # error value not printing
                        
                            if(priznak==1):
                               soucet = soucet * -1  # negation number

                            teplota = soucet/10.0

                            if(priznak!=255):
                               self.status['DS%d' % i] = teplota
                               log.info(NAME, _('Temperature') + ' DS' + str(i) + ': ' + u'%.1f \u2103' % teplota)
                            else:
                               self.status['DS%d' % i] = -127
                               log.info(NAME, _('Temperature') + ' DS' + str(i) + ': Err')

                       except Exception:
                          log.error(NAME, '\n' + _('Can not read data from I2C bus.') + ':\n' + traceback.format_exc())
                          pass
                       
                    self._sleep(5)

            except Exception:
                log.error(NAME, _('Air Temperature and Humidity Monitor plug-in') + ':\n' + traceback.format_exc())
                self._sleep(60)
Пример #7
0
    def run(self):
        weather.add_callback(self.update)
        self._sleep(10)  # Wait for weather callback before starting
        while not self._stop_event.is_set():
            try:
                log.clear(NAME)
                if plugin_options['enabled']:
                    log.debug(NAME, _(u'Checking weather status') + '...')

                    if plugin_options['use_netatmo']:
                        authorization = ClientAuth()
                        devList = WeatherStationData(authorization)
                        now = time.time()
                        begin = now - (
                            plugin_options['days_history']) * 24 * 3600
                        mac2 = plugin_options['netatmomac']
                        rainmac2 = plugin_options['netatmorain']
                        resp = (devList.getMeasure(mac2,
                                                   '1hour',
                                                   'sum_rain',
                                                   rainmac2,
                                                   date_begin=begin,
                                                   date_end=now,
                                                   limit=None,
                                                   optimize=False))
                        result = [(time.ctime(int(k)), v[0])
                                  for k, v in resp['body'].items()]
                        result.sort()
                        xdate, xrain = zip(*result)
                        zrain = 0
                        for yrain in xrain:
                            zrain = zrain + yrain
                    else:
                        zrain = 0

                    info = []
                    days = 0
                    total_info = {'rain_mm': 0.0}
                    for day in range(-plugin_options['days_history'],
                                     plugin_options['days_forecast'] + 1):
                        check_date = datetime.date.today(
                        ) + datetime.timedelta(days=day)
                        hourly_data = weather.get_hourly_data(check_date)
                        if hourly_data:
                            days += 1
                        info += hourly_data

                        total_info['rain_mm'] += weather.get_rain(check_date)

                    log.info(
                        NAME,
                        _(u'Using') + ' %d ' % days +
                        _(u'days of information.'))

                    total_info.update({
                        'temp_c':
                        sum([val['temperature'] for val in info]) / len(info),
                        'wind_ms':
                        sum([val['windSpeed'] for val in info]) / len(info),
                        'humidity':
                        sum([val['humidity'] for val in info]) / len(info)
                    })

                    # We assume that the default 100% provides 4mm water per day (normal need)
                    # We calculate what we will need to provide using the mean data of X days around today

                    water_needed = 4 * days  # 4mm per day
                    water_needed *= 1 + (total_info['temp_c'] -
                                         20) / 15  # 5 => 0%, 35 => 200%
                    water_needed *= 1 + (total_info['wind_ms'] / 100
                                         )  # 0 => 100%, 20 => 120%
                    water_needed *= 1 - (total_info['humidity'] -
                                         50) / 200  # 0 => 125%, 100 => 75%
                    water_needed = round(water_needed, 1)

                    water_left = water_needed - total_info['rain_mm']
                    water_left = round(max(0, min(100, water_left)), 1)

                    water_adjustment = round((water_left / (4 * days)) * 100,
                                             1)

                    level_adjustments[NAME] = water_adjustment / 100

                    if plugin_options['use_netatmo']:
                        water_left = water_needed - zrain - total_info[
                            'rain_mm']
                        water_left = round(max(0, min(100, water_left)), 1)

                    else:
                        water_left = water_needed - total_info['rain_mm']
                        water_left = round(max(0, min(100, water_left)), 1)

                    water_adjustment = round(
                        (water_left /
                         ((plugin_options['netatmo_level']) * days)) * 100, 1)

                    water_adjustment = float(
                        max(plugin_options['wl_min'],
                            min(plugin_options['wl_max'], water_adjustment)))

                    log.info(
                        NAME,
                        _(u'Water needed') + '(%d ' % days + _(u'days') +
                        '): %.1fmm' % water_needed)
                    log.info(
                        NAME,
                        _(u'Total rainfall') +
                        ': %.1fmm' % total_info['rain_mm'])
                    log.info(NAME, _(u'_______________________________'))
                    log.info(NAME,
                             _(u'Irrigation needed') + ': %.1fmm' % water_left)
                    log.info(
                        NAME,
                        _(u'Weather Adjustment') +
                        ': %.1f%%' % water_adjustment)
                    log.info(NAME, _(u'_______________________________'))
                    log.info(
                        NAME,
                        _(u'History rain by Netatmo') + ': %.1fmm' % zrain)

                    self._sleep(3600)

                else:
                    log.clear(NAME)
                    log.info(NAME, _(u'Plug-in is disabled.'))
                    if NAME in level_adjustments:
                        del level_adjustments[NAME]
                    self._sleep(24 * 3600)

            except Exception:
                log.error(
                    NAME,
                    _(u'Weather-based water level plug-in') + ':\n' +
                    traceback.format_exc())
                self._sleep(3600)
        weather.remove_callback(self.update)
Пример #8
0
    def run(self):
        Temperature = 0
        Humidity = 0

        last_millis = 0  # timer for save log
        var1 = True  # Auxiliary variable for once on
        var2 = True  # Auxiliary variable for once off

        while not self._stop.is_set():
            try:
                if plugin_options['enabled']:  # if plugin is enabled
                    log.clear(NAME)
                    log.info(NAME, datetime_string())
                    try:

                        result = instance.read()
                        if result.is_valid():
                            Temperature = result.temperature
                            Humidity = result.humidity
                    except:
                        log.clear(NAME)
                        log.info(NAME, datetime_string())
                        log.info(NAME, _('DHT11 data is not valid'))

                    if Humidity and Temperature != 0:
                        self.status['temp'] = Temperature
                        self.status['humi'] = Humidity
                        log.info(
                            NAME,
                            _('Temperature') + ' DHT: ' +
                            u'%.1f \u2103' % Temperature)
                        log.info(
                            NAME,
                            _('Humidity') + ' DHT: ' + u'%.1f' % Humidity +
                            ' %RH')
                        if plugin_options['enabled_reg']:
                            OT = _('ON') if self.status['outp'] is 1 else _(
                                'OFF')
                            log.info(NAME, _('Output') + ': ' + u'%s' % OT)

                        if plugin_options['enable_log']:
                            millis = int(round(time.time() * 1000))
                            interval = (plugin_options['log_interval'] * 60000)
                            if (millis - last_millis) > interval:
                                last_millis = millis
                                update_log(self.status)

                        station = stations.get(
                            plugin_options['control_output'])

                        if plugin_options[
                                'enabled_reg']:  # if regulation is enabled
                            if Humidity > (plugin_options['humidity_on'] +
                                           plugin_options['hysteresis'] /
                                           2) and var1 is True:
                                station.active = True
                                var1 = False
                                var2 = True
                                self.status['outp'] = 1
                                log.debug(NAME,
                                          _('Station output was turned on.'))
                                update_log(self.status)

                            if Humidity < (plugin_options['humidity_off'] -
                                           plugin_options['hysteresis'] /
                                           2) and var2 is True:
                                station.active = False
                                var1 = True
                                var2 = False
                                self.status['outp'] = 0
                                log.debug(NAME,
                                          _('Station output was turned off.'))
                                update_log(self.status)

                        # Activate again if needed:
                        if station.remaining_seconds != 0:
                            station.active = True

                    if plugin_options[
                            'ds_enabled']:  # if in plugin is enabled DS18B20
                        DS18B20_read_data(
                        )  # get read DS18B20 temperature data to global tempDS[xx]

                        for i in range(0, plugin_options['ds_used']):
                            self.status['DS%d' % i] = tempDS[i]
                            log.info(
                                NAME,
                                _('Temperature') + ' DS' + str(i + 1) + ' (' +
                                u'%s' % plugin_options['label_ds%d' % i] +
                                '): ' +
                                u'%.1f \u2103' % self.status['DS%d' % i])

                    #print DS18B20_read_string_data() # for testing only
                    self._sleep(5)

            except Exception:
                log.error(
                    NAME,
                    _('Air Temperature and Humidity Monitor plug-in') + ':\n' +
                    traceback.format_exc())
                self._sleep(60)
Пример #9
0
    def run(self):
        weather.add_callback(self.update)
        self._sleep(10)  # Wait for weather callback before starting
        while not self._stop.is_set():
            try:
                log.clear(NAME)
                if plugin_options['enabled']:
                    log.debug(NAME, _('Checking weather status') + '...')

                    history = weather.get_wunderground_history(
                        plugin_options['days_history'])
                    forecast = weather.get_wunderground_forecast(
                        plugin_options['days_forecast'])
                    today = weather.get_wunderground_conditions()

                    info = {}

                    for day in range(-20, 20):
                        if day in history:
                            day_info = history[day]
                        elif day in forecast:
                            day_info = forecast[day]
                        else:
                            continue

                        info[day] = day_info

                    if 0 in info and 'rain_mm' in today:
                        day_time = datetime.datetime.now().time()
                        day_left = 1.0 - (day_time.hour * 60 +
                                          day_time.minute) / 24.0 / 60
                        info[0]['rain_mm'] = info[0][
                            'rain_mm'] * day_left + today['rain_mm']

                    if not info:
                        log.info(NAME, str(history))
                        log.info(NAME, str(today))
                        log.info(NAME, str(forecast))
                        raise Exception(_('No information available!'))

                    log.info(
                        NAME,
                        _('Using') + ' %d ' % len(info) +
                        _('days of information.'))

                    total_info = {
                        'temp_c':
                        sum([val['temp_c']
                             for val in info.values()]) / len(info),
                        'rain_mm':
                        sum([val['rain_mm'] for val in info.values()]),
                        'wind_ms':
                        sum([val['wind_ms']
                             for val in info.values()]) / len(info),
                        'humidity':
                        sum([val['humidity']
                             for val in info.values()]) / len(info)
                    }

                    # We assume that the default 100% provides 4mm water per day (normal need)
                    # We calculate what we will need to provide using the mean data of X days around today

                    water_needed = 4 * len(info)  # 4mm per day
                    water_needed *= 1 + (total_info['temp_c'] -
                                         20) / 15  # 5 => 0%, 35 => 200%
                    water_needed *= 1 + (total_info['wind_ms'] / 100
                                         )  # 0 => 100%, 20 => 120%
                    water_needed *= 1 - (total_info['humidity'] -
                                         50) / 200  # 0 => 125%, 100 => 75%
                    water_needed = round(water_needed, 1)

                    water_left = water_needed - total_info['rain_mm']
                    water_left = round(max(0, min(100, water_left)), 1)

                    water_adjustment = round(
                        (water_left / (4 * len(info))) * 100, 1)

                    water_adjustment = float(
                        max(plugin_options['wl_min'],
                            min(plugin_options['wl_max'], water_adjustment)))

                    log.info(
                        NAME,
                        _('Water needed') + ' %d ' % len(info) + _('days') +
                        ': %.1fmm' % water_needed)
                    log.info(
                        NAME,
                        _('Total rainfall') +
                        ': %.1fmm' % total_info['rain_mm'])
                    log.info(NAME, '_______________________________')
                    log.info(NAME,
                             _('Irrigation needed') + ': %.1fmm' % water_left)
                    log.info(
                        NAME,
                        _('Weather Adjustment') +
                        ': %.1f%%' % water_adjustment)

                    level_adjustments[NAME] = water_adjustment / 100

                    if plugin_options['protect_enabled']:
                        log.debug(
                            NAME,
                            _('Temperature') +
                            ': %s' % today['temperature_string'])
                        month = time.localtime().tm_mon  # Current month.
                        cold = (today['temp_c'] < plugin_options['protect_temp']) if options.temp_unit == "C" else \
                            (today['temp_f'] < plugin_options['protect_temp'])
                        if cold and month in plugin_options['protect_months']:
                            station_seconds = {}
                            for station in stations.enabled_stations():
                                if station.index in plugin_options[
                                        'protect_stations']:
                                    station_seconds[
                                        station.index] = plugin_options[
                                            'protect_minutes'] * 60
                                else:
                                    station_seconds[station.index] = 0

                            for station in stations.enabled_stations():
                                if run_once.is_active(datetime.datetime.now(),
                                                      station.index):
                                    break
                            else:
                                log.debug(NAME, _('Protection activated.'))
                                run_once.set(station_seconds)

                    self._sleep(3600)

                else:
                    log.clear(NAME)
                    log.info(NAME, _('Plug-in is disabled.'))
                    if NAME in level_adjustments:
                        del level_adjustments[NAME]
                    self._sleep(24 * 3600)

            except Exception:
                log.error(
                    NAME,
                    _('Weather-based water level plug-in') + ':\n' +
                    traceback.format_exc())
                self._sleep(3600)
        weather.remove_callback(self.update)
Пример #10
0
    def run(self):
        weather.add_callback(self.update)
        self._sleep(10)  # Wait for weather callback before starting
        while not self._stop.is_set():
            try:
                log.clear(NAME)
                if plugin_options['enabled']:
                    log.debug(NAME, _('Checking weather status') + '...')

                    if plugin_options['use_netatmo']:
                        authorization = ClientAuth()
                        devList = WeatherStationData(authorization)
                        now = time.time()
                        begin = now - (
                            plugin_options['days_history']) * 24 * 3600
                        mac2 = plugin_options['netatmomac']
                        rainmac2 = plugin_options['netatmorain']
                        resp = (devList.getMeasure(mac2,
                                                   '1hour',
                                                   'sum_rain',
                                                   rainmac2,
                                                   date_begin=begin,
                                                   date_end=now,
                                                   limit=None,
                                                   optimize=False))
                        result = [(time.ctime(int(k)), v[0])
                                  for k, v in resp['body'].items()]
                        result.sort()
                        xdate, xrain = zip(*result)
                        zrain = 0
                        for yrain in xrain:
                            zrain = zrain + yrain
                    else:
                        zrain = 0

                    history = weather.get_wunderground_history(
                        plugin_options['days_history'])
                    forecast = weather.get_wunderground_forecast(
                        plugin_options['days_forecast'])
                    today = weather.get_wunderground_conditions()

                    info = {}

                    for day in range(-20, 20):
                        if day in history:
                            day_info = history[day]
                        elif day in forecast:
                            day_info = forecast[day]
                        else:
                            continue

                        info[day] = day_info

                    if 0 in info and 'rain_mm' in today:
                        day_time = datetime.datetime.now().time()
                        day_left = 1.0 - (day_time.hour * 60 +
                                          day_time.minute) / 24.0 / 60
                        info[0]['rain_mm'] = info[0][
                            'rain_mm'] * day_left + today['rain_mm']

                    if not info:
                        log.info(NAME, str(history))
                        log.info(NAME, str(today))
                        log.info(NAME, str(forecast))
                        raise Exception(_('No information available!'))

                    log.info(
                        NAME,
                        _('Using') + ' %d ' % len(info) +
                        _('days of information.'))

                    total_info = {
                        'temp_c':
                        sum([val['temp_c']
                             for val in info.values()]) / len(info),
                        'rain_mm':
                        sum([val['rain_mm'] for val in info.values()]),
                        'wind_ms':
                        sum([val['wind_ms']
                             for val in info.values()]) / len(info),
                        'humidity':
                        sum([val['humidity']
                             for val in info.values()]) / len(info)
                    }

                    # We assume that the default 100% provides 4mm water per day (normal need)
                    # We calculate what we will need to provide using the mean data of X days around today

                    water_needed = 4 * len(info)  # 4mm per day
                    water_needed *= 1 + (total_info['temp_c'] -
                                         20) / 15  # 5 => 0%, 35 => 200%
                    water_needed *= 1 + (total_info['wind_ms'] / 100
                                         )  # 0 => 100%, 20 => 120%
                    water_needed *= 1 - (total_info['humidity'] -
                                         50) / 200  # 0 => 125%, 100 => 75%
                    water_needed = round(water_needed, 1)

                    water_left = water_needed - total_info['rain_mm']
                    water_left = round(max(0, min(100, water_left)), 1)

                    water_adjustment = round(
                        (water_left / (4 * len(info))) * 100, 1)

                    level_adjustments[NAME] = water_adjustment / 100

                    if plugin_options['use_netatmo']:
                        water_left = water_needed - zrain - forecast_info2[
                            'rain_mm']
                        water_left = round(max(0, min(100, water_left)), 1)

                    else:
                        water_left = water_needed - total_info['rain_mm']
                        water_left = round(max(0, min(100, water_left)), 1)

                    water_adjustment = round(
                        (water_left /
                         ((plugin_options['netatmo_level']) * len(info))) *
                        100, 1)

                    water_adjustment = float(
                        max(plugin_options['wl_min'],
                            min(plugin_options['wl_max'], water_adjustment)))

                    log.info(
                        NAME,
                        _('Water needed') + '(%d ' % len(info) + _('days') +
                        '): %.1fmm' % water_needed)
                    log.info(
                        NAME,
                        _('Total rainfall') +
                        ': %.1fmm' % total_info['rain_mm'])
                    log.info(NAME, _('_______________________________'))
                    log.info(NAME,
                             _('Irrigation needed') + ': %.1fmm' % water_left)
                    log.info(
                        NAME,
                        _('Weather Adjustment') +
                        ': %.1f%%' % water_adjustment)
                    log.info(NAME, _('_______________________________'))
                    log.info(NAME,
                             _('History rain by Netatmo') + ': %.1fmm' % zrain)

                    self._sleep(3600)

                else:
                    log.clear(NAME)
                    log.info(NAME, _('Plug-in is disabled.'))
                    if NAME in level_adjustments:
                        del level_adjustments[NAME]
                    self._sleep(24 * 3600)

            except Exception:
                log.error(
                    NAME,
                    _('Weather-based water level plug-in') + ':\n' +
                    traceback.format_exc())
                self._sleep(3600)
        weather.remove_callback(self.update)
Пример #11
0
    def GET(self):
        log.clear(NAME)
        cmd = "sudo echo 'bcm2708_wdog' >> /etc/modules"
        log.debug(NAME, cmd)
        run_process(cmd)
        cmd = "sudo modprobe bcm2708_wdog"
        log.debug(NAME, cmd)
        run_process(cmd)
        cmd = "sudo apt-get install -y watchdog chkconfig"
        log.debug(NAME, cmd)
        run_process(cmd)
        cmd = "sudo chkconfig watchdog on"
        log.debug(NAME, cmd)
        run_process(cmd)
        log.debug(NAME, _('Saving config to /etc/watchdog.conf'))

        # http://linux.die.net/man/5/watchdog.conf
        f = open("/etc/watchdog.conf", "w")
        f.write("watchdog-device = /dev/watchdog\n")
        f.write("watchdog-timeout = 14\n")
        f.write("realtime = yes\n")
        f.write("priority = 1\n")
        f.write("interval = 4\n")
        f.write("max-load-1 = 24\n")
        f.close()

        cmd = "sudo systemctl enable watchdog"
        log.debug(NAME, cmd)
        run_process(cmd)
        cmd = "sudo systemctl daemon-reload"
        log.debug(NAME, cmd)
        run_process(cmd)
        cmd = "sudo systemctl start watchdog"
        log.debug(NAME, cmd)
        run_process(cmd)

        reboot(True)  # reboot HW software after instal watchdog
        return self.core_render.restarting(plugin_url(status_page))