示例#1
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
示例#2
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
示例#3
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
示例#4
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
示例#5
0
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
示例#6
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
示例#7
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
示例#8
0
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)
示例#9
0
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
示例#10
0
    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)
示例#11
0
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
示例#12
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()
示例#13
0
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)
示例#14
0
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)