Experiment with Amazon's Dash Buttons Using Fitlet

Application notes using fitlet. Credit goes to user Hassellbear for publishing more than enough cool application notes to justify a dedicated sub-forum.

Moderator: hassellbear

Post Reply
hassellbear
Posts: 106
Joined: Mon May 28, 2012 12:25 pm

Experiment with Amazon's Dash Buttons Using Fitlet

Post by hassellbear »

Overview
Animated_Dash_Button.gif
Animated_Dash_Button.gif (50.38 KiB) Viewed 19497 times
Amazon offers quite a number of Dash Buttons which are intended to allow you to reorder your favorite products with one press of a button. The idea is to deploy a product's dash button in the area where you use that product. This allows you to simply press the dash button when the product is running low, and that product will magically appear at your doorstep a few days later.

Since Dash Buttons are relatively inexpensive at $4.99 (US) each, they are an attractive target for hacking and re-purposing for other tasks. This application note will show you how to use Dash Buttons in conjunction with your fitlet to do things other than ordering Amazon products.




Principles of Operation

Unlike other available single-button solutions, Dash Buttons are not bluetooth devices. Instead, they are WiFi devices which independently connect to Amazon's servers using a wireless network. They do not need nor do they interact with a local computer while in operation.

Because they are battery powered, Dash Buttons mostly remain in a sleep state in order to conserve energy. When a Dash Button is pressed, it wakes up, connects to its host wireless network, and communicates with Amazon's servers. The establishment of a new network connection upon each button press is what allows Dash Buttons to be re-purposed.

Each time a Dash Button wakes up and establishes a network connection, it announces its presence by issuing an Address Resolution Protocol (ARP) probe. During the ARP process the Dash Button sends it MAC address to the host network. The trick to re-purposing a button is to listen on the network for the button's MAC address and then trigger an action when that address is heard. This application note uses fitlet and some very simple software to do just that. In this case, we will use Dash Buttons to send specific text messages using the TextBelt REST API. Many other tasks other than sending texts are possible - let your imagination take you there!




Hardware

1. Fitlet
2. Assorted Dash Buttons
3. Android or iOS Smart Phone for configuring buttons
Dash_fitlet.JPG
Dash_fitlet.JPG (358.9 KiB) Viewed 19497 times

Configuring a Dash Button

Using an iOS Smart Phone

1. Open Amazon app
2. Open selection screen and select "Your Account"
3. Scroll to "Dash Devices" and select "Set up a new device"
4. Select Dash Button
5. Select "Get Started
6. Input network name and password
7. Press and hold Dash Button until blue LED flashes
8. Place iPhone next to Dash Button and press "Connect"
9. Wait for audio data transfer to complete
10. STOP - DO NOT SELECT A PRODUCT, OR EACH TIME YOU PRESS THE BUTTON YOU WILL PLACE AN ORDER !!
11. Exit the Amazon app - Dash Button configuration is complete

View Image To See iPhone Screens For Steps
iOS Steps.jpeg
iOS Steps.jpeg (1.44 MiB) Viewed 19497 times

hassellbear
Posts: 106
Joined: Mon May 28, 2012 12:25 pm

Experiment with Amazon's Dash Buttons Using Fitlet

Post by hassellbear »

Software

The required packages are:

1. python
2. python-pcapy
3. python-impacket
4. curl (to allow sending of text messages from command line)
5. simple python apps listed below

Python App 1: ethernet.py

#!/usr/bin/python

# Python program "ethernet.py"
# This program lists ethernet hardware on system
# Base code by ujj-novo @ https://gist.github.com/ujj-nuvo
# Code modifications by Darryl E. Hassell

import pcapy
from impacket.ImpactDecoder import *
from impacket.ImpactPacket import *

def get_interface():
devs = pcapy.findalldevs()
i=0
for eth in devs:
print " %d - %s" %(i,devs)
i+=1

if __name__ == "__main__":
dev = get_interface()




Python App 2: mac.py

#!/usr/bin/python

# Python program "mac.py"
# This program captures and lists mac addresses and other data for devices communicating with network
# Base code by ujj-novo @ https://gist.github.com/ujj-nuvo
# Code modifications by Darryl E. Hassell

import pcapy
from impacket.ImpactDecoder import *
from impacket.ImpactPacket import *

def recv_pkts(hdr, data):
packet = EthDecoder().decode(data)
ip_hdr = packet.child()
op_code = ip_hdr.get_ar_op()
src_mac = ip_hdr.as_hrd(ip_hdr.get_ar_sha())
dest_ip = ip_hdr.as_pro(ip_hdr.get_ar_spa())
print "ARP Request from Device: " + str(src_mac)
print "IP Address for Device: " + str(dest_ip)
print "MAC Control Opcode for Device: " + str(op_code)
print " "

if __name__ == "__main__":
max_bytes = 1024 # number of bytes to capture per packet
promiscuous = False # When a data packet is transmitted in non-promiscuous mode, all the LAN devices "listen to" the data to determine if the network address included in the data packet is theirs
read_timeout = 100 # in milliseconds
pc = pcapy.open_live("<Your Ethernet Device Designation>", max_bytes, promiscuous, read_timeout)
packet_limit = -1 # infinite number of packets
pc.setfilter("arp")

try:
pc.loop(packet_limit, recv_pkts) # capture packets
except KeyboardInterrupt:
pass





Python App 3: dashtext.py

#!/usr/bin/python

# Python program "dashtext.py"
# This program listens on network for Dash Button mac addresses and sends text message associated with the detected mac address
# Base code by ujj-novo @ https://gist.github.com/ujj-nuvo
# Code modifications by Darryl E. Hassell

import pcapy
from impacket.ImpactDecoder import *
from impacket.ImpactPacket import *

import os

# callback for received packets
def recv_pkts(hdr, data):
packet = EthDecoder().decode(data)
ip_hdr = packet.child()
op_code = ip_hdr.get_ar_op()
src_mac = ip_hdr.as_hrd(ip_hdr.get_ar_sha())
dest_ip = ip_hdr.as_pro(ip_hdr.get_ar_spa())

if dest_ip == '192.168.1.138' and op_code == 1 and src_mac == "74:c2:46:97:71:b8":
os.system('curl http://textbelt.com/text -d number=<Phone Number> -d message="<Your Message 1 Here>"')
print "<Your Message 1 Here>"
print " "

elif dest_ip == '192.168.1.120' and op_code == 1 and src_mac == "44:65:d:e5:fe:46":
os.system('curl http://textbelt.com/text -d number=<Phone Number> -d message="<Your Message 2 Here>"')
print "<Your Message 2 Here>"
print " "

elif dest_ip == '192.168.1.124' and op_code == 1 and src_mac == "74:75:48:b6:2c:fd":
os.system('curl http://textbelt.com/text -d number=<Phone Number> -d message="<Your Message 3 Here>"')
print "Your Messagge 3 Here>"
print " "

elif dest_ip == '192.168.1.106' and op_code == 1 and src_mac == "74:c2:46:39:70:4e":
os.system('curl http://textbelt.com/text -d number=<Phone Number> -d message="<Your Message 4 Here>"')
print "<Your Message 4 Here>"
print " "

if __name__ == "__main__":
max_bytes = 1024
promiscuous = 0 # every data packet transmitted can be received and read by a network adapter to which its connected
read_timeout = 100 # in milliseconds
pc = pcapy.open_live("<Your Ethernet Device Designation", max_bytes, promiscuous, read_timeout)
packet_limit = -1 # Infinite number of packets
pc.setfilter("arp")

try:
pc.loop(packet_limit, recv_pkts) # capture packets
except KeyboardInterrupt:
pass




Using The Software

1. Run ethernet.py and determine the designation of the system ethernet device you wish to use (Something such as "wlan0", etc.)
ethernet.png
ethernet.png (66.48 KiB) Viewed 19491 times
2. Run mac.py and determine the mac address, mac control opcode, and IP address for Dash Button
mac.png
mac.png (120.56 KiB) Viewed 19491 times
3. Edit dashtext.py and insert the required ethernet device designation. Also insert the mac address, mac control code, IP address, phone number, and message to be sent for each Dash Button you are using.

4. Run dashtext.py and automatically send a text message when a Dash Button is pressed.
dashtext.PNG
dashtext.PNG (72.79 KiB) Viewed 19491 times


Results

1. Although the python code I am using is quite crude and not polished, the results were acceptable and encouraging. The dashtext app reliably send predetermined text messages when a button is pressed.




Conclusions

1. Dash Buttons are an affordable and simple means of implementing single button remote stations used to initiate tasks.

2. Many more Dasj Button implementations are available. Much work has been done by others.

3. Fitlet makes an ideal compact, low power host for a constellation of Dash Buttons.

4. Fitlet again demonstrates its adaptable nature.

Post Reply

Return to “Cool stuff with fitlet”