Notification of unread incoming letter using Arduino
Good day!
Recently I became interested in the Arduino platform. After the Arduino Mega 2560 board was received as a New Year present, I, like a decent novice robotics lover, blinked a diode, including through a button (which, by the way, were dropped from an old disassembled computer mouse).
It was after such standard experiments that I decided to do something useful. I was inspired by various videos from youtube, which showed how with the help of Arduino + Python a physical notification was implemented (someone had a blinking light, someone had a checkbox) about receiving a new mail to the gmail box. In this article I want to talk about my experience in creating such a “notification”. From the "iron" you need very little, here's what I used: ')
- Fee Arduino Mega 2560 - 1 pc. - USB cable for connecting the Arduino to the computer - 1 pc. - LED - 1 pc. I implemented the software part in C #. A program running on a computer does the following:
By timer, every 10 seconds the status of the mailbox is checked, if there are unread letters, then the value 1 is transmitted via the COM port, if there are no new letters, the value 2 is transmitted. To communicate with a C # program with Arduino, the SerialPort component is used, which is a standard Toolbox element in the C # Windows Forms project in Visual Studio 2010. There you can also find a timer.
To connect with the gmail mailbox and search for unread emails, use Mail.dll, which can be found on www.lesnikowski.com (I would not call it an advertisement, rather, copyright, but a special thank you to the author). The DLL is well documented, so we will not dwell on this point in detail. Consider a code that “reads letters”:
usingSystem; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Linq; usingSystem.Text; usingSystem.Windows.Forms; using Lesnikowski.Client.IMAP; // Mail.dll using Lesnikowski.Mail; using Lesnikowski.Mail.Headers; using Lesnikowski.Mail.Headers.Constants; namespace Arduino_Mail_Notification { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e) // { using (Imap imap = new Imap()) { imap.ConnectSSL("imap.gmail.com"); // IMAP- imap.Login("__e-mail", ""); // imap.SelectInbox(); // List<long> uids = imap.SearchFlag(Flag.Unseen); // serialPort1.PortName = "COM15"; // COM-, Arduino serialPort1.Open(); // COM- if (uids.Count > 0) // serialPort1.Write("1"); // Arduino "1" else // serialPort1.Write("2"); // Arduino "2" serialPort1.Close(); // COM- imap.Close(); // IMAP- } } } }
On the given code, anticipating questions, I will immediately answer some of them. Yes, it was possible to open the port and connect to the server once, and not by timer, every 10 seconds. Yes, I use someone else's dll-kami in this project, and not writing my classes. The reason for this is that at this stage the goal was to create not an ideal C # code and not describe how to check mail in C #, but to make the notification of new letters work, with which this code copes successfully.
What happens in Arduino when the numbers “1” or “2” arrive at it on the COM port? And the following happens in it:
Those. on Arduino, a fairly simple program is written down that practically deals with “physical notification” - in my case, when an unread letter appears in a box, the LED lights up. If the user has logged into his mailbox and read the letter, the diode will turn off within the next 10 and seconds of the timer, which will indicate that there are no unread letters.
As an example, I will cite one of the many videos that inspired me to create my own “notification”:
This is how my development of the Arduino began. I hope this project once will find its practical application and not only in my hands.