31.07.2015 Views

A-Teachers-Guide-to-the-Intel-Galileo-Final

A-Teachers-Guide-to-the-Intel-Galileo-Final

A-Teachers-Guide-to-the-Intel-Galileo-Final

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

A TEACHER’S GUIDE TO THE INTEL® GALILEO | 64Coding <strong>the</strong> PythonCreate a python file called UnreadEmailChecker.py with <strong>the</strong> following contents:import imaplibobj = imaplib.IMAP4_SSL('imap.gmail.com', '993')obj.login('yourEmail@gmail.com,'yourPassword')obj.select()print len(obj.search(None,'UnSeen')[1][0].split())Explanation of <strong>the</strong> codeThe first line imports a module called imaplib which has functions for sending mail.import imaplibThe next three lines initialise an object with <strong>the</strong> mail server address and login <strong>to</strong> your mailserver . You need <strong>to</strong> put in <strong>the</strong> correct details here for your mail server and your mail account.obj = imaplib.IMAP4_SSL('imap.gmail.com', '993')obj.login('yourEmail@gmail.com,'yourPassword')obj.select()The final line uses <strong>the</strong> search method <strong>to</strong> return <strong>the</strong> number of UnSeen emails and <strong>the</strong>n printsa count of <strong>the</strong>se. For more information on <strong>the</strong> imaplib methods go <strong>to</strong> https://docs.python.org/2/library/imaplib.htmlprint len(obj.search(None,'UnSeen')[1][0].split())Breaking this line down fur<strong>the</strong>r, obj.search(None,'UnSeen') returns a tuple of which<strong>the</strong> second element has data and we are interested in <strong>the</strong> first item of data which is why wehave <strong>the</strong> array index [1][0]. The response is a space separated list so we need <strong>to</strong> call <strong>the</strong> split()command <strong>to</strong> remove <strong>the</strong> final space.The len() command gives us <strong>the</strong> length which corresponds <strong>to</strong> <strong>the</strong> number of emails and <strong>the</strong>n weprint that number.Coding <strong>the</strong> ArduinoUpload <strong>the</strong> following sketch <strong>to</strong> your Arduino and you should start getting your light going onwhen you have unread emails./* <strong>Galileo</strong> Email Checkerby Sarah BoydAdapted from Jim LindblomSparkFun ElectronicsThis code runs a Python script which calls a Gmail account andwrites <strong>the</strong> number of unread emails <strong>to</strong> a file.*///////////////////////// Library Includes ////////////////////////#include // E<strong>the</strong>rnet library//////////////////////////

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!