Go Down

Topic: Gmail Notification Globe (Read 1 time) previous topic - next topic

n1ck75

Feb 24, 2013, 03:19 pm Last Edit: Feb 24, 2013, 03:29 pm by n1ck75 Reason: 1
Gmail Notification - Using Raspberry Pi running python script.



Python Code:
Code: [Select]
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()

robtillaart

Looks good!
Can you post the Python code too? (you may leave out your google account details ;)
Rob Tillaart

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


robtillaart

#3
Feb 24, 2013, 03:33 pm Last Edit: Feb 24, 2013, 03:56 pm by robtillaart Reason: 1
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
Rob Tillaart

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

n1ck75

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: [Select]
// 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);

robtillaart

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.
Rob Tillaart

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

Go Up