Online Sales Physical Notification with a Raspberry Pi 
Friday, January 24, 2014, 18:15
Selling no longer wanted things from my apartment online with Amazon and Ebay is one of my new favorite hobbies. I take pride in getting quality items out for sale in a timely manner but it has been a constant drag to be checking my email account hundreds of times a day to see if I have sold anything. I’ve been mentally working on an idea to have my ceiling mounted LEDs turn on every time I have a new sale to ship out. I finally sat down to implement this project a few nights ago and was shocked when it only took me about 20 minutes to get everything working the way I wanted.

The hardware component of this is shown below:

Image Removed

This is the set of LED’s that I have attached to the ceiling with thumbtacks and some cardboard. I’ve lately added the green strand of LED leaves that I got at the dollar store. I’ve been controlling these lights with the same “LazierGeek” app I use to turn my binary clock on and off with. The only difference now is that I also let the following scripts turn on the light if they want to.
curl -u username:password --silent "" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n "s/<title>\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p

This is a very hand bash script making use of curl that I found online which scrapes Gmail’s atom feed for unread emails and does some sed manipulation to trim down the output to just the senders name and subject. To get this one working just replace the username and password section with your appropriate account information. In conjunction with this script I made the following Python code to run it occasionally.
#!/usr/bin/env python
Unread email notifier - Spike Snell - 2014
Version 1.5
# Import what we need to drive the light
import time, sys, subprocess
import RPi.GPIO as GPIO
from datetime import datetime

# Set Up the GPIO to use our notification light
GPIO.setwarnings(False) # Set warnings to false
GPIO.setmode(GPIO.BOARD) # Use board pin numbering
GPIO.setup(5, GPIO.OUT) # Setup GPIO Pin 8 to OUT

# Loop Forever and Drive the Notification Light
while True:

GPIO.output(5,True) # Turn off the light by default

# Get the current local machine hour in 24 hour format
h = int('%H'))

# Make sure it is after 0700 and before 2100
if h > 6 and h < 21:
# The time is just right so check for sales with bash script
proc = subprocess.Popen(["bash",""], stdout=subprocess.PIPE)
(out, err) = proc.communicate()

# Check if there are recent unread mail subjects that indicate a sale
if out.find("ship now:") > 0 or out.find("item sold!") > 0:
GPIO.output(5,False) # Turn on the light

time.sleep(600) # Wait ten minutes
To run this notifier I use the command " sudo nohup python & " this lets me run the script in the background as a nohup ( no hang up ) process where the output is logged to nohup.out so that I can monitor the state of it remotely if I wish. Every 600 seconds ( 10 minutes ) this script will wake up from its slumber and fire the Gmail scraping bash script. If any of the subjects match text information indicating that an online sale has occurred it turns the LEDs on. If no sales have occurred lately it sets the LEDs to their off position. One handy feature of this is that after I have checked my email to see what sale occurred the lights automatically turn themselves off after a while since the email is no longer unread at that point. I might increase the delay in checking for sales since I’m a little hesitant to be polling Gmail for information this frequently and don’t want to be a nuisance to a service I rely so heavily on.

The only complaint I have about my notification system so far is that it is annoying when it comes on in the middle of the night when I am trying to sleep and wakes me up. I'm probably going to modify this code tonight so that it doesn't come on at night even if a sale has occurred but then operates normally if it is daytime.

So far this sales notification light has been working splendidly. Future expansions could include making the light blink to indicate how many sales have occurred or to have the script also text my phone to let me know that something sold. I’d love to hear any ideas or comments that the rest of you have about this small project.

-- Edit 2.11.14

I have updated the Python portion of the code to reflect my latest version which doesn't turn on at night. This one is much more straightforward because the indicator light's off position is the default state. Periodically the light will turn off briefly and then back on when going through another cycle if there is an active sale; this operational feature is to make it even more obvious that a sale has occurred.


Administrator (Spike Snell) 
Tuesday, February 11, 2014, 22:18
I have greatly simplified the python code portion by removing all of the else statements and turning the light off by default without needing to check if it should be off or not.
Administrator (Spike Snell) 
Tuesday, January 28, 2014, 15:47
Created a second version of this which doesn't turn the light on at night:
Monday, January 27, 2014, 13:18
Neat project, and nice job writing it up. Love the extra leaf bling!

the Immortal spirit of Pancho Villa Revolutionaire 
Saturday, January 25, 2014, 19:32
That's really cool little project. Makes me wanna do electronics soldiering again, though most likely I would end up with a sculpture that symbolizes the relation between the opressed and facebook comments rather than actual working gadget.

Samantha Province 
Saturday, January 25, 2014, 15:13
Its quite cool. You should def. do the phone thing. I love those leaf lights.

Love, Cat

Add Comment
Fill out the form below to add your own comments.

Insert Special:

Moderation is turned on for this blog. Your comment will require the administrators approval before it will be visible.