Amazon-Dash-Button

 view release on metacpan or  search on metacpan

lib/Amazon/Dash/Button.pm  view on Meta::CPAN

package Amazon::Dash::Button;
$Amazon::Dash::Button::VERSION = '0.11';
$Amazon::Dash::Button = '0.10';

use Amazon::Dash::Button::Device ();
use Net::Pcap::Easy              ();

use strict;
use warnings;

# ABSTRACT: a very simple perl interface to play & interact with an Amazon Dash Button.

=head1 NAME
Amazon::Dash::Button - a very simple perl interface to play & interact with an Amazon Dash Button.

=head1 VERSION

version 0.11

=head1 DESCRIPTION

Amazon::Dash::Button allows you to discover your mac address button and
set a listener to run any custom actions when the button is clicked...

Here is a non exhaustive list of ideas, applications you can think about:

=over 4

=item control your music player (provide an example for mpd: Music Player Daemon)

=item silent doorbell which send a notification (text, email, ...)

=item order your favorite pizza

=item switch on/off the light

=item open the garage door

=item ...

=back

Feel free to complete this list, and submit more ideas.

This can be used on a Raspberry Pi, linux, mac os computer...
In order to properly listen to packets you would need to run it as root using 'sudo' 

=head1 Setting

=head2 Linking the button to your wifi network

The first thing to do once you have received your button is to set it and discover it.
Here is the basic setting process:

=over 4

=item use your phone or table to perform the basic setting, but do not complete it, stop when asking to select to link a product with the button.

=item  in the mobile app you would find a menu "Your Dash Button" -> "Settings" then "Set up a new device".

=item  choose your dash device, then follow the instructions: long press on the button until it discovery mode (blue light)

=item  provide the wifi password of your network

=item  but do not select the exact product linked to your button exit from there !

=back

=head2 Detecting the button

Amazon::Dash::Button comes with one search method which allows you to look for your device.
You mainly want to know the mac address of your button

=head3 * from the command line

You can use the sample scripts provided in the distribution to detect your button.
The button should be listed as one of the Amazon device, as shown in the sample below:

		> sudo ./examples/search.pl
		> sudo ./examples/search.pl eth0
		Password:
		# using filter: arp or ( udp and ( port 67 or port 68 ) )
		# listening on device: en0
		# using cache Yes
		ARP - Mac Address = c8:b1:ce:bb:a3:1c
		ARP - Mac Address = 36:07:8d:ab:61:b7
		ARP - Mac Address = a6:5e:88:28:d2:9f
		ARP - Mac Address = e9:97:12:9e:38:56
		ARP - Mac Address = 68:54:b5:41:69:9c - Amazon device

=head3 * oneliner

Or simply opt for one of the oneliner below to search for your buttong

		perl -MAmazon::Dash::Button -e 'Amazon::Dash::Button->search()'

you can also provide your own filter to look for your button.
By default it's using udp and arp lookup which should cover most of the buttons.
Depending on your button generation and software version it might use one or the other.

You will find several options to use with the search function there, in order to run it 
as a oneliner, simple replace 'YOUR RULE HERE' with the rule you want to use.

		perl -MAmazon::Dash::Button -e 'YOUR RULE HERE'

		# this is the default rule
		Amazon::Dash::Button->search( filter => q{arp or ( udp and ( port 67 or port 68 ) )} );

		# only look on udp
		Amazon::Dash::Button->search( filter => q{'udp and ( port 67 or port 68 )} );

		# remove more noise using cache (by default disabled), one mac address is only displayed once
		Amazon::Dash::Button->search( cache => 1 );

You can also specifiy the network device to use to listen depending 
if it's a wifi or cable ethernet connection use one or the other.

		# search on a specific device
		Amazon::Dash::Button->search( dev => q{en0} );
		Amazon::Dash::Button->search( dev => q{eth0} );

=head1 Usage

=head2 Manage a single button



( run in 1.541 second using v1.01-cache-2.11-cpan-39bf76dae61 )