This is a small project I did with Raspberry pi to be able to water plants with an email sent to do so!
Here is what you need:
1. Rapberry pi
2. Hobby Motor
4. Rubber tube and some bottle cap
Below is the connection diagram between raspberry pi and motor chip (L293D). Credit goes to Adafruit lesson on DC motor. I followed the same connections and used the occidentalis software provided by them.
For the software to extract gmail titles to look for “Waterr” and water the plant, I followed the below code (With due credits to https://pythonadventures.wordpress.com/tag/gmail/)
#from motor1 import run_motor
import RPi.GPIO as io
in1_pin = 4
in2_pin = 17
def set(property, value):
f = open("/sys/class/rpi-pwm/pwm0/" + property, 'w')
print("Error writing to: " + property + " value: " + value)
FEED_URL = 'https://mail.google.com/mail/feed/atom'
def get_unread_msgs(user, passwd):
auth_handler = urllib2.HTTPBasicAuthHandler()
realm='New mail feed',
opener = urllib2.build_opener(auth_handler)
feed = urllib2.urlopen(FEED_URL)
if __name__ == "__main__":
# user = raw_input('Username: ')
# passwd = getpass.getpass('Password: ')
# print get_unread_msgs(user, passwd)
#make sure you change the below to yours
USER = 'USERNAME'
PASSWORD = PASSWORD'
xml = get_unread_msgs(USER, PASSWORD)
o = untangle.parse(xml)
for e in o.feed.entry:
title = e.title.cdata
# print title
if title == "Waterr":
print 'Watering the raspberry pi now'
#Call the motor function here to water.
pass # no new mail
Send email with subject as “Waterr” to see your raspberry pi watering your plants.
If you want to use cron tab, please follow the blog below (one of the best blogs I know on python)
If you want to execute it every few minutes, it is better to use code such as below than crontab (which is better used for boot time activities).