Pages: [1]   Go Down
Author Topic: Gmail Notification Globe  (Read 1516 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Gmail Notification - Using Raspberry Pi running python script.



Python Code:
Code:
import serial, sys, feedparser
#Settings - Change these to match your account details
USERNAME="xxxxxxx"
PASSWORD="xxxxxxx"
PROTO="https://"
SERVER="mail.google.com"
PATH="/gmail/feed/atom"
SERIALPORT = "/dev/ttyACM0" # Change this to your serial port!
# Set up serial port
try:
ser = serial.Serial(SERIALPORT, 9600)
except serial.SerialException:
print "no device connected - exiting"
sys.exit()

newmails = int(feedparser.parse(PROTO + USERNAME + ":" + PASSWORD + "@" + SERVER + PATH)["feed"]["fullcount"])
   
# Output data to serial port
if newmails > 0:
ser.write("m")
print "some mail"
else:
ser.write("n")
print "no mail"
#print data to terminal


# Close serial port
ser.close()
« Last Edit: February 24, 2013, 09:29:22 am by n1ck75 » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks good!
Can you post the Python code too? (you may leave out your google account details smiley-wink
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

added
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you also describe the schematic?
From code I assume you have an Ethernet thingie on serial?

update -
Sorry, you're using feedparser() in the python to get the mails
« Last Edit: February 24, 2013, 09:56:36 am by robtillaart » Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Python script is running on a Raspberry Pi, pushes a N or M to the arduino which lights leds inside the globe if it gets a M (mail).

Really hoping i could done this with an Ethernet shield but couldn't Sketch below

Code:
// led wired + to pin 13, resistor to positive +5v

int outPin = 13; // Output connected to digital pin 13
int mail = LOW; // Is there new mail?
int val; // Value read from the serial port
const int ledPin =  13;      // the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated

// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000;
void setup()
{
 pinMode(outPin, OUTPUT); // sets the digital pin as output
 Serial.begin(9600);
 Serial.flush();
 mail = LOW; // start off with lights out
 }

void loop()
{
    unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = LOW;
    else
      ledState = HIGH;
    // set the LED with the ledState of the variable:
    digitalWrite(outPin, ledState);}
 // Read from serial port
 if (Serial.available())
 {
   val = Serial.read();
   Serial.println(val, byte(0));

   if (val == 110) // n = 110 in dec
   {
     mail = LOW;  // HIGH is off because led is connected to +5v on the other side
   }

   else if (val == 109) //109 = m in dec
   {
     mail = HIGH; // LOW is on because led is connected to +5v on the other side
   }
 }

 // Set the status of the output pin
 digitalWrite(outPin, mail);
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Idea:
you could also send the number of mails to the Arduino .
The using  analogWrite()  to the led to increase the light with the number of mails.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: