Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Email Notifier Tutorial

by Exigent on Sat Jan 05, 2013 2:24 pm

tried this as my first project on RPi but getting this error when i run the script:

File "./raspi-gmail.py", line 2
SyntaxError: Non-ASCII character '\xc2' in file ./raspi-gmail.py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

this is what i used to create the file by just copy/paste :

cat <<! > raspi-gmail.py
#!/usr/bin/env python

import RPi.GPIO as GPIO, feedparser, time

DEBUG = 1

USERNAME = "username" # just the part before the @ sign, add yours here
PASSWORD = "password"

NEWMAIL_OFFSET = 1 # my unread messages never goes to zero, yours might
MAIL_CHECK_FREQ = 60 # check mail every 60 seconds

GPIO.setmode(GPIO.BCM)
GREEN_LED = 18
RED_LED = 23
GPIO.setup(GREEN_LED, GPIO.OUT)
GPIO.setup(RED_LED, GPIO.OUT)

while True:

newmails = int(feedparser.parse("https://" + USERNAME + ":" + PASSWORD +"@mail.google.com/gmail/feed/atom")["feed"]["fullcount"])

if DEBUG:
print "You have", newmails, "new emails!"

if newmails > NEWMAIL_OFFSET:
GPIO.output(GREEN_LED, True)
GPIO.output(RED_LED, False)
else:
GPIO.output(GREEN_LED, False)
GPIO.output(RED_LED, True)

time.sleep(MAIL_CHECK_FREQ)
!

Any ideas? Can I just delete the file and start over ?
Exigent
 
Posts: 1
Joined: Thu Dec 20, 2012 7:46 am

Re: Email Notifier Tutorial

by Killerspec on Fri Feb 15, 2013 2:39 pm

Hi

Looking for some help! I have put together this project and I know that the e-mail thing is working as in Putty window it is showing the updates. My problem is that my LED's stay on all the time no matter what I do I even tried to change the out puts from 18 and 23 to 21 and 24 but no joy please help.

Thanks a million in advance.

Matthew
Killerspec
 
Posts: 1
Joined: Tue Feb 22, 2011 10:51 am

Re: Email Notifier Tutorial

by Wanders11 on Fri Feb 22, 2013 10:03 am

I am having a lot of problems running this script, BUT I have found and solved my instance of the problem you have.

I don't know what the origin of it was, but there were unprintable characters showing up in my raspi-gmail.py after I created it and tried to run it.

I both cut and pasted or handwrote the script using either nano or Leafpad. I removed blank lines and the problem would disappear (for that line - only to be replaced by the same error in the next blank line) SO: What I found were unprintable characters (possibly formatting or control codes) that were carried into the script. Removing the line and reinserting it cured the problem - even when there was a "blank" line. It turns out that the line wasn't blank, just unprintable.

I hope this helps.
Wanders11
 
Posts: 1
Joined: Sat Jan 19, 2013 11:59 am

Raspberry Pi E-mail Notifier Using LEDs

by Ron2222 on Wed Mar 06, 2013 4:08 pm

I am also have a problem making the Gmail Python working. when I run the program here is what I get:
pi@raspberrypi ~ $ sudo ./raspi-gmail.py
Traceback (most recent call last):
File "./raspi-gmail.py", line 21, in <module>
newmails = int(feedparser.parse("https://" + USERNAME + ":" + PASSWORD +"@ma il.google.com/gmail/feed/atom")["feed"]["fullcount"])
File "/usr/local/lib/python2.7/dist-packages/feedparser.py", line 375, in __ge titem__
return dict.__getitem__(self, key)
KeyError: 'fullcount'

I am new to the Raspberry Pi and Python. If someone would be so kind to help me
Thanks Ron
Ron2222
 
Posts: 2
Joined: Fri Feb 15, 2013 7:01 pm

Re: Email Notifier Tutorial

by killeth on Wed May 22, 2013 4:00 pm

Hi just a quick update to the problem with the copy and paste section in the tutorial. The problem arises because the window the code appears in has embedded hidden code and when you copy it, it carries that hidden code with it. At the bottom of that window on the right hand side you can click to see the raw file. Click here and another screen in your browser will open, this is pure text without any hidden formatting code. Copy this and you will not have any problems with pasting and creating the file. BUT the python script will not run on my Pi and I am desperately searching for the reason. Which is why I ended up here Hey oh.
killeth
 
Posts: 1
Joined: Wed May 22, 2013 3:31 pm

Re: Email Notifier Tutorial

by sjarvis on Sun Jun 09, 2013 8:25 pm

I have the script running under Occidentalis 0.2, and the script returns the proper value from gmail, but NOTHING lights up on my board.

I have my RPi B connected with the ribbon cable to a Pi Cobbler on a half-size board. Everything is wired up exacly like in the photos in the tutorial, but I can't get any LEDs to light up.

I don't have any female-to-male wires to try connecting straight from the GPIO pins to the breadboard, but I suspect hardware issues.

Do I need to restart the RPi after each time I wire the board up or change something?

Thanks,

Steven
sjarvis
 
Posts: 4
Joined: Sun Jun 09, 2013 8:20 pm

Re: Email Notifier Tutorial

by adafruit_support_mike on Mon Jun 10, 2013 1:45 pm

Are you sure your LED is plugged in the right way around? More generally, have you tested the LED by applying voltage directly and confirming that it lights up?
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 8676
Joined: Thu Feb 11, 2010 1:51 pm

Re: Email Notifier Tutorial

by sjarvis on Tue Jun 11, 2013 12:02 am

Turns out I had my GPIO ribbon cable installed backwards. I read and re-read and re-read AGAIN the setup, but I kept incorrectly interpreting the directions on how to hook up the ribbon cable.
sjarvis
 
Posts: 4
Joined: Sun Jun 09, 2013 8:20 pm

Re: Email Notifier Tutorial

by adafruit_support_mike on Tue Jun 11, 2013 4:30 pm

Ah, the old "ribbon cable orientation issue".. it's driven many a brave soul to drink, despair, and the occasional "calibration hammer" incident.

Welcome to the club, and I'm glad you got it working. ;-)
When you void a product warranty, you give up your right to sue the manufacturer if something goes wrong and accept full responsibility for whatever happens next. And then you truly own the product.
User avatar
adafruit_support_mike
 
Posts: 8676
Joined: Thu Feb 11, 2010 1:51 pm

Re: Email Notifier Tutorial

by phil.drummond on Sat Jun 22, 2013 6:32 pm

I got the email notifier to work with my Pi and LCD pi plate!
Here is my script...
Code: Select all | TOGGLE FULL SIZE
#!/usr/bin/env python

from time import sleep
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
import RPi.GPIO as GPIO, feedparser, time

# Initialize the LCD plate.  Should auto-detect correct I2C bus.  If not,
# pass '0' for early 256 MB Model B boards or '1' for all later versions
lcd = Adafruit_CharLCDPlate()

# Clear display and show greeting, pause 1 sec
lcd.clear()
lcd.message("raspi-gmail.py")
sleep(1)

DEBUG = 1

USERNAME = "username" # just the part before the @ sign, add yours here
PASSWORD = "password"

NEWMAIL_OFFSET = 0 # my unread messages never goes to zero, yours might
MAIL_CHECK_FREQ = 600

while True:

   newmails = int(feedparser.parse("https://" + USERNAME + ":" + PASSWORD +"@mail.google.com/gmail/feed/atom")["feed"]["fullcount"])

   if DEBUG:
      lcd.clear()
      text = "Mail Count: " + str(newmails)
      lcd.message('GMAIL username\n')
      lcd.message(text)

      if newmails > NEWMAIL_OFFSET:
         col = (lcd.RED)
         lcd.backlight(col)
      else:
         col = (lcd.GREEN)
         lcd.backlight(col)

   sleep(MAIL_CHECK_FREQ)
phil.drummond
 
Posts: 125
Joined: Sun Feb 08, 2009 3:57 pm