コード例 #1
0
def get_overview():
    """Returns the info data as a list of lines."""
    result = []
    log.clear(NAME)
    meminfo = helpers.get_meminfo()
    netdevs = helpers.get_netdevs()

    result.append('System release: ' + platform.release())
    result.append('System name:    ' + platform.system())
    result.append('Node:           ' + platform.node())
    result.append('Machine:        ' + platform.machine())
    result.append('Total memory:   ' + meminfo['MemTotal'])
    result.append('Free memory:    ' + meminfo['MemFree'])
    if netdevs:
        for dev, info in netdevs.items():
            result.append('%-16s %s MiB %s MiB' %
                          (dev + ':', info['rx'], info['tx']))
    else:
        result.append('Network:        Unknown')
    result.append('Uptime:         ' + helpers.uptime())
    result.append('CPU temp:       ' +
                  helpers.get_cpu_temp(options.temp_unit) + ' ' +
                  options.temp_unit)
    result.append('MAC adress: ' + helpers.get_mac())
    try:
        result.append('I2C HEX Adress:')
        rev = str(0 if helpers.get_rpi_revision() == 1 else 1)
        cmd = 'sudo i2cdetect -y ' + rev
        result.append(process(cmd))
    except Exception:
        log.error(NAME, 'System info plug-in:\n' + traceback.format_exc())
    log.info(NAME, result)
    return result
コード例 #2
0
ファイル: api.py プロジェクト: teodoryantcheff/OSPy
 def GET(self):
     logger.debug('GET ' + self.__class__.__name__)
     return {
         'version': version.ver_str,
         'CPU_temperature': helpers.get_cpu_temp(),
         'release_date': version.ver_date,
         'uptime': helpers.uptime(),
         'platform': helpers.determine_platform(),
         'rpi_revision': helpers.get_rpi_revision()
     }
コード例 #3
0
ファイル: api.py プロジェクト: Rimco/OSPy
 def GET(self):
     logger.debug('GET ' + self.__class__.__name__)
     return {
         'version': version.ver_str,
         'CPU_temperature': helpers.get_cpu_temp(),
         'release_date': version.ver_date,
         'uptime': helpers.uptime(),
         'platform': helpers.determine_platform(),
         'rpi_revision': helpers.get_rpi_revision(),
         'total_adjustment': level_adjustments.total_adjustment()
     }
