i'm having trouble with configuring sensors so that it can send an email via gmail when it is triggered.
im testing out first with a sound sensor. The sensor works when it is activated but i can't make it work so that i can be notified when it is.
Here is the code for the sensor working:
Code: Select all
#!/usr/bin/python import RPi.GPIO as GPIO import time #GPIO SETUP channel = 17 GPIO.setmode(GPIO.BCM) GPIO.setup(channel, GPIO.IN) def callback(channel): if GPIO.input(channel): print "Sound Detected!" GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime=300) # let us know when the pin goes HIGH or LOW GPIO.add_event_callback(channel, callback) # assign function to GPIO PIN, Run function on change # infinite loop while True: time.sleep(1)
And here is the code for the smtp:
I would really appreciate if you gave me an instruction on how to connect those two, and how to learn how to do the same to other sensors, that is to receive email when any sensor is triggered. This is for a project. If any of you could recommend any sites, links that i can learn from, then that would be sweet.
Code: Select all
#!/usr/bin/python import smtplib TO = 'firstname.lastname@example.org' SUBJECT = 'PIR' TEXT = 'Motion is detected' gmail_sender = 'email@example.com' gmail_passwd = 'mypwd' server = smtplib.SMTP('smtp.gmail.com', 587) server.ehlo() server.starttls() server.ehlo server.login(gmail_sender, gmail_passwd) BODY = '\r\n'.join([ 'TO: %s' % TO, 'From: %s' % gmail_sender , 'Subject: %s' % SUBJECT , '', TEXT ]) try: server.sendmail(gmail_sender, [TO], BODY) print 'email sent' except: print 'error' server.[/quote]quit()
thx again in advance.