Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import Adafruit_DHT
- import MySQLdb
- import RPi.GPIO as GPIO
- import os
- from os import system
- import time
- from time import gmtime, strftime #importamos gmtime y strftime
- #===================================================================
- # SENSOR LLAMA + AGUA + HUMO + PIR
- llama_sensor = 27
- humo_sensor = 6
- agua_sensor = 17
- pir_sensor = 13
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(llama_sensor, GPIO.IN)
- GPIO.setup(humo_sensor, GPIO.IN)
- GPIO.setup(agua_sensor, GPIO.IN)
- GPIO.setup(pir_sensor, GPIO.IN)
- current_state = 0
- try:
- while True:
- # time.sleep(0.1)
- # current_state = GPIO.input(pir_sensor)
- # if current_state == 1:
- # print("GPIO pin %s is %s" % (pir_sensor, current_state))
- # system('echo "Se ha detectado un aviso del sensor de movimiento" | mutt -s "Alarma de movimiento" asir.domotica@gmail.com')
- # timex = strftime("%d-%m-%Y %H:%M:%S", gmtime()) #Creamos una cadena$
- # print timex + " MOVIMIENTO DETECTADO" #La sacamos por pantalla
- time.sleep(0.1)
- current_state = GPIO.input(llama_sensor)
- if current_state == 0:
- # print("GPIO pin %s is %s" % (llama_sensor, current_state))
- timex = strftime("%d-%m-%Y %H:%M:%S", gmtime()) #Creamos una cadena$
- system('echo "Se ha detectado una alarma de fuego" | mutt -s "Alarma de fuego" asir.domotica@gmail.comm')
- # print timex + " LLAMA DETECTADA" #La sacamos por pantalla
- # else:
- # print " NO SE HA DETECTADO NADA"
- current_state = GPIO.input(humo_sensor)
- if current_state == 1:
- # print("GPIO pin %s is %s" % (humo_sensor, current_state))
- timex = strftime("%d-%m-%Y %H:%M:%S", gmtime()) #Creamos una cadena$
- system('echo "Se ha detectado una alarma de humo" | mutt -s "Alarma de humo" asir.domotica@gmail.com')
- # print timex + " HUMO DETECTADO" #La sacamos por pantalla
- # else:
- # print " NO SE HA DETECTADO NADA"
- current_state = GPIO.input(agua_sensor)
- if current_state == 0:
- # print("GPIO pin %s is %s" % (agua_sensor, current_state))
- timex = strftime("%d-%m-%Y %H:%M:%S", gmtime()) #Creamos una cadena$
- system('echo "Se ha detectado un aviso de agua" | mutt -s "Alarma de lluvia" asir.domotica@gmail.com')
- # print timex + " AGUA DETECTADA" #La sacamos por pantalla
- # else:
- # print " NO SE HA DETECTADO NADA"
- time.sleep(5)
- except KeyboardInterrupt:
- pass
- finally:
- GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement