Ejemplo n.º 1
0
 def ldr():
     bulb_flg = 0
     while (1):
         time.sleep(2)
         #reading RTC value
         t = i2c.i2c_time()
         os.system("clear")
         print "Time : ", t
         #reading LDR value
         LDR = spi.adc_read(0)
         print "LDR : ", LDR
         if LDR > 3600 and bulb_flg == 0:
             time.sleep(3)
             LDR = spi.adc_read(0)
             if LDR > 3600:
                 data = {'BULB': 'ON'}
                 pubnub.publish(channel1,
                                data,
                                callback=callback,
                                error=callback)
                 GPIO.output(BULB, False)
                 message = client.messages.create(
                     to="+919446047003",
                     from_="+141xxxxxx32",
                     body="Light is turning on at " + t)
                 print message.sid
                 bulb_flg = 1
         elif LDR <= 3600:  #and bulb_flg==1:
             GPIO.output(BULB, True)
             bulb_flg = 0
Ejemplo n.º 2
0
    def temper():
        fan_flg = 0
        while (1):
            time.sleep(2)
            #reading RTC value
            t = i2c.i2c_time()
            os.system("clear")
            print "Time : ", t
            #reading temperature value
            tem = temp.read_temp()
            print "Temperature : ", tem, " c"

            if int(tem) > 28 and fan_flg == 0:
                time.sleep(3)
                tem = temp.read_temp()
                if int(tem) > 28:
                    data = {'FAN': 'ON'}
                    pubnub.publish(channel1,
                                   data,
                                   callback=callback,
                                   error=callback)
                    GPIO.output(FAN, False)
                    message = client.messages.create(
                        to="+918075946770",
                        from_="+14xxxxxxxxxxxxxxxxx32",
                        body="AC is turning on at " + t + "\ntemperature : " +
                        str(tem))
                    print message.sid
                    fan_flg = 1
            elif int(tem) <= 28 and fan_flg == 1:
                GPIO.output(FAN, True)
                fan_flg = 0
    def pir():

        while (1):
            #reading RTC value
            t = i2c.i2c_time()
            os.system("clear")
            print "Time : ", t  #not needed given for testing code
            if GPIO.input(PIR):
                print "Security alert"
                data = {'Security': 'Alert'}
                pubnub.publish(channel1,
                               data,
                               callback=callback,
                               error=callback)
                c = cam.PiCamera()
                c.capture("img.jpg")
                c.close()
                GPIO.output(WARNING, False)
                message = client.messages.create(
                    to="+919446047003",
                    from_="+14xxxxxxxx2",
                    body="Some one at Home \n\nTime: " + t)
                s = mail.my_mail("gmail username", "password")
                s.send_mail("*****@*****.**",
                            "Attention:Security Issue",
                            "Some one in your home", "./img.jpg")

                time.sleep(10)
                GPIO.output(WARNING, True)
            time.sleep(1)  #not needed  given only for checking value
    def temper():
        fan_flg = 0
        while (1):
            time.sleep(1)  #not needed  given only for checking value
            #reading RTC value
            t = i2c.i2c_time()
            os.system("clear")
            print "Time : ", t  #not needed given for testing code
            #reading temperature value
            tem = temp.read_temp()
            print "Temperature : ", tem, " c"  #not needed given for testing code

            if tem > 29.0 and fan_flg == 0:
                time.sleep(3)
                tem = temp.read_temp()
                if tem > 29.0:
                    data = {'FAN': 'ON'}
                    pubnub.publish(channel1,
                                   data,
                                   callback=callback,
                                   error=callback)
                    GPIO.output(FAN, False)
                    message = client.messages.create(
                        to="+919446047003",
                        from_="+14xxxxxxx2",
                        body="AC is turning on at " + t + "\ntemperature : " +
                        str(tem))
                    print message.sid
                    fan_flg = 1
            elif tem <= 29.0 and fan_flg == 1:
                GPIO.output(FAN, True)
                fan_flg = 0
Ejemplo n.º 5
0
def main():
    adc_setup()
    while (1):
        os.system("clear")
        data = adc_read(0)
        data1 = adc_read(1)
        print "channel : ", data, "   channel2 : ", data1, "  ", i2c.i2c_time()
        time.sleep(1)
 def ir():
     while (1):
         #reading RTC value
         time.sleep(1)  #not needed  given only for checking value
         t = i2c.i2c_time()
         os.system("clear")
         print "Time : ", t  #not needed given for testing code
         #reading IR value
         IR = spi.adc_read(1)
         print "IR : ", IR  #not needed given for testing code
         if IR < 3000:
             GPIO.output(TAP, False)
             time.sleep(3)
             GPIO.output(TAP, True)
Ejemplo n.º 7
0
 def ir():
     tap_flg = 0
     while (1):
         #reading RTC value
         time.sleep(2)
         t = i2c.i2c_time()
         os.system("clear")
         print "Time : ", t
         #reading IR value
         IR = spi.adc_read(1)
         print "IR : ", IR
         if IR < 4000 and tap_flg == 0:
             GPIO.output(TAP, False)
             time.sleep(3)
             GPIO.output(TAP, True)
Ejemplo n.º 8
0
 def pir():
     while (1):
         time.sleep(2)
         #reading RTC value
         t = i2c.i2c_time()
         os.system("clear")
         print "Time : ", t
         if GPIO.input(PIR):
             print "Security alert"
             data = {'Security': 'Alert'}
             pubnub.publish(channel1,
                            data,
                            callback=callback,
                            error=callback)
             GPIO.output(WARNING, False)
             message = client.messages.create(
                 to="+919446047003",
                 from_="+141xxxxxx2",
                 body="Some one at Home \n\nTime: " + t)
             time.sleep(10)
             GPIO.output(WARNING, True)
             time.sleep(2)