コード例 #4
0
def get_report(index):
    result = None

    if index == 0:
        if lcd_options['d_system_name']:
            result = ASCI_convert(_('System:'))
        else:
            result = None
    elif index == 1:
        if lcd_options['d_system_name']:
            result = ASCI_convert(options.name)
        else:
            result = None
    elif index == 2:
        if lcd_options['d_sw_version_date']:
            result = ASCI_convert(_('SW Version:'))
        else:
            result = None
    elif index == 3:
        if lcd_options['d_sw_version_date']:
            result = ASCI_convert('{} {}'.format(version.ver_str,
                                                 version.ver_date))
        else:
            result = None
    elif index == 4:
        if lcd_options['d_ip']:
            result = ASCI_convert(_('My IP is:'))
        else:
            result = None
    elif index == 5:
        if lcd_options['d_ip']:
            if options.use_ssl:
                result = ASCI_convert(
                    ('https://{}:{}').format(helpers.get_ip(),
                                             options.web_port))
            else:
                result = ASCI_convert(
                    ('http://{}:{}').format(helpers.get_ip(),
                                            options.web_port))
        else:
            result = None
    elif index == 6:
        if lcd_options['d_port']:
            result = ASCI_convert(_('My Port is:'))
        else:
            result = None
    elif index == 7:
        if lcd_options['d_port']:
            result = ASCI_convert('{}'.format(options.web_port))
        else:
            result = None
    elif index == 8:
        if lcd_options['d_cpu_temp']:
            result = ASCI_convert(_('CPU Temperature:'))
        else:
            result = None
    elif index == 9:
        if lcd_options['d_cpu_temp']:
            result = ASCI_convert('{} {}'.format(
                helpers.get_cpu_temp(options.temp_unit), options.temp_unit))
        else:
            result = None
    elif index == 10:
        if lcd_options['d_time_date']:
            result = ASCI_convert(
                _('Date:') + ' {}'.format(datetime.now().strftime('%d.%m.%Y')))
        else:
            result = None
    elif index == 11:
        if lcd_options['d_time_date']:
            result = ASCI_convert(
                _('Time:') + ' {}'.format(datetime.now().strftime('%H:%M:%S')))
        else:
            result = None
    elif index == 12:
        if lcd_options['d_uptime']:
            result = ASCI_convert(_('System Uptime:'))
        else:
            result = None
    elif index == 13:
        if lcd_options['d_uptime']:
            result = ASCI_convert(helpers.uptime())
        else:
            result = None
    elif index == 14:
        if lcd_options['d_rain_sensor']:
            result = ASCI_convert(_('Rain Sensor:'))
        else:
            result = None
    elif index == 15:
        if lcd_options['d_rain_sensor']:
            if inputs.rain_sensed():
                result = ASCI_convert(_('Active'))
            else:
                result = ASCI_convert(_('Inactive'))
        else:
            result = None
    elif index == 16:
        if lcd_options['d_last_run']:
            result = ASCI_convert(_('Last Program:'))
        else:
            result = None
    elif index == 17:
        if lcd_options['d_last_run']:
            finished = [
                run for run in log.finished_runs() if not run['blocked']
            ]
            if finished:
                str_fin = '{}{}'.format(
                    finished[-1]['program_name'],
                    finished[-1]['start'].strftime(' %d.%m.%Y %H:%M:%S'))
                result = ASCI_convert(str_fin)
            else:
                result = ASCI_convert(_('None'))
        else:
            result = None
    elif index == 18:
        if lcd_options['d_pressure_sensor']:
            result = ASCI_convert(_('Pressure Sensor:'))
        else:
            result = None
    elif index == 19:
        if lcd_options['d_pressure_sensor']:
            try:
                from plugins import pressure_monitor
                state_press = pressure_monitor.get_check_pressure()
                if state_press:
                    result = ASCI_convert(_('Inactive'))
                else:
                    result = ASCI_convert(_('Active'))
            except Exception:
                result = ASCI_convert(_('Not Available'))
        else:
            result = None
    elif index == 20:
        if lcd_options['d_water_tank_level']:
            result = ASCI_convert(_('Water Tank Level:'))
        else:
            result = None
    elif index == 21:
        if lcd_options['d_water_tank_level']:
            try:
                from plugins import tank_monitor
                cm = tank_monitor.get_all_values()[0]
                percent = tank_monitor.get_all_values()[1]
                ping = tank_monitor.get_all_values()[2]
                volume = tank_monitor.get_all_values()[3]
                units = tank_monitor.get_all_values()[4]
            except Exception:
                cm = -1
                percent = 0
                ping = -1
                volume = 0
                units = -1

            if cm > 0 and units != -1:
                result = ASCI_convert(
                    _('Level') + ' {}'.format(cm) + _('cm') +
                    ' {}'.format(percent) + _('%') + ' {}'.format(int(volume)))
                if units:
                    result += ASCI_convert(_('liter'))
                else:
                    result += ASCI_convert(_('m3'))
            elif units == -1:
                result = ASCI_convert(_('Not Available'))
            else:
                result = ASCI_convert(_('Error - I2C Device Not Found!'))
        else:
            result = None
    elif index == 22:
        if lcd_options['d_temperature']:
            result = ASCI_convert(_('DS Temperature:'))
        else:
            result = None
    elif index == 23:
        if lcd_options['d_temperature']:
            try:
                from plugins import air_temp_humi
                air_options = air_temp_humi.plugin_options
                if air_options['ds_enabled']:
                    air_result = ''
                    for i in range(0, air_options['ds_used']):
                        air_result += '{}:{} '.format(
                            air_options['label_ds%d' % i],
                            air_temp_humi.DS18B20_read_probe(i))
                    result = ASCI_convert(air_result)
                else:
                    result = ASCI_convert(_('DS temperature not use'))
            except Exception:
                result = ASCI_convert(_('Not Available'))
        else:
            result = None
    elif index == 24:
        if lcd_options['d_running_stations']:
            result = ASCI_convert(_('Station running:'))
        else:
            result = None
    elif index == 25:
        if lcd_options['d_running_stations']:
            if get_active_state() == False:
                result = ASCI_convert(_('Nothing running'))
            else:
                result = ASCI_convert(get_active_state())
        else:
            result = None
    elif index == 26:
        if lcd_options['d_sched_manu']:
            result = ASCI_convert(_('Control:'))
        else:
            result = None
    elif index == 27:
        if lcd_options['d_sched_manu']:
            if options.manual_mode:
                result = ASCI_convert(_('Manual mode'))
            else:
                result = ASCI_convert(_('Scheduler'))
        else:
            result = None
    elif index == 28:
        if lcd_options['d_syst_enabl']:
            result = ASCI_convert(_('Scheduler:'))
        else:
            result = None
    elif index == 29:
        if lcd_options['d_syst_enabl']:
            if options.scheduler_enabled:
                result = ASCI_convert(_('Enabled'))
            else:
                result = ASCI_convert(_('Disabled'))
        else:
            result = None
    ### OSPy sensors ###
    elif index == 30:
        if lcd_options['d_sensors']:
            result = ASCI_convert(_('Sensors:'))
        else:
            result = None
    elif index == 31:
        if lcd_options['d_sensors']:
            try:
                if sensors.count() > 0:
                    sensor_result = ''
                    for sensor in sensors.get():
                        if sensor.enabled:
                            if sensor.response == 1:
                                sensor_result += sensor.name + ': '
                                if sensor.sens_type == 1:  # dry contact
                                    if sensor.last_read_value[4] == 1:
                                        sensor_result += _('Contact Closed')
                                    elif sensor.last_read_value[4] == 0:
                                        sensor_result += _('Contact Open')
                                    else:
                                        sensor_result += _('Probe Error')
                                if sensor.sens_type == 2:  # leak detector
                                    if sensor.last_read_value[5] != -127:
                                        sensor_result += '{}'.format(
                                            sensor.last_read_value[5]
                                        ) + ' ' + _('l/s')
                                    else:
                                        sensor_result += _('Probe Error')
                                if sensor.sens_type == 3:  # moisture
                                    if sensor.last_read_value[6] != -127:
                                        sensor_result += '{}'.format(
                                            sensor.last_read_value[6]) + _('%')
                                    else:
                                        sensor_result += _('Probe Error')
                                if sensor.sens_type == 4:  # motion
                                    if sensor.last_read_value[7] != -127:
                                        sensor_result += _(
                                            'Motion Detected') if int(
                                                sensor.last_read_value[7]
                                            ) == 1 else _('No Motion')
                                    else:
                                        sensor_result += _('Probe Error')
                                if sensor.sens_type == 5:  # temperature
                                    if sensor.last_read_value[0] != -127:
                                        sensor_result += '{}'.format(
                                            sensor.last_read_value[0])
                                    else:
                                        sensor_result += _('Probe Error')
                                if sensor.sens_type == 6:  # multi sensor
                                    if sensor.multi_type >= 0 and sensor.multi_type < 4:  # multi temperature DS1-DS4
                                        if sensor.last_read_value[
                                                sensor.multi_type] != -127:
                                            sensor_result += '{}'.format(
                                                sensor.last_read_value[
                                                    sensor.multi_type])
                                        else:
                                            sensor_result += _('Probe Error')
                                    if sensor.multi_type == 4:  #  multi dry contact
                                        if sensor.last_read_value[4] != -127:
                                            sensor_result += _(
                                                'Contact Closed') if int(
                                                    sensor.last_read_value[4]
                                                ) == 1 else _('Contact Open')
                                        else:
                                            sensor_result += _('Probe Error')
                                    if sensor.multi_type == 5:  #  multi leak detector
                                        if sensor.last_read_value[5] != -127:
                                            sensor_result += '{}'.format(
                                                sensor.last_read_value[5]
                                            ) + ' ' + _('l/s')
                                        else:
                                            sensor_result += _('Probe Error')
                                    if sensor.multi_type == 6:  #  multi moisture
                                        if sensor.last_read_value[6] != -127:
                                            sensor_result += '{}'.format(
                                                sensor.last_read_value[6]
                                            ) + ' ' + _('%')
                                        else:
                                            sensor_result += _('Probe Error')
                                    if sensor.multi_type == 7:  #  multi motion
                                        if sensor.last_read_value[7] != -127:
                                            sensor_result += _(
                                                'Motion Detected') if int(
                                                    sensor.last_read_value[7]
                                                ) == 1 else _('No Motion')
                                        else:
                                            sensor_result += _('Probe Error')
                                    if sensor.multi_type == 8:  #  multi ultrasonic
                                        if sensor.last_read_value[8] != -127:
                                            get_level = get_tank_cm(
                                                sensor.last_read_value[8],
                                                sensor.distance_bottom,
                                                sensor.distance_top)
                                            get_perc = get_percent(
                                                get_level,
                                                sensor.distance_bottom,
                                                sensor.distance_top)
                                            sensor_result += '{}'.format(
                                                get_level) + ' ' + _(
                                                    'cm') + ' (' + '{}'.format(
                                                        get_perc) + ' %)'
                                        else:
                                            sensor_result += _('Probe Error')
                                    if sensor.multi_type == 9:  #  multi soil moisture
                                        err_check = 0
                                        calculate_soil = [0.0] * 16
                                        state = [-127] * 16
                                        for i in range(0, 16):
                                            if type(sensor.
                                                    soil_last_read_value[i]
                                                    ) == float:
                                                state[
                                                    i] = sensor.soil_last_read_value[
                                                        i]
                                                ### voltage from probe to humidity 0-100% with calibration range (for footer info)
                                                if sensor.soil_invert_probe_in[
                                                        i]:  # probe: rotated state 0V=100%, 3V=0% humidity
                                                    calculate_soil[i] = maping(
                                                        state[i],
                                                        float(
                                                            sensor.
                                                            soil_calibration_max[
                                                                i]),
                                                        float(
                                                            sensor.
                                                            soil_calibration_min[
                                                                i]), 0.0,
                                                        100.0)
                                                    calculate_soil[i] = round(
                                                        calculate_soil[i], 1
                                                    )  # round to one decimal point
                                                    calculate_soil[
                                                        i] = 100.0 - calculate_soil[
                                                            i]  # ex: 90% - 90% = 10%, 10% is output in invert probe mode
                                                else:  # probe: normal state 0V=0%, 3V=100%
                                                    calculate_soil[i] = maping(
                                                        state[i],
                                                        float(
                                                            sensor.
                                                            soil_calibration_min[
                                                                i]),
                                                        float(
                                                            sensor.
                                                            soil_calibration_max[
                                                                i]), 0.0,
                                                        100.0)
                                                    calculate_soil[i] = round(
                                                        calculate_soil[i], 1
                                                    )  # round to one decimal point
                                                if state[i] > 0.1:
                                                    if sensor.soil_show_in_footer[
                                                            i]:
                                                        sensor_result += '{} {}% ({}V) '.format(
                                                            sensor.
                                                            soil_probe_label[
                                                                i],
                                                            round(
                                                                calculate_soil[
                                                                    i], 2),
                                                            round(state[i], 2))
                                            else:
                                                err_check += 1
                                        if err_check > 15:
                                            sensor_result += _('Probe Error')
                            else:
                                sensor_result += sensor.name + ': ' + _(
                                    'No response!')
                        else:
                            sensor_result += sensor.name + ': ' + _('Disabled')
                        if sensors.count() > 1:
                            sensor_result += ', '
                    result = ASCI_convert(sensor_result)
                else:
                    result = ASCI_convert(_('No sensors available'))
            except Exception:
                result = ASCI_convert(_('Not Available'))
        else:
            result = None

    return result
