{"id":1868,"date":"2017-05-22T22:07:36","date_gmt":"2017-05-22T21:07:36","guid":{"rendered":"https:\/\/www.nathankowald.com\/blog\/?p=1868"},"modified":"2019-05-29T16:42:40","modified_gmt":"2019-05-29T15:42:40","slug":"dash-button-with-raspberry-pi","status":"publish","type":"post","link":"https:\/\/www.nathankowald.com\/blog\/2017\/05\/dash-button-with-raspberry-pi\/","title":{"rendered":"Dash Button with Raspberry Pi"},"content":{"rendered":"<p>I set up my Raspberry Pi to listen for <a href=\"http:\/\/amzn.to\/2rawcqr\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon Dash Button<\/a> presses recently.<br \/>\nRaspberry Pis are excellent devices for monitoring Dash button presses because they use very little electricity, so can be left running.<\/p>\n<p>I spent some time getting it working so I&#8217;m adding the steps I took here.<\/p>\n<p><strong>1. The easiest way to get a Dash button&#8217;s MAC address:<\/strong><br \/>\nFollow the steps in this post to find your Dash button&#8217;s MAC address.<\/p>\n<p>https:\/\/medium.com\/@bahman.\/hack-the-amazon-dash-button-jk29lp-on-macos-sierra-fe8b2312a471<\/p>\n<p><strong>2. Install the required dependencies:<\/strong><\/p>\n<pre class=\"prettyprint lang-sh\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\"># Update your software\nsudo apt-get update &amp;&amp; sudo apt-get upgrade\n\n# Install pydhcplib\nsudo apt-get install python-pip\nsudo pip install pydhcplib<\/pre>\n<p><strong>3. Copy this script to your Raspberry Pi<\/strong><br \/>\nThe easiest way is to use wget:<\/p>\n<pre class=\"prettyprint lang-sh\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">wget https:\/\/gist.githubusercontent.com\/mr-pj\/75297864abef5c8f2d5c134be2656023\/raw\/adc4de046c8972243eb322a6137d508da9c80372\/dashbutton.py<\/pre>\n<p>Here&#8217;s the script:<br \/>\n<script src=\"https:\/\/gist.github.com\/mr-pj\/75297864abef5c8f2d5c134be2656023.js\"><\/script><\/p>\n<p><strong>4. Replace the script&#8217;s MAC address with yours<\/strong><\/p>\n<pre class=\"prettyprint lang-sh\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\"># Replace \"50:f4:de:f1:3b:a0\" with the MAC address you found in step 1\n# It needs to be lowercase, with a colon after every two characters\ndashbuttons.register(\"50:f4:de:f1:3b:a0\", do_something)<\/pre>\n<p><strong>5. Make your Python script executable<\/strong><\/p>\n<pre class=\"prettyprint lang-sh\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">sudo chmod +x \/home\/pi\/dashbutton.py<\/pre>\n<p><strong>7. Test the script<\/strong><br \/>\nYour Python script should now be able to detect your Amazon Dash button presses. Test the Python script by running:<\/p>\n<pre class=\"prettyprint lang-sh\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">sudo python \/home\/pi\/dashbutton.py<\/pre>\n<p>Press your button and you should see the message, &#8220;button has been pressed&#8221;.<\/p>\n<p><strong>8. Update the do_something function to make it do something useful<\/strong><br \/>\nI&#8217;m using mine to track toilet roll changes. When I get down to two or less I send an email reminder.<br \/>\nI&#8217;m using another Dash button as a &#8220;digital habit tracker&#8221;.<br \/>\nI&#8217;m logging morning Meditation to a habits.txt text file on my Raspberry Pi. I&#8217;ve ordered four more to track other habits.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2245\" src=\"https:\/\/www.nathankowald.com\/blog\/wp-content\/uploads\/2017\/05\/planner.jpg\" alt=\"\" width=\"700\" height=\"465\" \/><br \/>\n<em>Analogue is so trendy.<\/em><\/p>\n<p><strong>Other uses for your Dash button:<\/strong><br \/>\n&#8211; <a href=\"https:\/\/medium.com\/@brody_berson\/hacking-amazon-s-5-dash-button-to-order-domino-s-pizza-9d19c9d04646\">Order pizza<\/a><br \/>\n&#8211; <a href=\"http:\/\/www.notenoughtech.com\/raspberry-pi\/free-wireless-doorbell\/\">Wireless doorbell<\/a><br \/>\n&#8211; <a href=\"https:\/\/github.com\/JamieKnight\/dash-hue\">Control smart lights<\/a><br \/>\n&#8211; <a href=\"https:\/\/github.com\/sanzgiri\/dash-sms\">Send a text<br \/>\n<\/a>&#8211; <a href=\"https:\/\/blog.cloudstitch.com\/how-i-hacked-amazon-s-5-wifi-button-to-track-baby-data-794214b0bdd8\">Track baby data<\/a><br \/>\n&#8211; <a href=\"https:\/\/github.com\/BraedenYoung\/PracticeTracker\">Track practice sessions<\/a><\/p>\n<p><strong>8. Set the Python script to run on startup<\/strong><\/p>\n<p><strong>Edit \/etc\/rc.local<\/strong><\/p>\n<pre class=\"prettyprint lang-sh\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">sudo vim \/etc\/rc.local<\/pre>\n<p>Add the following to the end of \/etc\/rc.local (before exit 0<\/p>\n<pre class=\"prettyprint lang-sh\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\"># Wait for an Internet connection\n# If you connect using an Ethernet cable, change 'wlan0' to 'eth0'\nwhile ! \/sbin\/ifconfig wlan0 | grep -q 'inet addr:[0-9]'; do\n    sleep 3\ndone\n\n# Network connection now exists: run Dash listener\n# Change \/home\/pi\/dashbutton.py to the path you copied the script to\n# Send errors to rclocal.log &lt;-- Useful for debugging sudo \/usr\/bin\/python \/home\/pi\/dashbutton.py 2&gt;&amp;1 \/home\/pi\/rclocal.log &amp;\n\n# Make sure exit 0 is the last line of rclocal\nexit 0<\/pre>\n<p><strong>9. Reboot and test your script<\/strong><\/p>\n<pre class=\"prettyprint lang-sh\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">sudo shutdown -r now<\/pre>\n<p>You should have the dashbutton.py process running in the background, listening for presses.<br \/>\nTo verify your Python script is running type:<\/p>\n<pre class=\"prettyprint lang-sh\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">ps wafux | grep dash<\/pre>\n<p>You should see something like:<\/p>\n<pre class=\"prettyprint lang-sh\" data-start-line=\"1\" data-visibility=\"visible\" data-highlight=\"\" data-caption=\"\">root      2490  0.0  0.6   3756  2296 ?        S    May21   0:00 sudo \/usr\/bin\/python \/home\/pi\/dashbutton.py \/home\/pi\/rclocal.log\nroot      2499  0.0  1.8   8904  6924 ?        S    May21   0:00  \\_ \/usr\/bin\/python \/home\/pi\/dashbutton.py \/home\/pi\/rclocal.log<\/pre>\n<p>This means the Python script is running and listening for your presses.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I set up my Raspberry Pi to listen for Amazon Dash Button presses recently. Raspberry Pis are excellent devices for monitoring Dash button presses because they use very little electricity, so can be left running. I spent some time getting it working so I&#8217;m adding the steps I took here. 1. The easiest way to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[25,14],"tags":[],"class_list":["post-1868","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi","category-useful-information"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts\/1868","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/comments?post=1868"}],"version-history":[{"count":36,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts\/1868\/revisions"}],"predecessor-version":[{"id":2246,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/posts\/1868\/revisions\/2246"}],"wp:attachment":[{"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/media?parent=1868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/categories?post=1868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nathankowald.com\/blog\/wp-json\/wp\/v2\/tags?post=1868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}