コード例 #1
0
ファイル: helpers.py プロジェクト: bkoblenz/SIP
def restart(wait=1, block=False):
    """
    Restarts the software from a new thread.
    
    @type wait: int
    @param wait: length of time to wait before rebooting
    @type block: bool
    @param block: If True, clear output and perform reboot after wait.
        Set to True at start of thread (recursive).
    """
    if block:
        report_restart()
        from gpio_pins import set_output
        gv.srvals = [0] * (gv.sd['nst'])
        set_output()
        if gv.use_pigpio:
            pass
        else:
            GPIO.cleanup()
        time.sleep(wait)
        try:
            gv.logger.info(_('Restarting...'))
        except Exception:
            pass
        subprocess.Popen('service sip restart'.split())
    else:
        t = Thread(target=restart, args=(wait, True))
        t.start()
コード例 #2
0
ファイル: helpers.py プロジェクト: scudella/SIP
def poweroff(wait=1, block=False):
    """
    Powers off the Raspberry Pi from a new thread.
    
    @type wait: int or float
    @param wait: number of seconds to wait before rebooting
    @type block: bool
    @param block: If True, clear output and perform reboot after wait.
        Set to True at start of thread (recursive).
    """
    if block:
        from gpio_pins import set_output
        gv.srvals = [0] * (gv.sd['nst'])
        set_output()
        if gv.use_pigpio:
            pass
        else:
            GPIO.cleanup()
        time.sleep(wait)
        try:
            print _('Powering off...')
        except Exception:
            pass
        subprocess.Popen(['poweroff'])
    else:
        t = Thread(target=poweroff, args=(wait, True))
        t.start()
コード例 #3
0
ファイル: helpers.py プロジェクト: scudella/SIP
def restart(wait=1, block=False):
    """
    Restarts the software from a new thread.
    
    @type wait: int
    @param wait: length of time to wait before rebooting
    @type block: bool
    @param block: If True, clear output and perform reboot after wait.
        Set to True at start of thread (recursive).
    """
    if block:
        report_restart()
        from gpio_pins import set_output
        gv.srvals = [0] * (gv.sd['nst'])
        set_output()
        if gv.use_pigpio:
            pass
        else:
            GPIO.cleanup()
        time.sleep(wait)
        try:
            print _('Restarting...')
        except Exception:
            pass
        gv.restarted = 0
        subprocess.Popen('systemctl restart sip.service'.split())
    else:
        t = Thread(target=restart, args=(wait, True))
        t.start()
コード例 #4
0
def restart(wait=1, block=False):
    """
    Restarts the software from a new thread.
    Set to True at start of thread (recursive).
    """
    if block:
        report_restart()
        from gpio_pins import set_output

        gv.srvals = [0] * (gv.sd[u"nst"])
        set_output()
        if gv.use_pigpio:
            pass
        else:
            GPIO.cleanup()
        time.sleep(wait)
        try:
            print(_(u"Restarting..."))
        except Exception:
            pass
        gv.restarted = 0
        pid = os.getpid()
        command = u"systemctl status " + str(pid)
        output = str(subprocess.check_output(command.split()))
        unit_name = output.split()[1]
        command = u"systemctl restart " + unit_name
        subprocess.Popen(command.split())
    else:
        t = Thread(target=restart, args=(wait, True))
        t.start()
コード例 #5
0
ファイル: helpers.py プロジェクト: mirecta/SIP
def restart(wait=1, block=False):
    """
    Restarts the software from a new thread.
    Set to True at start of thread (recursive).
    """
    if block:
        report_restart()
        from gpio_pins import set_output

        gv.srvals = [0] * (gv.sd[u"nst"])
        set_output()
        if gv.use_pigpio:
            pass
        else:
            GPIO.cleanup()
        time.sleep(wait)
        try:
            print(_(u"Restarting..."))
        except Exception:
            pass
        gv.restarted = 0
        if six.PY2:
            subprocess.Popen(u"systemctl restart sip.service".split())
        elif six.PY3:
            subprocess.Popen(u"systemctl restart sip3.service".split())
    else:
        t = Thread(target=restart, args=(wait, True))
        t.start()
