/amazon-dash-rpi

A python script running on the Raspberry Pi that listens for the Amazon Dash Button press, and logs to a Google Sheet.

Primary LanguagePython

Amazon Dash Hack with the Raspberry Pi

Sources & Inspiration:

Why Use the Raspberry Pi?

The Amazon Dash Button hack typically works by using a Python script that listens for the button's ARP Probe. Most tutorials just cover running the script and capturing a few button presses, but what if you don't want to leave your main desktop or laptop on 24/7 just to listen for button presses? If you want to use the button long-term, you'll want the listener script to auto-start and run constantly, and it'd also be a plus to use as little power as possible. That's why I prefer using the Raspberry Pi, which only uses 2-5 Watts.

Stuff to install on Raspberry Pi's Debian

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install tcpdump python-scapy

Get Python Pip and install gspread and oauth2client:

sudo apt-get update
sudo apt-get install python-pip
sudo pip install gspread oauth2client

Initial 'Listen' script from the initial article

Customized so it can work on Raspberry Pi. Fixes the "IndexError: Layer [ARP] not found" error. Main edits are line 3, if pkt.haslayer(ARP): and last line, count=0 so that it runs forever.

from scapy.all import *

def arp_display(pkt):
  if pkt.haslayer(ARP):
    if pkt[ARP].op == 1: #who-has (request)
      if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
        print "ARP Probe from: " + pkt[ARP].hwsrc

print sniff(prn=arp_display, filter="arp", store=0, count=0)

Let's try posting directly to Google Sheets without Cloudstich shenanigans

Run the script

sudo python habits.py

Notes about going DIY

  • It's a bit harder, as you might imagine, but quite valuable in picking up some python and knowledge about how to fix code that is outdated or no longer supported, and adapting to API updates
  • Google changed their oauth2client.client since the Adafruit docs were written about logging info to Google Sheets, so need to update cpde fpr that as well. (from oauth2client.client import SignedJwtAssertionCredentials to from oauth2client.service_account import ServiceAccountCredentials Discussion and Updated docs
  • Will need to update Raspberry Pi to Python 2.7.3 to 2.7.9 to get rid of gspread InsecurePlatformWarning
    • wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz
    • Source
  • Had to reinstall a bunch of things after building Python 2.7.9 from source... python-pkg-resources
  • Easier to just update Raspberry Pi Debian Wheezy to Jessie - It has Python 2.7.9 by default
sudo apt-get install --reinstall python-pkg-resources
gunzip Python-2.7.9.tgz
tar -xvf Python-2.7.9.tar
cd Python-2.7.9/
./configure
make
sudo make install
python -V # check version to see that it took

Running a Python Script on-boot with a cron job

Source: Running A Python Script At Boot Using Cron

Install Crontab on OSMC

sudo apt-get update
sudo apt-get install cron

Edit root's crontab

sudo crontab -e

Add this to the end of it (no need for sudo since it's already root's crontab): @reboot python /home/osmc/scripts/habits.py &

Check that root is actually running the script

ps aux | grep /home/osmc/scripts/habits.py

Look for root 252 10.9 2.3 20260 18008 ? S 16:08 0:03 python /home/osmc/scripts/habits.py

If you need to kill the script/job, run sudo kill 252

Other options

Blocking Amazon Dash Phone Notifications

You'll probably receive annoying notifications on your phone asking you to complete the setup process. To prevent these notifications, you'll need to block the Amazon Dash Button from reaching the internet by tweaking your router settings.