I adapted his python code to something a little more appropriate for my usage:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2 | |
# Author: Will Price | |
# Date: Jan 2011 | |
# Import statements: | |
# - Feedparser - needed to extract mailcount | |
# - Serial - needed to send command to Arduino | |
# - Time - waiting for gmail to be read | |
import feedparser, serial, time | |
# Variables | |
checkPeriod = 60 # Time between check in seconds | |
username = "username" | |
password = "pass" | |
label = " " #Label of folder to check no. of unread messages | |
# Define 'msgCount' function, returns number of unread messages (CREDIT TO: Tom Paton) | |
def msgCount(uid, pwd, filter): | |
inbox = feedparser.parse("https://%s:%s@gmail.google.com/gmail/feed/atom%s" % (uid, pwd, filter)) | |
return len(inbox["entries"]) | |
# Loop | |
while True: | |
# Serial port setup | |
com = serial.Serial("/dev/ttyUSB0",9600,timeout=0.25) | |
msgs = msgCount(username, password, label) | |
if (msgs > 0): # If number of unread messages is greater than 0, then tell the arduino | |
com.write("%c" % (msgs) ) | |
# print "You have %d messages to read" % msgs # For debugging purposes | |
com.close() | |
while (msgs > 0): | |
msgs = msgCount(username, password, label) | |
time.sleep(10) | |
com = serial.Serial("/dev/ttyUSB0",9600,timeout=0.25) | |
com.write("%c" % 0) | |
# print "Inbox is empty" # For debugging purposes | |
com.close() | |
time.sleep(checkPeriod) |
(replace username and password with your username and password. You might also need to fiddle with the serial port I've got mine setup as /dev/ttyUSB1)
Here's the Arduino code:
Here's the Arduino code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gmail Notifier | |
// Author: Will Price | |
// Date: Jan 2011 | |
// Website: willprice94.blogspot.com | |
// Description: | |
// | |
// A simple sketch that waits for the number of unread messages to come over serial | |
// Use 'gmail_daemon' inconjunction for a physical mail notification system | |
// Macros | |
#include <Servo.h> | |
#define ServoPin 9 // The pin that the servo is connected to | |
// Variables | |
int msgs = 0; // Number of messages unread | |
//Setup Servo | |
Servo myservo; | |
//Initial Setup | |
void setup() { | |
pinMode(ServoPin, OUTPUT); | |
myservo.write(90); // Down position | |
myservo.attach(ServoPin); | |
Serial.begin(9600); | |
} | |
//Loop | |
if (Serial.available() > 0) { // Waiting to read from serial, if the buffer > 0 BYTES then execute code below | |
int msgs = Serial.read(); | |
if (msgs == 1) { | |
myservo.write(0); // Up position | |
} | |
else if (msgs == 0){ | |
myservo.write(90); // Down position | |
} | |
} | |
} |