コード例 #6
0
ファイル: helpers.py プロジェクト: aocana/SIP
def reboot(wait=1, block=False):
    """
    Reboots the Raspberry Pi from a new thread.
    
    @type wait: int
    @param wait: length of time to wait before rebooting
    @type block: bool
    @param block: If True, clear output and perform reboot after wait.
        Set to True at start of thread (recursive).
    """
    if block:
        from gpio_pins import set_output
        gv.srvals = [0] * (gv.sd['nst'])
        set_output()
        if gv.use_pigpio:
            pass
        else:
            GPIO.cleanup()
        time.sleep(wait)
        try:
            print _('Rebooting...')
        except Exception:
            pass
        subprocess.Popen(['reboot'])
    else:
        t = Thread(target=reboot, args=(wait, True))
        t.start()
コード例 #7
0
ファイル: helpers.py プロジェクト: aocana/SIP
def check_rain():
    """
    Checks status of an installed rain sensor.
    
    Handles normally open and normally closed rain sensors
    
    Sets gv.sd['rs'] to 1 if rain is detected otherwise 0.
    """

    global pi
    try:
        if gv.sd['rst'] == 1:  # Rain sensor type normally open (default)
            if gv.use_pigpio:
                if not pi.read(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
            else:
                if not GPIO.input(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
        elif gv.sd['rst'] == 0:  # Rain sensor type normally closed
            if gv.use_pigpio:
                if pi.read(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
            else:
                if GPIO.input(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
    except NameError:
        pass
コード例 #8
0
ファイル: helpers.py プロジェクト: aocana/SIP
def poweroff(wait=1, block=False):
    """
    Powers off the Raspberry Pi from a new thread.
    
    @type wait: int or float
    @param wait: number of seconds to wait before rebooting
    @type block: bool
    @param block: If True, clear output and perform reboot after wait.
        Set to True at start of thread (recursive).
    """
    if block:
        from gpio_pins import set_output
        gv.srvals = [0] * (gv.sd['nst'])
        set_output()
        if gv.use_pigpio:
            pass
        else:
            GPIO.cleanup()
        time.sleep(wait)
        try:
            print _('Powering off...')
        except Exception:
            pass
        subprocess.Popen(['poweroff'])
    else:
        t = Thread(target=poweroff, args=(wait, True))
        t.start()
コード例 #9
0
ファイル: helpers.py プロジェクト: scudella/SIP
def check_rain():
    """
    Checks status of an installed rain sensor.
    
    Handles normally open and normally closed rain sensors
    
    Sets gv.sd['rs'] to 1 if rain is detected otherwise 0.
    """

    global pi
    try:
        if gv.sd['rst'] == 1:  # Rain sensor type normally open (default)
            if gv.use_pigpio:
                if not pi.read(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
            else:
                if GPIO.input(pin_rain_sense) == gv.sd[
                        'rs']:  #  Rain sensor changed, reading and gv.sd['rs'] are inverse.
                    report_rain_changed()
                    gv.sd['rs'] = 1 - gv.sd['rs']  #  toggle
        elif gv.sd['rst'] == 0:  # Rain sensor type normally closed
            if gv.use_pigpio:
                if pi.read(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
            else:
                if GPIO.input(
                        pin_rain_sense) != gv.sd['rs']:  # Rain sensor changed
                    report_rain_changed()
                    gv.sd['rs'] = 1 - gv.sd['rs']  #  toggle
    except NameError:
        pass
コード例 #10
0
ファイル: helpers.py プロジェクト: sbruggeman/SIP
def check_rain():
    """
    Checks status of an installed rain sensor.
    
    Handles normally open and normally closed rain sensors
    
    Sets gv.sd['rs'] to 1 if rain is detected otherwise 0.
    """

    global pi
    try:
        if gv.sd['rst'] == 1:  # Rain sensor type normally open (default)
            if gv.use_pigpio:
                if not pi.read(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
            else:
                if GPIO.input(pin_rain_sense) == gv.sd['rs']: #  Rain sensor changed, reading and gv.sd['rs'] are inverse.
                    report_rain_changed()
                    gv.sd['rs'] = 1 - gv.sd['rs'] #  toggle
        elif gv.sd['rst'] == 0:  # Rain sensor type normally closed
            if gv.use_pigpio:
                if pi.read(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
            else:
                if GPIO.input(pin_rain_sense) != gv.sd['rs']:  # Rain sensor changed
                    report_rain_changed()
                    gv.sd['rs'] = 1 - gv.sd['rs'] #  toggle
    except NameError:
        pass
コード例 #11
0
ファイル: helpers.py プロジェクト: scudella/SIP
def reboot(wait=1, block=False):
    """
    Reboots the Raspberry Pi from a new thread.
    
    @type wait: int
    @param wait: length of time to wait before rebooting
    @type block: bool
    @param block: If True, clear output and perform reboot after wait.
        Set to True at start of thread (recursive).
    """
    if block:
        from gpio_pins import set_output
        gv.srvals = [0] * (gv.sd['nst'])
        set_output()
        if gv.use_pigpio:
            pass
        else:
            GPIO.cleanup()
        time.sleep(wait)
        try:
            print _('Rebooting...')
        except Exception:
            pass
        subprocess.Popen(['reboot'])
    else:
        t = Thread(target=reboot, args=(wait, True))
        t.start()
コード例 #12
0
ファイル: helpers.py プロジェクト: cbright/OSPi
def check_rain():
    """
    Checks status of an installed rain sensor.
    
    Handles normally open and normally closed rain sensors
    
    Sets gv.sd['rs'] to 1 if rain is detected otherwise 0.
    """

    global pi
    try:
        if gv.sd['rst'] == 1:  # Rain sensor type normally open (default)
            if gv.use_pigpio:
                if not pi.read(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
            else:
                if not GPIO.input(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
        elif gv.sd['rst'] == 0:  # Rain sensor type normally closed
            if gv.use_pigpio:
                if pi.read(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
            else:
                if GPIO.input(pin_rain_sense):  # Rain detected
                    gv.sd['rs'] = 1
                else:
                    gv.sd['rs'] = 0
    except NameError:
        pass
コード例 #13
0
ファイル: relay.py プロジェクト: alustig/OSPi
 def GET(self):
     try:
         GPIO.output(pin_relay, GPIO.HIGH)  # turn relay on
         time.sleep(3)
         GPIO.output(pin_relay, GPIO.LOW)  # Turn relay off
     except Exception:
         pass
     raise web.seeother('/')  # return to home page
コード例 #14
0
def notify_zone_change(name, **kw):
    relayGPIO = 10 
    targetZone = 8

    if len(gv.srvals) >= targetZone:
        if gv.srvals[targetZone] == 1:
            GPIO.output(relayGPIO, GPIO.HIGH)
        else:
            GPIO.output(relayGPIO, GPIO.LOW)
コード例 #15
0
ファイル: helpers.py プロジェクト: ntc490/OSPi
def check_rain():
    try:
        if gv.sd['rst'] == 1:  # Rain sensor type normally open (default)
            if not GPIO.input(pin_rain_sense):  # Rain detected
                gv.sd['rs'] = 1
            else:
                gv.sd['rs'] = 0
        elif gv.sd['rst'] == 0:  # Rain sensor type normally closed
            if GPIO.input(pin_rain_sense):  # Rain detected
                gv.sd['rs'] = 1
            else:
                gv.sd['rs'] = 0
    except NameError:
        pass
コード例 #16
0
ファイル: helpers.py プロジェクト: jesper-skriver/OSPi
def check_rain():
    try:
        if gv.sd['rst'] == 1:  # Rain sensor type normally open (default)
            if not GPIO.input(pin_rain_sense):  # Rain detected
                gv.sd['rs'] = 1
            else:
                gv.sd['rs'] = 0
        elif gv.sd['rst'] == 0:  # Rain sensor type normally closed
            if GPIO.input(pin_rain_sense):  # Rain detected
                gv.sd['rs'] = 1
            else:
                gv.sd['rs'] = 0
    except NameError:
        pass
コード例 #17
0
ファイル: helpers.py プロジェクト: alustig/OSPi
def check_rain():
    try:
        if gv.sd['rst'] == 0:
            if GPIO.input(pin_rain_sense):  # Rain detected
                gv.sd['rs'] = 1
            else:
                gv.sd['rs'] = 0
        elif gv.sd['rst'] == 1:
            if not GPIO.input(pin_rain_sense):
                gv.sd['rs'] = 1
            else:
                gv.sd['rs'] = 0
    except NameError:
        pass
コード例 #18
0
ファイル: helpers.py プロジェクト: ntc490/OSPi
def poweroff(wait=1, block=False):
    if block:
        from gpio_pins import set_output
        gv.srvals = [0] * (gv.sd['nst'])
        set_output()
        GPIO.cleanup()
        time.sleep(wait)
        try:
            print _('Powering off...')
        except Exception:
            pass
        subprocess.Popen(['poweroff'])
    else:
        t = Thread(target=poweroff, args=(wait, True))
        t.start()
コード例 #19
0
ファイル: relay.py プロジェクト: Dan-in-CA/sip_plugins
    def GET(self):
        global pi
        try:
            if gv.use_pigpio:
                pi.write(pin_relay, 1)  
            else:
                GPIO.output(pin_relay, GPIO.HIGH)  # turn relay on
            time.sleep(3)
            if gv.use_pigpio:
                pi.write(pin_relay, 0)
            else:
                GPIO.output(pin_relay, GPIO.LOW)  # Turn relay off
        except Exception, e:
#            print "Relay plugin error: ", e
            pass
コード例 #20
0
ファイル: helpers.py プロジェクト: jesper-skriver/OSPi
def poweroff(wait=1, block=False):
    if block:
        from gpio_pins import set_output
        gv.srvals = [0] * (gv.sd['nst'])
        set_output()
        GPIO.cleanup()
        time.sleep(wait)
        try:
            print _('Powering off...')
        except Exception:
            pass
        subprocess.Popen(['poweroff'])
    else:
        t = Thread(target=poweroff, args=(wait, True))
        t.start()
コード例 #21
0
ファイル: relay.py プロジェクト: soxslayer/sip_plugins
 def GET(self):
     global pi
     try:
         if gv.use_pigpio:
             pi.write(pin_relay, 1)
         else:
             GPIO.output(pin_relay, GPIO.HIGH)  # turn relay on
         time.sleep(3)
         if gv.use_pigpio:
             pi.write(pin_relay, 0)
         else:
             GPIO.output(pin_relay, GPIO.LOW)  # Turn relay off
     except Exception, e:
         #            print "Relay plugin error: ", e
         pass
コード例 #22
0
ファイル: pressure_adj.py プロジェクト: teodoryantcheff/OSPy
def get_check_pressure():
    datapressure = get_pressure_options()
    try:
        if datapressure['normally'] != 'off':
            if GPIO.input(pin_pressure):  # pressure detected
                press = 1
            else:
                press = 0
        elif datapressure['normally'] != 'on':
            if not GPIO.input(pin_pressure):
                press = 1
            else:
                press = 0
        return press
    except NameError:
        pass
コード例 #23
0
ファイル: pressure_adj.py プロジェクト: soxslayer/sip_plugins
def get_pressure_sensor():
    if GPIO.input(pin_pressure) != 1:
        press = ('Pressure sensor is not active.')  # sensor pin is connected to ground
    else:
        press = ('Pressure sensor is active - pressure in pipeline is OK.')  # sensor pin is unconnected

    return str(press)
コード例 #24
0
def restart(wait=1, block=False):
    if block:
        from gpio_pins import set_output
        gv.srvals = [0] * (gv.sd['nst'])
        set_output()
        try:
            GPIO.cleanup()
        except Exception:
            pass
        time.sleep(wait)
        try:
            print _('Restarting...')
        except Exception:
            pass
        subprocess.Popen('service ospi restart'.split())
    else:
        t = Thread(target=restart, args=(wait, True))
        t.start()
コード例 #25
0
ファイル: helpers.py プロジェクト: ntc490/OSPi
def restart(wait=1, block=False):
    if block:
        from gpio_pins import set_output
        gv.srvals = [0] * (gv.sd['nst'])
        set_output()
        try:
            GPIO.cleanup()
        except Exception:
            pass
        time.sleep(wait)
        try:
            print _('Restarting...')
        except Exception:
            pass
        subprocess.Popen('service ospi restart'.split())
    else:
        t = Thread(target=restart, args=(wait, True))
        t.start()
コード例 #26
0
ファイル: ups_adj.py プロジェクト: teodoryantcheff/OSPy
def get_check_power():
    dataUPS = get_ups_options()
    try:
        if GPIO.input(pin_power_ok):  # power line detected
            pwr = 1
        else:
            pwr = 0
        return pwr
    except NameError:
        pass
コード例 #27
0
ファイル: pressure_adj.py プロジェクト: soxslayer/sip_plugins
    def run(self):
        time.sleep(randint(3, 10))  # Sleep some time to prevent printing before startup information
        print "Pressure plugin is active"
        send = False
        SUBJ = "Reporting from ospi"  # Subject in email
        self.add_status('Waiting...')

        while True:
            try:
                datapressure = get_pressure_options()                             # load data from file
                if datapressure['press'] != 'off':                                # if pressure plugin is enabled
                    if (gv.sd['mas'] != 0) and not (gv.sd['mm']):                   # if is use master station and not manual control
                        if gv.srvals[gv.sd['mas']] != 0:                              # if master station is ON
                            if GPIO.input(pin_pressure) == 0:                           # if sensor is open
                                self._sleep(int(datapressure['time']))                   # wait to activated pressure sensor
                                if GPIO.input(pin_pressure) == 0:                        # if sensor is current open
                                    stop_stations()
                                    self.add_status('Pressure sensor is not activated in time -> stops all stations and sends email.')
                                    if datapressure['sendeml'] != 'off':  # if enabled send email
                                        send = True

                    else:  # if not used master station
                        self.status = ''
                        self.add_status('Not used master station.')

                if send:
                    TEXT = ('On ' + time.strftime("%d.%m.%Y at %H:%M:%S", time.localtime(
                        time.time())) + ' System detected error: pressure sensor.')
                    try:
                        from plugins.email_adj import email
                        email(SUBJ, TEXT)     # send email without attachments
                        self.add_status('Email was sent: ' + TEXT)
                        send = False
                    except Exception as err:
                        self.add_status('Email was not sent! ' + str(err))

                self._sleep(1)

            except Exception:
                exc_type, exc_value, exc_traceback = sys.exc_info()
                err_string = ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback))
                self.add_status('Pressure plugin encountered error: ' + err_string)
                self._sleep(60)
コード例 #28
0
ファイル: helpers.py プロジェクト: mirecta/SIP
def reboot(wait=1, block=False):
    """
    Reboots the Raspberry Pi from a new thread.
    Set to True at start of thread (recursive).
    """
    if block:
        from gpio_pins import set_output

        gv.srvals = [0] * (gv.sd[u"nst"])
        set_output()
        if gv.use_pigpio:
            pass
        else:
            GPIO.cleanup()
        time.sleep(wait)
        try:
            print(_(u"Rebooting..."))
        except Exception:
            pass
        subprocess.Popen([u"reboot"])
    else:
        t = Thread(target=reboot, args=(wait, True))
        t.start()
コード例 #29
0
def check_rain():
    """
    Checks status of an installed rain sensor.
    Handles normally open and normally closed rain sensors
    Sets gv.sd["rs"] to 1 if rain is detected otherwise 0.
    """

    global pi
    rain_sensor = gv.sd[u"rs"]
    try:
        if gv.sd[u"rst"] == 1:  # Rain sensor type normally open (default)
            if gv.use_pigpio:
                if not pi.read(pin_rain_sense):  # Rain detected
                    rain_sensor = 1
                else:
                    rain_sensor = 0
            else:
                if (
                    GPIO.input(pin_rain_sense) == rain_sensor
                ):  #  Rain sensor changed, reading and gv.sd["rs"] are inverse.
                    rain_sensor = 1 - rain_sensor  #  toggle
        elif gv.sd[u"rst"] == 0:  # Rain sensor type normally closed
            if gv.use_pigpio:
                if pi.read(pin_rain_sense):  # Rain detected
                    rain_sensor = 1
                else:
                    rain_sensor = 0
            else:
                if GPIO.input(pin_rain_sense) != rain_sensor:  # Rain sensor changed
                    rain_sensor = 1 - rain_sensor  #  toggle
    except NameError:
        pass

    if gv.sd[u"rs"] != rain_sensor:  # Update if rain sensor changed
        gv.sd[u"rs"] = rain_sensor
        report_rain_changed()
コード例 #30
0
ファイル: ups_adj.py プロジェクト: teodoryantcheff/OSPy
################################################################################
# GPIO input pullup and output:                                                #
################################################################################

from gpio_pins import GPIO as GPIO

try:
    if gv.platform == 'pi':  # If this will run on Raspberry Pi:
        pin_power_ok = 16 # GPIO23
    elif gv.platform == 'bo':  # If this will run on Beagle Bone Black:
        pin_power_ok = " "
except AttributeError:
    pass

try:
    GPIO.setup(pin_power_ok, GPIO.IN, pull_up_down=GPIO.PUD_UP)
except NameError:
    pass

try:
    if gv.platform == 'pi':  # If this will run on Raspberry Pi:
        pin_ups_down = 18 # GPIO24
    elif gv.platform == 'bo':  # If this will run on Beagle Bone Black:
        pin_ups_down = " "
except AttributeError:
    pass

try:
    GPIO.setmode(GPIO.BOARD) ## Use board pin numbering
    GPIO.setup(pin_ups_down, GPIO.OUT)
    GPIO.output(pin_ups_down, GPIO.LOW)
コード例 #31
0
ファイル: pressure_adj.py プロジェクト: soxslayer/sip_plugins
################################################################################
# GPIO input pullup:                                                           #
################################################################################

from gpio_pins import GPIO as GPIO

try:
    if gv.platform == 'pi':  # If this will run on Raspberry Pi:
        pin_pressure = 22
    elif gv.platform == 'bo':  # If this will run on Beagle Bone Black:
        pin_pressure = "P9_17"
except AttributeError:
    pass

try:
    GPIO.setup(pin_pressure, GPIO.IN, pull_up_down=GPIO.PUD_UP)
except NameError:
    pass


################################################################################
# Main function loop:                                                          #
################################################################################

class PressureSender(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.daemon = True
        self.start()
        self.status = ''
コード例 #32
0
ファイル: ups_adj.py プロジェクト: teodoryantcheff/OSPy
def get_check_power_str():
    if GPIO.input(pin_power_ok) == 0:
        pwr = ('GPIO Pin = 0 Power line is OK.')  
    else:
        pwr = ('GPIO Pin = 1 Power line ERROR.')  
    return str(pwr)
コード例 #33
0
ファイル: ups_adj.py プロジェクト: teodoryantcheff/OSPy
    def run(self):
        time.sleep(randint(3, 10))  # Sleep some time to prevent printing before startup information
        reboot_time = False
        once = True
        once_two = True
        once_three = True
        subject = "Reporting from OSPy"  # Subject in email
        self.add_status('UPS plugin is started.')

        last_time = int(time.time())

        while True:
            try:
                dataUPS = get_ups_options()                             # load data from file
                if dataUPS['ups'] != 'off':                             # if ups plugin is enabled
                    test = get_check_power() 
                    if not test:
                       last_time = int(time.time())

                    if test:                                            # if power line is not active
                       reboot_time = True                               # start countdown timer
                       if once: 
                          if dataUPS['sendeml'] != 'off':               # if enabled send email
                             msg = 'UPS plugin detected fault on power line.' # send email with info power line fault
                             send_email(self, msg, subject)
                             once = False
                             once_three = True 

                    if reboot_time and test:
                       count_val = int(dataUPS['time'])*60 # value for countdown
                       actual_time = int(time.time())
                       self.status = ''
                       self.add_status('Time to shutdown: ' + str(count_val - (actual_time - last_time)) + ' sec')  
                       if ((actual_time - last_time) >= count_val):        # if countdown is 0
                          last_time = actual_time
                          test = get_check_power()
                          if test:                                         # if power line is current not active
                             self.add_status('Power line is not restore in time -> sends email and shutdown system.')
                             reboot_time = False  
                             if dataUPS['sendeml'] != 'off':               # if enabled send email
                                if once_two:
                                    msg = 'UPS plugin - power line is not restore in time -> shutdown system!' # send email with info shutdown system
                                    send_email(self, msg, subject)
                                    once_two = False 

                             GPIO.output(pin_ups_down, GPIO.HIGH)          # switch on GPIO fo countdown UPS battery power off 
                             self._sleep(4)
                             GPIO.output(pin_ups_down, GPIO.LOW) 
                             poweroff(1, True)                            # shutdown system      
          
                    if not test:
                         if once_three:
                            if dataUPS['sendeml'] != 'off':               # if enabled send email
                               msg = 'UPS plugin - power line has restored - OK.'
                               send_email(self, msg, subject)   
                               once = True
                               once_two = True
                               once_three = False                

                self._sleep(1)

            except Exception:
                exc_type, exc_value, exc_traceback = sys.exc_info()
                err_string = ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback))
                self.add_status('UPS plugin encountered error: ' + err_string)
                self._sleep(60)
コード例 #34
0
ファイル: pressure_adj.py プロジェクト: teodoryantcheff/OSPy
def get_pressure_sensor_str():
    if GPIO.input(pin_pressure) == 0:
        press = ('GPIO Pin = 0 is closed.')  
    else:
        press = ('GPIO Pin = 1 is open.')  
    return str(press)