0

I am trying to write a script when motion is detected it will send me an email, can anyone help me put this script here

    enter import smtplib

smtpUser = '[email protected]'
smtpPass = 'mypassword'

toAdd = '[email protected]'
fromAdd = smtpUser

subject = 'Test'
header = 'To: ' + toAdd + '\n' + 'From: ' + fromAdd + '\n' + 'Subject: ' + subject
body = 'From pi'

print header + '\n' + body

s = smtplib.SMTP('smtp.gmail.com',587)

s.ehlo()
s.starttls()
s.ehlo()

s.login(smtpUser, smtpPass)
s.sendmail(fromAdd, toAdd, header + '\n' + body)

s.quit()

Into this script here if any motion is detected

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(10,GPIO.OUT)
GPIO.setup(21,GPIO.IN)

while True:
    input_state = GPIO.input(21)
    if input_state == True:
        GPIO.output(10,1)
        print "motion detected"
        time.sleep(2)
        GPIO.output(10,0)
        time.sleep(2)
1
  • This being a programming question, it would be best asked on the StackOverflow board.
    – goobering
    Jun 19, 2016 at 18:18

1 Answer 1

0

Best you ask this question on Stack Overflow, this is out of scope for this site.

Anyways, from your code it looks like that the if input_state == True: is the condition that detects motion, so you need to put your entire e-mail sending script inside that if code block.

Not the answer you're looking for? Browse other questions tagged or ask your own question.