Merge pull request #492 from adafruit/Raspberry_Pi_E-mail_Notifier_Using_LEDs
Raspberry pi email notifier using leds
This commit is contained in:
commit
7807c7aafb
2 changed files with 49 additions and 0 deletions
4
Raspberry_Pi_E-mail_Notifier_Using_LEDs/README.md
Normal file
4
Raspberry_Pi_E-mail_Notifier_Using_LEDs/README.md
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Raspberry_Pi_E-mail_Notifier_Using_LEDs
|
||||||
|
|
||||||
|
Code to accompany this tutorial:
|
||||||
|
https://learn.adafruit.com/raspberry-pi-e-mail-notifier-using-leds
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
import time
|
||||||
|
import board
|
||||||
|
from imapclient import IMAPClient
|
||||||
|
from digitalio import DigitalInOut, Direction
|
||||||
|
|
||||||
|
HOSTNAME = 'imap.gmail.com'
|
||||||
|
MAILBOX = 'Inbox'
|
||||||
|
MAIL_CHECK_FREQ = 60 # check mail every 60 seconds
|
||||||
|
|
||||||
|
# The following three variables must be customized for this
|
||||||
|
# script to work
|
||||||
|
USERNAME = 'your username here'
|
||||||
|
PASSWORD = 'your password here'
|
||||||
|
NEWMAIL_OFFSET = 1 # my unread messages never goes to zero, use this to override
|
||||||
|
|
||||||
|
# setup Pi pins as output for LEDs
|
||||||
|
green_led = DigitalInOut(board.D18)
|
||||||
|
red_led = DigitalInOut(board.D23)
|
||||||
|
green_led.direction = Direction.OUTPUT
|
||||||
|
red_led.direction = Direction.OUTPUT
|
||||||
|
|
||||||
|
def mail_check():
|
||||||
|
# login to mailserver
|
||||||
|
server = IMAPClient(HOSTNAME, use_uid=True, ssl=True)
|
||||||
|
server.login(USERNAME, PASSWORD)
|
||||||
|
|
||||||
|
# select our MAILBOX and looked for unread messages
|
||||||
|
unseen = server.folder_status(MAILBOX, ['UNSEEN'])
|
||||||
|
|
||||||
|
# number of unread messages
|
||||||
|
# print to console to determine NEWMAIL_OFFSET
|
||||||
|
newmail_count = (unseen[b'UNSEEN'])
|
||||||
|
print('%d unseen messages' % newmail_count)
|
||||||
|
|
||||||
|
if newmail_count > NEWMAIL_OFFSET:
|
||||||
|
green_led.value = True
|
||||||
|
red_led.value = False
|
||||||
|
else:
|
||||||
|
green_led.value = False
|
||||||
|
red_led.value = True
|
||||||
|
|
||||||
|
time.sleep(MAIL_CHECK_FREQ)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
mail_check()
|
||||||
Loading…
Reference in a new issue