Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # coding: utf-8
- import RPi.GPIO as GPIO
- import picamera
- import datetime
- import time
- import MySQLdb as mysql
- import simplemail
- Pin = 7
- camera = picamera.PiCamera()
- zeit = datetime.datetime.now().hour
- db = mysql.connect(host="localhost", user="root", passwd="htltraun", db="test")
- GPIO.setmode(GPIO.BOARD)
- GPIO.setup(Pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
- def video_aufnehmen(video):
- print("Aufnahme")
- zeit = datetime.datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264")
- video.resolution = (640, 480)
- video.start_recording(zeit)
- video.start_preview()
- return video
- def stop_aufnehmen(video):
- print("Stopt Aufnahme")
- video.stop_recording()
- video.stop_preview()
- return video
- def alarmanlage(video):
- simplemail.Email(
- smtp_server = "bellatrix.uberspace.de:587",
- smtp_user = "projekt@jakobstadlhuber.com",
- smtp_password = "htltraun!432",
- from_address = "projekt@jakobstadlhuber.com",
- to_address = "projekthtl@gmx.at",
- subject = u"This is the subject with umlauts",
- message = u"This is the short message body with umla."
- ).send()
- video.capture('/var/www/foto.jpg', use_video_port=True)
- vor = False
- now = False
- while True:
- time.sleep(0.1)
- cursor = db.cursor()
- cursor.execute("""SELECT * From projekt""")
- ausgabe = cursor.fetchone()[1]
- print(ausgabe)
- vor = now
- now = GPIO.input(Pin)
- if now != vor:
- if now:
- if (zeit >= 17 or zeit <= 8) and ausgabe == 0:
- cursor = db.cursor()
- cursor.execute("""UPDATE projekt SET nr=1 WHERE id=1""")
- db.commit()
- cursor.close()
- video = video_aufnehmen(camera)
- alarmanlage(video)
- print("Email Versendet")
- else:
- video = video_aufnehmen(camera)
- else:
- stop_aufnehmen(video)
- else:
- print("ausgabe")
- cursor.close()
- aufgabe = None
- db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement