#!/usr/bin/env python #coding: utf8 # Ohjelma joka kuuntelee varashälyttimen sarjaporttia # ja suorittaa komentoja sen mukaan mitä hälytin käskee # Author: Joni Junni # Date: 13.5.2013 import serial import time import smtplib ser1 = serial.Serial("/dev/tty.usbmodem1421") while True: try: line = ser1.readline() #print(line) timestamp = time.asctime( time.localtime(time.time()) ) if line.find('ALARM') !=-1: message = timestamp + ': ALARM WAS TRIGGERED' sender = 'arduinohalytys@gmail.com' receivers = ['joni.junni@me.com'] emailmsg = """From: Arduino Alert To: Joni Junni Subject: Alert was triggered! Your home might be intruded. """ try: smtpObj = smtplib.SMTP('smtp.gmail.com', 587) smtpObj.ehlo() smtpObj.starttls() smtpObj.ehlo() smtpObj.login('arduinohalytys','Trolololo') smtpObj.sendmail(sender, receivers, emailmsg) print "Successfully sent email" except smtplib.SMTPException: print "Error: unable to send email" elif line.find('UU') !=-1: message = timestamp + ': Unauthorized user tried to log in' elif line.find('AU') !=-1: message = timestamp + ': Authorized user has been logged' elif line.find('MS') !=-1: message = timestamp + ': Door was Closed' elif line.find('PS') !=-1: message = timestamp + ': Motion stopped' elif line.find('P') !=-1: message = timestamp + ': Motion detected' elif line.find('M') !=-1: message = timestamp + ': Door Open' elif line.find('A') !=-1: message = timestamp + ': System Armed' elif line.find('D') !=-1: message = timestamp + ': System Disarmed' f = open('alertLog.log','a') f.write(message + '\n') print message except (serial.serialutil.SerialException, OSError): pass