コード例 #5
0
ファイル: __init__.py プロジェクト: martinpihrt/OSPy-plugins
def FTP_upload(self):
    try:
        # create a file "stavy.php"
        cas = time.strftime('%d.%m.%Y (%H:%M:%S)', time.localtime(time.time()))

        text = "<?php\r\n$cas = \""  # actual time (ex: cas = dd.mm.yyyy (HH:MM:SS)
        text += cas + "\";\r\n"
        text += "$rain = \'"  # rain state (ex: rain = 0/1)
        text += str(1 if inputs.rain_sensed() else 0) + "\';\r\n"
        text += "$output = \'"  # use xx outputs count (ex: output = 8)
        text += str(options.output_count) + "\';\r\n"
        text += "$program = \'"  # use xx programs count (ex: program = 3)
        text += str(programs.count()) + "\';\r\n"

        text += "$masterstat = "  # master stations index
        for station in stations.get():
            if station.is_master:
                text += "\'" + str(station.index) + "\';\r\n"
        if stations.master is None:
            text += "\'\';\r\n"

        text += "$raindel = "  # rain delay
        if rain_blocks.seconds_left():
            m, s = divmod(int(rain_blocks.seconds_left()), 60)
            h, m = divmod(m, 60)
            text += "\'" + "%dh:%02dm:%02ds" % (h, m, s) + "\';\r\n"
        else:
            text += "\'\';\r\n"

        import unicodedata  # for only asci text in PHP WEB (stations name, program name...)

        namestations = []
        for num in range(0, options.output_count):  # stations name as array
            namestations.append(
                unicodedata.normalize('NFKD',
                                      stations.get(num).name).encode(
                                          'ascii', 'ignore'))
        text += "$name" + " = array"
        text += str(namestations) + ";\r\n"

        statestations = []
        for num in range(0, options.output_count):  # stations state as array
            statestations.append(1 if stations.get(num).active else 0)
        text += "$state" + " = array"
        text += str(statestations) + ";\r\n"

        progrname = []
        for program in programs.get():  # program name as array
            progrname.append(
                unicodedata.normalize('NFKD',
                                      program.name).encode('ascii', 'ignore'))
        text += "$progname" + " = array"
        text += str(progrname) + ";\r\n"

        text = text.replace('[', '(')
        text = text.replace(']', ')')

        text += "$schedul = \'"  # scheduller state (ex: schedul = 0 manual/ 1 scheduler)
        text += str(0 if options.manual_mode else 1) + "\';\r\n"
        text += "$system = \'"  # scheduller state (ex: system = 0 stop/ 1 scheduler)
        text += str(0 if options.scheduler_enabled else 1) + "\';\r\n"
        text += "$cpu = \'"  # cpu temp (ex: cpu  = 45.2)
        text += str(helpers.get_cpu_temp(options.temp_unit)) + "\';\r\n"
        text += "$unit = \'"  # cpu temp unit(ex: unit  = C/F) in Celsius or Fahrenheit
        text += str(options.temp_unit) + "\';\r\n"
        text += "$ver = \'"  # software version date (ex: ver  = 2016-07-30)
        text += str(version.ver_date) + "\';\r\n"
        text += "$id = \'"  # software OSPy ID (ex: id  = "opensprinkler")
        text += str(options.name) + "\';\r\n"
        text += "$ip = \'"  # OSPy IP address (ex: ip  = "192.168.1.1")
        text += str(helpers.get_ip()) + "\';\r\n"
        text += "$port = \'"  # OSPy port (ex: port  = "8080")
        text += str(options.web_port) + "\';\r\n"
        text += "$ssl = \'"  # OSPy use ssl port (ex: ssl  = "1" or "0")
        text += str(1 if options.use_ssl else 0) + "\';\r\n"

        tank = ''
        try:
            from plugins import tank_humi_monitor
            tank = tank_humi_monitor.get_sonic_tank_cm()
            if tank < 0:  # -1 is error I2C device for ping not found in tank_humi_monitor
                tank = ''
        except Exception:
            tank = ''

        text = text + "$tank = \'"  # from tank humi monitor plugins check water level (ex: tank  = "100" in cm or "")
        text = text + str(tank) + "\';\r\n"

        press = ''
        try:
            from plugins import pressure_monitor
            press = pressure_monitor.get_check_pressure()
        except Exception:
            press = ''

        text = text + "$press = \'"  # from pressure plugins check press (ex: press  = "1" or "0")
        text = text + str(press) + "\';\r\n"

        ups = ''
        try:
            from plugins import ups_adj
            ups = ups_adj.get_check_power(
            )  # read state power line from plugin ups adj
        except Exception:
            ups = ''

        text = text + "$ups = \'"
        text = text + str(ups) + "\';\r\n"

        result = ''
        finished = [run for run in log.finished_runs() if not run['blocked']]
        if finished:
            result = finished[-1]['start'].strftime(
                '%d-%m-%Y v %H:%M:%S program: ') + finished[-1]['program_name']
        else:
            result = ''

        text = text + "$lastrun = \'"  # last run program (ex: start d-m-r v h:m:s program: jmemo programu)
        text = text + str(result) + "\';\r\n"

        text = text + "$up = \'"  # system run uptime
        text = text + str(helpers.uptime()) + "\';\r\n"

        text = text + "?>\r\n"
        #print text
        """ example php code -----------
      <?php
      $cas = "09.08.2016 (15:28:10)";
      $rain = '0';
      $output = '3';
      $program = '3';
      $masterstat = '0';
      $raindel = '1:26:22'; // hod:min:sec
      $name = array('cerpadlo','test','out2');
      $state = array('0', '0', '0');
      $progname = array('cerpadlo v 5','test','out2');   
      $schedul = '1';
      $system = '1';
      $cpu = '40.1';
      $unit = 'C';
      $ver = '2016-07-30';
      $id = 'Zalevac chata';
      $ip = '192.168.1.253';
      $port = '80';
      $ssl = '1';
      $tank = '20';
      $press = '0';
      $ups = '1';
      $lastrun = '09.08.2016 v 15:28:10 program: bezi 5 minut)';
      $up = '6 days, 0:48:01'
      ?>
      ------------------------------- """

        try:
            fs = file("/home/pi/ramdisk/stavy.php", 'w')
            fs.write(text)
            fs.close()

        except:
            log.error(NAME, _(u'Could not save stavy.php to ramdisk!'))
            pass

        self.ftp.storbinary("STOR " + plugin_options['loc'] + 'stavy.php',
                            open("/home/pi/ramdisk/stavy.php", 'rb'))
        log.info(
            NAME,
            _(u'Data file stavy.php has send on to FTP server') + ': ' +
            str(cas))

        self.ftp.storbinary("STOR " + plugin_options['loc'] + 'data.txt',
                            open("/home/pi/ramdisk/data.txt", 'rb'))
        log.info(
            NAME,
            _(u'Data file data.txt has send on to FTP server') + ': ' +
            str(cas))

        self.ftp.close  # FTP end

    except Exception:
        log.info(
            NAME,
            _(u'Remote FTP control settings') + ':\n' + traceback.format_exc())
コード例 #6
0
def get_report(index):
    result = None
    if (options.lang == 'cs_CZ'):
           if index == 0:  # start text to 16x1
             if lcd_options['d_system_name']:
                result = "ID systemu:"
             else: 
                result = None
           elif index == 1:
             if lcd_options['d_system_name']:
                result = options.name
             else:
                result = None 

           elif index == 2:
             if lcd_options['d_sw_version_date']:
                result = "FW Verze:"
             else: 
                result = None
           elif index == 3:
             if lcd_options['d_sw_version_date']:
                result = version.ver_str + ' (' + version.ver_date + ')' 
             else: 
                result = None

           elif index == 4:
             if lcd_options['d_ip']:
                result = "IP adresa:" 
             else: 
                result = None
           elif index == 5:
             if lcd_options['d_ip']:
                 ip = helpers.get_ip()
                 result = str(ip)
             else: 
                result = None

           elif index == 6:
             if lcd_options['d_port']:
                result = "Port:"
             else: 
                result = None
           elif index == 7:
             if lcd_options['d_port']:
                result = str(options.web_port)
             else: 
                result = None

           elif index == 8:
             if lcd_options['d_cpu_temp']:
                result = "Teplota CPU:"
             else: 
                result = None
           elif index == 9:
             if lcd_options['d_cpu_temp']:
                result = helpers.get_cpu_temp(options.temp_unit) + ' ' + options.temp_unit
             else: 
                result = None

           elif index == 10:
             if lcd_options['d_time_date']:
                result = datetime.now().strftime('Dat %d.%m.%Y')
             else: 
                result = None
           elif index == 11:
             if lcd_options['d_time_date']:
                result = datetime.now().strftime('Cas %H:%M:%S')
             else: 
                result = None

           elif index == 12:
             if lcd_options['d_uptime']:
                result = "V provozu:"
             else: 
                result = None
           elif index == 13:
             if lcd_options['d_uptime']:
                result = helpers.uptime() 
             else: 
                result = None

           elif index == 14:
             if lcd_options['d_rain_sensor']:
                result = "Cidlo deste:"
             else: 
                result = None
           elif index == 15:
             if lcd_options['d_rain_sensor']:
                if inputs.rain_sensed():
                    result = "aktivni"
                else:
                    result = "neaktivni"
             else: 
                result = None

           elif index == 16:
             if lcd_options['d_last_run']:
                result = 'Naposledy bezel'
             else: 
                result = None
           elif index == 17:
             if lcd_options['d_last_run']:
                finished = [run for run in log.finished_runs() if not run['blocked']]
                if finished:
                   result = finished[-1]['start'].strftime('%d-%m-%Y v %H:%M:%S program: ') + finished[-1]['program_name']
                   result = result.replace('Run-Once', 'Jednorazovy')
                   result = result.replace('Manual', 'Rucne')
                else:
                   result = 'zadny program'
             else: 
                result = None

           elif index == 18:
             if lcd_options['d_pressure_sensor']:
                result = "Cidlo tlaku:"
             else: 
                result = None
           elif index == 19:
             if lcd_options['d_pressure_sensor']:
                try:
                   from plugins import pressure_monitor
                   state_press = pressure_monitor.get_check_pressure()
                   if state_press:
                      result = "neaktivni"
                   else:
                      result = "aktivni"

                except Exception:
                   result = "neni k dispozici"
             else: 
                result = None

           elif index == 20:    
             if lcd_options['d_water_tank_level']:    
                result = "Nadrz s vodou:"
             else: 
                result = None
           elif index == 21:
             if lcd_options['d_water_tank_level']:
                try:
                   from plugins import tank_humi_monitor
                   cm = tank_humi_monitor.get_sonic_tank_cm()
                   if cm > 0: 
                      result = str(cm) + ' cm'
                   else:
                      result = "chyba - I2C zarizeni nenalezeno!"

                except Exception:
                   result = "neni k dispozici"
             else: 
                result = None

           elif index == 22:    
             if lcd_options['d_temperature']:    
                result = "Teplota DS1-6:"
             else: 
                result = None
           elif index == 23:
             if lcd_options['d_temperature']:
                try:
                   from plugins import air_temp_humi
                 
                   result = air_temp_humi.DS18B20_read_string_data()
                  
                except Exception:
                   result = "neni k dispozici"
             else: 
                result = None

           elif index == 24:    
             if lcd_options['d_running_stations']:    
                result = "Stanice v chodu:"
             else: 
                result = None
           elif index == 25:
             if get_active_state()==False:   
                result = "nic nebezi" 
             else:
                result = get_active_state()

           return ASCI_convert(result)


    if (options.lang == 'sk_SK'):
           if index == 0:  # start text to 16x1
             if lcd_options['d_system_name']:
                result = "ID systemu:"
             else: 
                result = None
           elif index == 1:
             if lcd_options['d_system_name']:
                result = options.name
             else:
                result = None 

           elif index == 2:
             if lcd_options['d_sw_version_date']:
                result = "FW Verzia:"
             else: 
                result = None
           elif index == 3:
             if lcd_options['d_sw_version_date']:
                result = version.ver_str + ' (' + version.ver_date + ')' 
             else: 
                result = None

           elif index == 4:
             if lcd_options['d_ip']:
                result = "IP adresa:" 
             else: 
                result = None
           elif index == 5:
             if lcd_options['d_ip']:
                 ip = helpers.get_ip()
                 result = str(ip)
             else: 
                result = None

           elif index == 6:
             if lcd_options['d_port']:
                result = "Port:"
             else: 
                result = None
           elif index == 7:
             if lcd_options['d_port']:
                result = str(options.web_port)
             else: 
                result = None

           elif index == 8:
             if lcd_options['d_cpu_temp']:
                result = "Teplota CPU:"
             else: 
                result = None
           elif index == 9:
             if lcd_options['d_cpu_temp']:
                result = helpers.get_cpu_temp(options.temp_unit) + ' ' + options.temp_unit
             else: 
                result = None

           elif index == 10:
             if lcd_options['d_time_date']:
                result = datetime.now().strftime('Dat %d.%m.%Y')
             else: 
                result = None
           elif index == 11:
             if lcd_options['d_time_date']:
                result = datetime.now().strftime('Cas %H:%M:%S')
             else: 
                result = None

           elif index == 12:
             if lcd_options['d_uptime']:
                result = "V prevadzke:"
             else: 
                result = None
           elif index == 13:
             if lcd_options['d_uptime']:
                result = helpers.uptime() 
             else: 
                result = None

           elif index == 14:
             if lcd_options['d_rain_sensor']:
                result = "Cidlo dazda:"
             else: 
                result = None
           elif index == 15:
             if lcd_options['d_rain_sensor']:
                if inputs.rain_sensed():
                    result = "aktivny"
                else:
                    result = "neaktivny"
             else: 
                result = None

           elif index == 16:
             if lcd_options['d_last_run']:
                result = 'Naposledy bezal'
             else: 
                result = None
           elif index == 17:
             if lcd_options['d_last_run']:
                finished = [run for run in log.finished_runs() if not run['blocked']]
                if finished:
                   result = finished[-1]['start'].strftime('%d-%m-%Y v %H:%M:%S program: ') + finished[-1]['program_name']
                   result = result.replace('Run-Once', 'Jednorazovy')
                   result = result.replace('Manual', 'Rucne')
                else:
                   result = 'ziadny program'
             else: 
                result = None

           elif index == 18:
             if lcd_options['d_pressure_sensor']:
                result = "Cidlo tlaku:"
             else: 
                result = None
           elif index == 19:
             if lcd_options['d_pressure_sensor']:
                try:
                   from plugins import pressure_monitor
                   state_press = pressure_monitor.get_check_pressure()
                   if state_press:
                      result = "neaktivny"
                   else:
                      result = "aktivny"

                except Exception:
                   result = "neni k dispozicii"
             else: 
                result = None

           elif index == 20:    
             if lcd_options['d_water_tank_level']:    
                result = "Nadrz s vodou:"
             else: 
                result = None
           elif index == 21:
             if lcd_options['d_water_tank_level']:
                try:
                   from plugins import tank_humi_monitor
                   cm = tank_humi_monitor.get_sonic_tank_cm()
                   if cm > 0: 
                      result = str(cm) + ' cm'
                   else:
                      result = "chyba - I2C zarizeni nenajdene!"

                except Exception:
                   result = "neni k dispozicii"
             else: 
                result = None

           elif index == 22:    
             if lcd_options['d_temperature']:    
                result = "Teplota DS1-6:"
             else: 
                result = None
           elif index == 23:
             if lcd_options['d_temperature']:
                try:
                   from plugins import air_temp_humi
                 
                   result = air_temp_humi.DS18B20_read_string_data()
                  
                except Exception:
                   result = "neni k dispozicii"
             else: 
                result = None

           elif index == 24:    
             if lcd_options['d_running_stations']:    
                result = "Stanice v chode:"
             else: 
                result = None
           elif index == 25:
             if get_active_state()==False:   
                result = "nic nebezi" 
             else:
                result = get_active_state()

           return ASCI_convert(result)

    if (options.lang == 'en_US') or (options.lang == 'default'):
          if index == 0:  
             if lcd_options['d_system_name']:
                result = options.name
             else: 
                result = None
          elif index == 1:
             if lcd_options['d_system_name']:
                result = "Irrigation system"
             else: 
                result = None

          elif index == 2:
             if lcd_options['d_sw_version_date']:
                result = "SW Version:"
             else: 
                result = None
          elif index == 3:
             if lcd_options['d_sw_version_date']:
                result = version.ver_str + ' (' + version.ver_date + ')'
             else: 
                result = None

          elif index == 4:
             if lcd_options['d_ip']:
                result = "My IP is:"
             else: 
                result = None
          elif index == 5:
             if lcd_options['d_ip']:
                ip = helpers.get_ip()
                result = str(ip)
             else: 
                result = None

          elif index == 6:
             if lcd_options['d_port']:
                result = "My Port is:"
             else: 
                result = None
          elif index == 7:
             if lcd_options['d_port']:
                result = str(options.web_port)
             else: 
                result = None

          elif index == 8:
             if lcd_options['d_cpu_temp']:
                result = "CPU Temperature:"
             else: 
                result = None
          elif index == 9:
             if lcd_options['d_cpu_temp']:
                result = helpers.get_cpu_temp(options.temp_unit) + ' ' + options.temp_unit
             else: 
                result = None

          elif index == 10:
             if lcd_options['d_time_date']:
                result = datetime.now().strftime('Date: %d.%m.%Y')
             else: 
                result = None
          elif index == 11:
             if lcd_options['d_time_date']:
                result = datetime.now().strftime('Time: %H:%M:%S')
             else: 
                result = None

          elif index == 12:
             if lcd_options['d_uptime']:
                result = "System Uptime:"
             else: 
                result = None
          elif index == 13:
             if lcd_options['d_uptime']:
                result = helpers.uptime()
             else: 
                result = None

          elif index == 14:
             if lcd_options['d_rain_sensor']:
                result = "Rain Sensor:"
             else: 
                result = None
          elif index == 15:
             if lcd_options['d_rain_sensor']:
                if inputs.rain_sensed():
                   result = "Active"
                else:
                   result = "Inactive"
             else: 
                result = None

          elif index == 16:
             if lcd_options['d_last_run']:
                result = 'Last Program:'
             else: 
                result = None
          elif index == 17:
             if lcd_options['d_last_run']:
                finished = [run for run in log.finished_runs() if not run['blocked']]
                if finished:
                   result = finished[-1]['start'].strftime('%H:%M: ') + finished[-1]['program_name']
                   result = result.replace('Run-Once', 'Jednorazovy') 
                else:
                   result = 'None'
             else: 
                result = None

          elif index == 18:
             if lcd_options['d_pressure_sensor']:
                result = "Pressure Sensor:"
             else: 
                result = None
          elif index == 19:
             if lcd_options['d_pressure_sensor']:
                try:
                   from plugins import pressure_monitor
                   state_press = pressure_monitor.get_check_pressure()
                   if state_press:
                       result = "GPIO is HIGH"
                   else:
                       result = "GPIO is LOW"

                except Exception:
                   result = "Not Available"
             else: 
                result = None


          elif index == 20:    
             if lcd_options['d_water_tank_level']:        
                result = "Water Tank Level:"
             else: 
                result = None
          elif index == 21:
             if lcd_options['d_water_tank_level']:    
                try:
                   from plugins import tank_humi_monitor
                   cm = tank_humi_monitor.get_sonic_tank_cm()
                   if cm > 0: 
                      result = str(cm) + ' cm'
                   else:
                      result = "Error - I2C Device Not Found!"

                except Exception:
                   result = "Not Available"
             else: 
                result = None

          elif index == 22:    
            if lcd_options['d_temperature']:    
               result = "DS Temperature:"
            else: 
               result = None
          elif index == 23:
            if lcd_options['d_temperature']:
               try:
                  from plugins import air_temp_humi
                 
                  result = air_temp_humi.DS18B20_read_string_data()
                                     
               except Exception:
                  result = "Not Available"
            else: 
               result = None

          elif index == 24:    
            if lcd_options['d_running_stations']:    
               result = "Station running:"
            else: 
                result = None
          elif index == 25:
            if get_active_state()==False:   
               result = "nothing running" 
            else:
               result = get_active_state()

          return result
コード例 #7
0
def sms_check(self):
    """Control and processing SMS"""
    try:
        import gammu
    except Exception:
        log.error(NAME,
                  _('SMS Modem plug-in') + ':\n' + traceback.format_exc())

    tel1 = sms_options['tel1']
    tel2 = sms_options['tel2']
    comm1 = sms_options['txt1']
    comm2 = sms_options['txt2']
    comm3 = sms_options['txt3']
    comm4 = sms_options['txt4']
    comm5 = sms_options['txt5']
    comm6 = sms_options['txt6']
    comm7 = sms_options['txt7']
    comm8 = sms_options['txt8']
    comm9 = sms_options['txt9']

    sm = gammu.StateMachine()
    sm.ReadConfig()
    try:
        sm.Init()
        log.debug(NAME, datetime_string() + ': ' + _('Checking SMS...'))
    except:
        log.error(NAME,
                  _('SMS Modem plug-in') + ':\n' + traceback.format_exc())
        self._sleep(60)

    if sms_options[
            "use_strength"]:  # print strength signal in status Window every check SMS
        signal = sm.GetSignalQuality(
        )  # list: SignalPercent, SignalStrength, BitErrorRate
        log.info(
            NAME,
            datetime_string() + ': ' + _('Signal') + ': ' +
            str(signal['SignalPercent']) + '% ' +
            str(signal['SignalStrength']) + 'dB')

    status = sm.GetSMSStatus()
    remain = status['SIMUsed'] + status['PhoneUsed'] + status['TemplatesUsed']
    sms = []
    start = True
    while remain > 0:
        if start:
            cursms = sm.GetNextSMS(Start=True, Folder=0)
            start = False
        else:
            cursms = sm.GetNextSMS(Location=cursms[0]['Location'], Folder=0)
        remain = remain - len(cursms)
        sms.append(cursms)
    data = gammu.LinkSMS(sms)
    for x in data:
        v = gammu.DecodeSMS(x)
        m = x[0]
        print '%-15s: %s' % ('Sender', m['Number'])
        print '%-15s: %s' % ('Date', str(m['DateTime']))
        print '%-15s: %s' % ('State', m['State'])
        print '%-15s: %s' % ('SMS command', m['Text'])
        if (m['Number']
                == tel1) or (m['Number']
                             == tel2):  # If telephone is admin 1 or admin 2
            log.info(NAME, datetime_string() + ': ' + _('SMS from admin'))
            if m['State'] == "UnRead":  # If SMS is unread
                log.clear(NAME)
                if m['Text'] == comm1:  # If command = comm1 (info - send SMS to admin phone1 and phone2)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm1 + ' ' + _('is processed'))
                    # send 1/2 SMS with text 1
                    up = helpers.uptime()
                    temp = helpers.get_cpu_temp(
                        options.temp_unit) + ' ' + options.temp_unit
                    ip = str(helpers.get_ip())
                    ver = version.ver_date
                    datastr = ('SMS 1/2. ' + datetime_string() + ', TEMP: ' +
                               temp + ', IP: ' + ip + ', SW: ' + ver +
                               ', UP: ' + up)
                    message = {
                        'Text': datastr,
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)  # send sms 1/2
                    log.info(NAME, datastr)
                    # send 2/2 SMS with text 2
                    if inputs.rain_sensed():
                        rain = "Active"
                    else:
                        rain = "Inactive"
                    try:
                        from plugins import pressure_monitor
                        state_press = pressure_monitor.get_check_pressure()

                        if state_press:
                            press = "High"
                        else:
                            press = "Low"
                    except Exception:
                        press = "N/A"
                    finished = [
                        run for run in log.finished_runs()
                        if not run['blocked']
                    ]
                    if finished:
                        last_prog = finished[-1]['start'].strftime(
                            '%H:%M: ') + finished[-1]['program_name']
                    else:
                        last_prog = 'None'
                    datastr = ('SMS 2/2. ' + 'RAIN: ' + rain + ', PRESS: ' +
                               press + ', LAST: ' + last_prog)
                    message = {
                        'Text': datastr,
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)  # send sms 2/2
                    log.info(NAME, datastr)

                    log.info(
                        NAME,
                        _('Command') + ': ' + comm1 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    sm.DeleteSMS(m['Folder'], m['Location'])  # SMS deleted
                    log.info(NAME, _('Received SMS was deleted'))

                elif m['Text'] == comm2:  # If command = comm2 (stop - scheduler)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm2 + ' ' + _('is processed'))
                    options.scheduler_enabled = False
                    log.finish_run(None)
                    stations.clear()

                    message = {
                        'Text': 'Command: ' + comm2 + ' was processed',
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + comm2 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    sm.DeleteSMS(m['Folder'], m['Location'])
                    log.info(NAME, _('Received SMS was deleted'))

                elif m['Text'] == comm3:  # If command = comm3 (start - scheduler)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm3 + ' ' + _('is processed'))
                    options.scheduler_enabled = True
                    message = {
                        'Text': 'Command: ' + comm3 + ' was processed',
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + comm3 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    sm.DeleteSMS(m['Folder'], m['Location'])
                    log.info(NAME, _('Received SMS was deleted'))

                elif m['Text'] == comm4:  # If command = comm4 (reboot system)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm4 + ' ' + _('is processed'))
                    message = {
                        'Text': 'Command: ' + comm4 + ' was processed',
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + comm4 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    sm.DeleteSMS(m['Folder'], m['Location'])
                    log.info(
                        NAME,
                        _('Received SMS was deleted and system is now reboot'))
                    reboot()  # restart linux system

                elif m['Text'] == comm5:  # If command = comm5 (poweroff system)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm5 + ' ' + _('is processed'))
                    message = {
                        'Text': 'Command: ' + comm5 + ' was processed',
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + comm5 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    sm.DeleteSMS(m['Folder'], m['Location'])
                    log.info(
                        NAME,
                        _('Received SMS was deleted and system is now poweroff'
                          ))
                    poweroff()  # poweroff linux system

                elif m['Text'] == comm6:  # If command = comm6 (update ospi system)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm6 + ' ' + _('is processed'))
                    message = {
                        'Text': 'Command: ' + comm6 + ' was processed',
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + comm6 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    try:
                        from plugins.system_update import perform_update

                        perform_update()
                        log.info(
                            NAME,
                            _('Received SMS was deleted, update was performed and program will restart'
                              ))
                    except ImportError:
                        log.info(
                            NAME,
                            _('Received SMS was deleted, but could not perform update'
                              ))

                    sm.DeleteSMS(m['Folder'], m['Location'])

                elif m['Text'] == comm7:  # If command = comm7 (send email with foto from webcam)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm7 + ' ' + _('is processed'))
                    message = {
                        'Text': 'Command: ' + comm7 + ' was processed',
                        'SMSC': {
                            'Location': 1
                        },
                        'Number': m['Number'],
                    }
                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + comm7 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    try:
                        from plugins.webcam import get_run_cam, get_image_location

                        get_run_cam()  # process save foto to ./data/image.jpg
                        msg = _('SMS plug-in send image file from webcam.')

                        send_email(msg, attach=get_image_location())

                    except ImportError:
                        log.info(
                            NAME,
                            _('Received SMS was deleted, but could not send email with photo from webcam'
                              ))
                        message = {
                            'Text': 'Error: not send foto from webcam',
                            'SMSC': {
                                'Location': 1
                            },
                            'Number': m['Number'],
                        }
                        sm.SendSMS(message)
                    sm.DeleteSMS(m['Folder'], m['Location'])

                elif m['Text'] == comm8:  # If command = comm8 (send SMS with available commands)
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm8 + ' ' + _('is processed'))
                    message = {
                        'Text':
                        'Available commands: ' + comm1 + ',' + comm2 + ',' +
                        comm3 + ',' + comm4 + ',' + comm5 + ',' + comm6 + ',' +
                        comm7 + ',' + comm8 + ',' + comm9 + 'xx',
                        'SMSC': {
                            'Location': 1
                        },
                        'Number':
                        m['Number'],
                    }
                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + comm8 + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    sm.DeleteSMS(m['Folder'], m['Location'])
                    log.info(NAME, _('Received SMS was deleted'))

                elif m['Text'][0:len(
                        comm9
                )] == comm9:  # If command = lenght char comm9 (run now program xx)
                    num = m['Text'][len(
                        comm9
                    ):]  # number from sms text example: run36 -> num=36
                    log.info(
                        NAME,
                        _('Command') + ' ' + comm9 + ' ' + _('is processed'))
                    index = int(num)
                    if index <= programs.count(
                    ):  # if program number from sms text exists in program db
                        log.finish_run(None)
                        stations.clear()
                        prog = int(index - 1)
                        programs.run_now(prog)
                        log.info(
                            NAME,
                            _('Program') + ': ' + str(index) + ' ' +
                            _('now run'))
                        message = {
                            'Text': 'Program: ' + str(index) + ' now run',
                            'SMSC': {
                                'Location': 1
                            },
                            'Number': m['Number'],
                        }
                    else:
                        message = {
                            'Text': 'Program: ' + str(index) + ' no exists!',
                            'SMSC': {
                                'Location': 1
                            },
                            'Number': m['Number'],
                        }

                    sm.SendSMS(message)
                    log.info(
                        NAME,
                        _('Command') + ': ' + str(m['Text']) + ' ' +
                        _('was processed and confirmation was sent as SMS to')
                        + ': ' + m['Number'])
                    sm.DeleteSMS(m['Folder'], m['Location'])
                    log.info(NAME, _('Received SMS was deleted'))

                else:  # If SMS command is not defined
                    sm.DeleteSMS(m['Folder'], m['Location'])
                    log.info(
                        NAME,
                        _('Received command') + ' ' + m['Text'] + ' ' +
                        _('is not defined!'))

            else:  # If SMS was read
                sm.DeleteSMS(m['Folder'], m['Location'])
                log.info(NAME, _('Received SMS was deleted - SMS was read'))
        else:  # If telephone number is not admin 1 or admin 2 phone number
            sm.DeleteSMS(m['Folder'], m['Location'])
            log.info(NAME,
                     _('Received SMS was deleted - SMS was not from admin'))
コード例 #8
0
ファイル: __init__.py プロジェクト: lthill/OSPy-plugins
def get_report(index):
    result = None
    station_state = False
    station_result = ''

    for station in stations.get():  # check if station runing
        if station.active:
            station_state = True  # yes runing
            station_result += str(
                station.index +
                1) + ', '  # station number runing ex: 2, 6, 20,

    if (options.lang == 'cs_CZ'):
        if station_state and lcd_options[
                'd_running_stations']:  # print on LCD only this text
            if index == 0 or index == 2 or index == 4 or index == 6 or index == 8 or index == 10 or index == 12 or index == 14 or index == 16 or index == 18 or index == 20:  # start text to 16x1
                result = "Stanice v chodu:"
            elif index == 1 or index == 3 or index == 5 or index == 7 or index == 9 or index == 11 or index == 13 or index == 15 or index == 17 or index == 19 or index == 21:
                result = station_result
            return result

        else:
            if index == 0:  # start text to 16x1
                if lcd_options['d_system_name']:
                    result = "ID systemu:"
                else:
                    result = None
            elif index == 1:
                if lcd_options['d_system_name']:
                    result = options.name
                else:
                    result = None

            elif index == 2:
                if lcd_options['d_sw_version_date']:
                    result = "FW Verze:"
                else:
                    result = None
            elif index == 3:
                if lcd_options['d_sw_version_date']:
                    result = version.ver_str + ' (' + version.ver_date + ')'
                else:
                    result = None

            elif index == 4:
                if lcd_options['d_ip']:
                    result = "IP adresa:"
                else:
                    result = None
            elif index == 5:
                if lcd_options['d_ip']:
                    ip = helpers.get_ip()
                    result = str(ip)
                else:
                    result = None

            elif index == 6:
                if lcd_options['d_port']:
                    result = "Port:"
                else:
                    result = None
            elif index == 7:
                if lcd_options['d_port']:
                    result = str(options.web_port)
                else:
                    result = None

            elif index == 8:
                if lcd_options['d_cpu_temp']:
                    result = "Teplota CPU:"
                else:
                    result = None
            elif index == 9:
                if lcd_options['d_cpu_temp']:
                    result = helpers.get_cpu_temp(
                        options.temp_unit) + ' ' + options.temp_unit
                else:
                    result = None

            elif index == 10:
                if lcd_options['d_time_date']:
                    result = datetime.now().strftime('Dat %d.%m.%Y')
                else:
                    result = None
            elif index == 11:
                if lcd_options['d_time_date']:
                    result = datetime.now().strftime('Cas %H:%M:%S')
                else:
                    result = None

            elif index == 12:
                if lcd_options['d_uptime']:
                    result = "V provozu:"
                else:
                    result = None
            elif index == 13:
                if lcd_options['d_uptime']:
                    result = helpers.uptime()
                else:
                    result = None

            elif index == 14:
                if lcd_options['d_rain_sensor']:
                    result = "Cidlo deste:"
                else:
                    result = None
            elif index == 15:
                if lcd_options['d_rain_sensor']:
                    if inputs.rain_sensed():
                        result = "aktivni"
                    else:
                        result = "neaktivni"
                else:
                    result = None

            elif index == 16:
                if lcd_options['d_last_run']:
                    result = 'Naposledy bezel'
                else:
                    result = None
            elif index == 17:
                if lcd_options['d_last_run']:
                    finished = [
                        run for run in log.finished_runs()
                        if not run['blocked']
                    ]
                    if finished:
                        result = finished[-1]['start'].strftime(
                            '%d-%m-%Y v %H:%M:%S program: '
                        ) + finished[-1]['program_name']
                        result = result.replace('Run-Once', 'Jednorazovy')
                        result = result.replace('Manual', 'Rucne')
                    else:
                        result = 'zadny program'
                else:
                    result = None

            elif index == 18:
                if lcd_options['d_pressure_sensor']:
                    result = "Cidlo tlaku:"
                else:
                    result = None
            elif index == 19:
                if lcd_options['d_pressure_sensor']:
                    try:
                        from plugins import pressure_monitor
                        state_press = pressure_monitor.get_check_pressure()
                        if state_press:
                            result = "neaktivni"
                        else:
                            result = "aktivni"

                    except Exception:
                        result = "neni k dispozici"
                else:
                    result = None

            elif index == 20:
                if lcd_options['d_water_tank_level']:
                    result = "Nadrz s vodou:"
                else:
                    result = None
            elif index == 21:
                if lcd_options['d_water_tank_level']:
                    try:
                        from plugins import tank_humi_monitor
                        cm = tank_humi_monitor.get_sonic_tank_cm()
                        if cm > 0:
                            result = str(cm) + ' cm'
                        else:
                            result = "chyba - I2C zarizeni nenalezeno!"

                    except Exception:
                        result = "neni k dispozici"
                else:
                    result = None

            return ASCI_convert(result)

    if (options.lang == 'en_US') or (options.lang == 'default'):
        if station_state and lcd_options[
                'd_running_stations']:  # print on LCD only this text
            if index == 0 or index == 2 or index == 4 or index == 6 or index == 8 or index == 10 or index == 12 or index == 14 or index == 16 or index == 18 or index == 20:  # start text to 16x1
                result = "Running stations:"
            elif index == 1 or index == 3 or index == 5 or index == 7 or index == 9 or index == 11 or index == 13 or index == 15 or index == 17 or index == 19 or index == 21:
                result = station_result
            return result

        else:

            if index == 0:
                if lcd_options['d_system_name']:
                    result = options.name
                else:
                    result = None
            elif index == 1:
                if lcd_options['d_system_name']:
                    result = "Irrigation system"
                else:
                    result = None

            elif index == 2:
                if lcd_options['d_sw_version_date']:
                    result = "SW Version:"
                else:
                    result = None
            elif index == 3:
                if lcd_options['d_sw_version_date']:
                    result = version.ver_str + ' (' + version.ver_date + ')'
                else:
                    result = None

            elif index == 4:
                if lcd_options['d_ip']:
                    result = "My IP is:"
                else:
                    result = None
            elif index == 5:
                if lcd_options['d_ip']:
                    ip = helpers.get_ip()
                    result = str(ip)
                else:
                    result = None

            elif index == 6:
                if lcd_options['d_port']:
                    result = "My Port is:"
                else:
                    result = None
            elif index == 7:
                if lcd_options['d_port']:
                    result = str(options.web_port)
                else:
                    result = None

            elif index == 8:
                if lcd_options['d_cpu_temp']:
                    result = "CPU Temperature:"
                else:
                    result = None
            elif index == 9:
                if lcd_options['d_cpu_temp']:
                    result = helpers.get_cpu_temp(
                        options.temp_unit) + ' ' + options.temp_unit
                else:
                    result = None

            elif index == 10:
                if lcd_options['d_time_date']:
                    result = datetime.now().strftime('Date: %d.%m.%Y')
                else:
                    result = None
            elif index == 11:
                if lcd_options['d_time_date']:
                    result = datetime.now().strftime('Time: %H:%M:%S')
                else:
                    result = None

            elif index == 12:
                if lcd_options['d_uptime']:
                    result = "System Uptime:"
                else:
                    result = None
            elif index == 13:
                if lcd_options['d_uptime']:
                    result = helpers.uptime()
                else:
                    result = None

            elif index == 14:
                if lcd_options['d_rain_sensor']:
                    result = "Rain Sensor:"
                else:
                    result = None
            elif index == 15:
                if lcd_options['d_rain_sensor']:
                    if inputs.rain_sensed():
                        result = "Active"
                    else:
                        result = "Inactive"
                else:
                    result = None

            elif index == 16:
                if lcd_options['d_last_run']:
                    result = 'Last Program:'
                else:
                    result = None
            elif index == 17:
                if lcd_options['d_last_run']:
                    finished = [
                        run for run in log.finished_runs()
                        if not run['blocked']
                    ]
                    if finished:
                        result = finished[-1]['start'].strftime(
                            '%H:%M: ') + finished[-1]['program_name']
                        result = result.replace('Run-Once', 'Jednorazovy')
                    else:
                        result = 'None'
                else:
                    result = None

            elif index == 18:
                if lcd_options['d_pressure_sensor']:
                    result = "Pressure Sensor:"
                else:
                    result = None
            elif index == 19:
                if lcd_options['d_pressure_sensor']:
                    try:
                        from plugins import pressure_monitor
                        state_press = pressure_monitor.get_check_pressure()
                        if state_press:
                            result = "GPIO is HIGH"
                        else:
                            result = "GPIO is LOW"

                    except Exception:
                        result = "Not Available"
                else:
                    result = None

            elif index == 20:
                if lcd_options['d_water_tank_level']:
                    result = "Water Tank Level:"
                else:
                    result = None
            elif index == 21:
                if lcd_options['d_water_tank_level']:
                    try:
                        from plugins import tank_humi_monitor
                        cm = tank_humi_monitor.get_sonic_tank_cm()
                        if cm > 0:
                            result = str(cm) + ' cm'
                        else:
                            result = "Error - I2C Device Not Found!"

                    except Exception:
                        result = "Not Available"
                else:
                    result = None

            return result
コード例 #9
0
ファイル: __init__.py プロジェクト: martinpihrt/OSPy-plugins
def get_overview():
    """Returns the info data as a list of lines."""
    result = []
    try:
        meminfo = helpers.get_meminfo()
        netdevs = helpers.get_netdevs()

        result.append(_('System release') + ': {}'.format(platform.release()))
        result.append(_('System name') + ': {}'.format(platform.system()))
        result.append(_('Node') + ': {}'.format(platform.node()))
        result.append(_('Machine') + ': {}'.format(platform.machine()))
        if is_python2():
            result.append(
                _('Distribution') +
                ': {} {}'.format(platform.linux_distribution()[0],
                                 platform.linux_distribution()[1]))
        else:
            try:  # python > 3.9
                import distro
                result.append(
                    _('Distribution') +
                    ': {} {}'.format(distro.linux_distribution()[0],
                                     distro.linux_distribution()[1]))
            except:  # python <= 3.9
                result.append(
                    _('Distribution') +
                    ': {} {}'.format(platform.linux_distribution()[0],
                                     platform.linux_distribution()[1]))
                pass
        result.append(_('Total memory') + ': {}'.format(meminfo['MemTotal']))
        result.append(_('Free memory') + ': {}'.format(meminfo['MemFree']))
        result.append(_('Python') + ': {}'.format(platform.python_version()))
        if netdevs:
            for dev, info in netdevs.items():
                result.append('%-16s %s MiB %s MiB' %
                              (dev + ': ', info['rx'], info['tx']))
        else:
            result.append(_('Network: Unknown'))
        result.append(_('Uptime') + ': {}'.format(helpers.uptime()))
        result.append(
            _('CPU temp') + ': {} {}'.format(
                helpers.get_cpu_temp(options.temp_unit), options.temp_unit))
        result.append(
            _('CPU usage') + ': {} %'.format(helpers.get_cpu_usage()))
        result.append(
            _('CPU serial number') + ': {}'.format(helpers.cpu_info()))
        result.append(_('MAC adress') + ': {}'.format(helpers.get_mac()))
        result.append(_('I2C HEX Adress') + ': ')
        try:
            result.append(get_all_addr())
        except Exception:
            result.append(_('Could not open any i2c device!'))

        # I2C test for Air Temperature and Humidity Monitor plugin
        if find_address(0x03):
            result.append(
                _('Found ATMEGA328 for Air Temperature and Humidity Monitor plugin (0x03).'
                  ))

        # I2C test for Water Tank Monitor plugin
        if find_address(0x04):
            result.append(
                _('Found ATMEGA328 for Water Tank Monitor plugin (0x04).'))

        # I2C test for Humidity Monitor plugin
        if find_address(0x05):
            result.append(
                _('Found ATMEGA328 for Humidity Monitor plugin (0x05).'))

        # I2C test for Button Control plugin
        if find_address(0x27):
            result.append(
                _('Found MCP23017 for Button Control plugin (0x27).'))

        # I2C test for LCD Display plugin
        search_range = {addr: 'PCF8574' for addr in range(32, 40)}
        search_range.update({addr: 'PCF8574A' for addr in range(56, 63)})
        if find_address(search_range, range=True):
            if find_address(0x27):
                result.append(
                    _('Warning: MCP23017 found for Button Control plugin (0x27). The address for PCF8574 must be different, not 0x27! If it is the same, change it on the LCD display board.'
                      ))
            result.append(
                _('Found PCF8574 for LCD Display plugin (0x20-0x28, 0x38-0x3F).'
                  ))

        # I2C test for Wind Speed Monitor/ Water Meter meter plugin
        search_range = {addr: 'PCF8583' for addr in range(80, 81)}
        if find_address(search_range, range=True):
            result.append(
                _('Found PCF8583 for Wind Speed Monitor or Water Meter plugin (0x50-0x51).'
                  ))

        # I2C test for Real Time and NTP time plugin
        if find_address(0x68):
            result.append(
                _('Found DS1307 for Real Time and NTP time plugin (0x68).'))

    except Exception:
        log.error(NAME, traceback.format_exc())
        pass

    return result