📜 ⬆️ ⬇️

Indication of a new Gmail message via Arduino

A week ago I received a parcel with Freeduino 2009 - a complete analogue of the Arduino Duemilanove.


I want to show a simple example. In this example, Arduino will inform you about new messages on Gmail. Since, until you purchased the LCD display, the LED will blink as an indication.

The application consists of 2 parts. The first part on the PC is a Python script that, using cron, runs every n minutes, checks messages and sends the number of unread messages on the serial port to the Arduino. The second part of the Arduino is a skateboard, which checks the value sent from the PC and if the letters are greater than zero, the LED starts blinking.
')

LED connection scheme:


Script in Python, the PySerial library is required for work:

Copy Source | Copy HTML<br/> <br/> import urllib, re, serial<br/> <br/>gml = '' <br/>username = "***" <br/>password = "***" <br/>adr = "https://" +username+ ":" +password+ "@mail.google.com/mail/feed/atom" <br/>cont = urllib .urlopen(adr) <br/>s = cont.read() <br/> <br/>reg = re . compile (r "<fullcount>\d+</fullcount>" ) <br/> <br/>gmlcnt = reg.search(s).group()<br/>reg2 = re . compile (r "\d+" ) <br/>gml = reg2.search(gmlcnt).group()<br/> <br/>ser = serial.Serial( '/dev/ttyUSB0' , 9600 )<br/>ser.write(gml)<br/>ser.close() <br/>

Skate for Arduino:

Copy Source | Copy HTML<br/> <br/>int ledPin = 13 ; <br/>int mail = 0 ;<br/>int i = 0 ;<br/> <br/>void setup(){ <br/> Serial.begin( 9600 );<br/> pinMode( ledPin, OUTPUT ); <br/>}<br/> <br/>void led_blink(){<br/> if ( i == 1 ){<br/> digitalWrite( ledPin, HIGH );<br/> delay( 500 );<br/> digitalWrite( ledPin, LOW );<br/> delay( 1000 );<br/> }<br/> delay( 1000 );<br/>}<br/> <br/>void loop(){ <br/> if ( Serial.available( ) > 0 ){<br/> mail = Serial.read();<br/> if ( char(mail ) != '0' ){<br/> i = 1 ;<br/> }<br/> else{<br/> i = 0 ;<br/> digitalWrite( ledPin, LOW );<br/> } <br/> }<br/> led_blink();<br/>} <br/>

In crontab you prescribe the path to the script and the interval between runs. In Arduino, you skate and enjoy the flashing LED when you receive new messages.

Source: https://habr.com/ru/post/90576/


All Articles