Gmail Notification - Using Raspberry Pi running python script.
Python 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()
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
// 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);