Advertisement
Guest User

Untitled

a guest
Oct 29th, 2015
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3.  
  4. import RPi.GPIO as GPIO
  5. import picamera
  6. import datetime
  7. import time
  8. import MySQLdb as mysql
  9. import simplemail
  10.  
  11. Pin = 7
  12. camera = picamera.PiCamera()
  13. zeit = datetime.datetime.now().hour
  14. db = mysql.connect(host="localhost", user="root", passwd="htltraun", db="test")
  15. GPIO.setmode(GPIO.BOARD)
  16. GPIO.setup(Pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
  17.  
  18.  
  19. def video_aufnehmen(video):
  20.    print("Aufnahme")
  21.    zeit = datetime.datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264")      
  22.    video.resolution = (640, 480)
  23.    video.start_recording(zeit)
  24.    video.start_preview()
  25.    return video
  26.    
  27. def stop_aufnehmen(video):
  28.     print("Stopt Aufnahme")
  29.     video.stop_recording()
  30.     video.stop_preview()
  31.     return video
  32.  
  33. def alarmanlage(video):
  34.     simplemail.Email(
  35.     smtp_server = "bellatrix.uberspace.de:587",
  36.     smtp_user = "projekt@jakobstadlhuber.com",
  37.     smtp_password = "htltraun!432",
  38.     from_address = "projekt@jakobstadlhuber.com",
  39.     to_address = "projekthtl@gmx.at",
  40.     subject = u"This is the subject with umlauts",
  41.     message = u"This is the short message body with umla."
  42.     ).send()    
  43.  
  44.     video.capture('/var/www/foto.jpg', use_video_port=True)
  45.      
  46. vor = False
  47. now = False
  48.  
  49. while True:
  50.     time.sleep(0.1)
  51.     cursor = db.cursor()
  52.         cursor.execute("""SELECT * From projekt""")
  53.     ausgabe = cursor.fetchone()[1]
  54.     print(ausgabe)
  55.     vor = now
  56.     now = GPIO.input(Pin)
  57.     if now != vor:
  58.         if now:
  59.             if (zeit >= 17 or zeit <= 8) and ausgabe == 0:
  60.                 cursor = db.cursor()
  61.                 cursor.execute("""UPDATE projekt SET nr=1 WHERE id=1""")
  62.                 db.commit()
  63.                 cursor.close()
  64.                 video = video_aufnehmen(camera)
  65.                 alarmanlage(video)
  66.                 print("Email Versendet")
  67.             else:
  68.                 video = video_aufnehmen(camera)
  69.         else:
  70.             stop_aufnehmen(video)
  71.     else:
  72.         print("ausgabe")
  73.         cursor.close()
  74.         aufgabe = None 
  75.        
  76. db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement