Advertisement
Guest User

global

a guest
Jun 17th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.61 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3.  
  4. import Adafruit_DHT
  5. import MySQLdb
  6. import RPi.GPIO as GPIO
  7. import os
  8. from os import system
  9. import time
  10. from time import gmtime, strftime  #importamos gmtime y strftime
  11.  
  12. #===================================================================
  13.  
  14.  
  15.  
  16. # SENSOR LLAMA + AGUA + HUMO + PIR
  17.  
  18. llama_sensor = 27
  19. humo_sensor = 6
  20. agua_sensor = 17
  21. pir_sensor = 13
  22.  
  23.  
  24. GPIO.setmode(GPIO.BCM)
  25.  
  26.  
  27. GPIO.setup(llama_sensor, GPIO.IN)
  28. GPIO.setup(humo_sensor, GPIO.IN)
  29. GPIO.setup(agua_sensor, GPIO.IN)
  30. GPIO.setup(pir_sensor, GPIO.IN)
  31.  
  32.  
  33. current_state = 0
  34.  
  35.  
  36. try:
  37.     while True:
  38. #        time.sleep(0.1)
  39. #        current_state = GPIO.input(pir_sensor)
  40. #        if current_state == 1:
  41. #            print("GPIO pin %s is %s" % (pir_sensor, current_state))
  42. #            system('echo "Se ha detectado un aviso del sensor de movimiento" | mutt -s "Alarma de movimiento" asir.domotica@gmail.com')
  43. #            timex = strftime("%d-%m-%Y %H:%M:%S", gmtime()) #Creamos una cadena$
  44. #            print timex + " MOVIMIENTO DETECTADO"  #La sacamos por pantalla
  45.  
  46.  
  47.  
  48.  
  49.  
  50.         time.sleep(0.1)
  51.         current_state = GPIO.input(llama_sensor)
  52.         if current_state == 0:
  53. #            print("GPIO pin %s is %s" % (llama_sensor, current_state))
  54.             timex = strftime("%d-%m-%Y %H:%M:%S", gmtime()) #Creamos una cadena$
  55.         system('echo "Se ha detectado una alarma de fuego" | mutt -s "Alarma de fuego" asir.domotica@gmail.comm')
  56.  
  57. #            print timex + " LLAMA DETECTADA"  #La sacamos por pantalla
  58.  
  59. #   else:
  60. #       print " NO SE HA DETECTADO NADA"
  61.  
  62.  
  63.  
  64.  
  65.         current_state = GPIO.input(humo_sensor)
  66.         if current_state == 1:
  67. #            print("GPIO pin %s is %s" % (humo_sensor, current_state))
  68.             timex = strftime("%d-%m-%Y %H:%M:%S", gmtime()) #Creamos una cadena$
  69.         system('echo "Se ha detectado una alarma de humo" | mutt -s "Alarma de humo" asir.domotica@gmail.com')
  70.  
  71. #            print timex + " HUMO DETECTADO"  #La sacamos por pantalla
  72. #        else:
  73. #            print " NO SE HA DETECTADO NADA"
  74.  
  75.  
  76.  
  77.         current_state = GPIO.input(agua_sensor)
  78.         if current_state == 0:
  79. #            print("GPIO pin %s is %s" % (agua_sensor, current_state))
  80.             timex = strftime("%d-%m-%Y %H:%M:%S", gmtime()) #Creamos una cadena$
  81.             system('echo "Se ha detectado un aviso de agua" | mutt -s "Alarma de lluvia" asir.domotica@gmail.com')
  82. #            print timex + " AGUA DETECTADA"  #La sacamos por pantalla
  83.  
  84. #        else:
  85. #            print " NO SE HA DETECTADO NADA"
  86.  
  87.  
  88.         time.sleep(5)
  89. except KeyboardInterrupt:
  90.     pass
  91. finally:
  92.     GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement