We use Amazon Dash Button for our own purposes



    You have probably already seen this promotional video about buttons for ordering goods with amazon, and you probably also wanted to automate something.

    Under the cat, the case of using amazon dash button in Russian realities and its implementation on nodejs.

    Introduction
    While reading articles about IoT at New Year's holidays, my hands were combed out to automate something and the amazon-ordered button just arrived, after playing with it, I began to think about how to use it with at least some benefit.
    I remembered that we in Flexby often forget to pre-order water for the cooler. It seems you see - it ends, but while you drink tea / coffee you already forget. Accordingly, the order was sent only when there was no water at all.
    Now it’s enough to click on the “Buy Water” button and the notification in slack will help you not to forget about it, but we went a little further and wrote a script that immediately places an order on the website of a local water delivery company.
    No, the order is not sent after each click
    So that the order is not re-sent when the next supervisory counterpart presses the button, they simply sent it no more than once every five days. The likelihood that the water will end faster than a week tends to zero.


    How it works?
    0. The button is "tied" to the wi-fi on the instructions but determined not to end, do not indicate the goods to the order on amazon was not created.

    1. When you click on the button:
    1.1 it connects to the wi-fi network to send a request to amazon.
    1.2 The order is not formed because The process of setting the button’s behavior has not been completed.

    2. The script, on a local server connected to the same wi-fi network, monitors the appearance of the mac address of the button and concludes that it was pressed.
    2.1 The actions you need are performed.
    in our case, this is sending an order for water for the cooler and notifying about it in slack

    Now about everything in order.

    Where to get the buttons?
    It is worth mentioning that there arehere is such a version for developers about using it, they wrote on geektimes with it, of course, it’s much easier and more beautiful to integrate everything you want, but where to get these iot-buttons remains a mystery to me.

    Buttons for ordering certain goods with amazon can be purchased for $ 5 (currently only customers with prime status can buy them).

    This button came to me at the New Year holidays. I took only one for testing, now I'm going to order 10 more.

    One more photo






    “Amazon Elements” is roughly a swipe :)
    The device connects to a wi-fi network, every time you click.
    The manufacturer writes that it is designed for ~ 1000 clicks. Most likely, this limitation is associated with the battery, which, if desired, can be replaced independently, there is just a battery inside .

    Let's get started


    About how "crack" these buttons can be read here here and here .
    Briefly - the whole hack in tracking the mac-address of a button in a wi-fi network using ARP sniffer.

    You can also force the router to forward requests to parker-gateway-na.amazon.com to your server.

    Binding a button to a wifi network
    In the amazon application, go to account settings- > device management and add a new button.

    At the stage of product selection, close the setup wizard . It is worth disabling notifications in order not to receive messages about failed orders.
    Screenshots of the button setup process



    "Server" for a button on NodeJs
    There is an easy-to-use module .
    Key points:
    • It works under linux, possibly on poppies (not tested).
    • It requires libpcap-dev to work.
    • The script must be run with superuser privileges.
    • And of course, on a machine connected to the same wi-fi network as the button .


    npm install node-dash-button
    

    If you have difficulty installing, try updating npm and node-gyp
    sudo npm install -g npm
    sudo npm install -g node-gyp
    

    You can find out the mac address of the button by running the following script:
    sudo node node_modules/node-dash-button/bin/findbutton 
    

    Well, or just in the admin panel of the router, determine the exception method.

    Here in a simple way catch button clicks:
    sniffer = require('node-dash-button');
    // mac-адреса и действия для кнопочек
    buttons = {
    	'8f:3f:20:33:54:44':{
    		action: function(){
    			console.log('Press button 1')
    		}
    	},
    	'2e:3f:20:33:54:22': {
    		action: function(){
    			console.log('Press button 2')
    		}
    	}
    	// ...
    };
    // Запускаем сниффер
    // Object.keys(buttons) - массив mac-адресов наших кнопок
    sniffer( Object.keys(buttons) ).on("detected", function (catched_mac){
    	console.log('Пойман mac-адрес: '+catched_mac+'\n');
    	// Вызываем событие этой кнопки
    	buttons[catched_mac].action(); 
    });
    

    Those. we say what mac addresses we need when they light up - we call the function we need.

    As an example, you can still see the sources of our script for ordering water .

    UPD : A couple of ideas for use.
    All the same, the main case, as shown in the commercial, is a reminder to yourself about the need to replenish the reserves of some resource.

    In the office :
    • The “Buy paper” button, next to the printer or the place where printing paper is stored, sends an email to the person in charge or immediately orders.
    • “Cookies run out” - email to the one who should replenish them.


    At home :
    • “Buy toilet paper”, sending reminders to yourself, email / task on wunderlist.
      Perhaps this is the only critical resource :) The rest, by analogy, is easy to think out depending on your needs, it can be diapers, toothpaste, tablets for a dishwasher, washing powder, etc.

    By the way, I did not find any applications for the shopping list with the API.

    Bit non-standard options :
    • Door bell.
      So that for example a call does not disturb the child’s sleep, let him just quietly send a notification to the phone. At other times, such a call can include any melody, again it will be possible to adjust the volume.
    • Counter of something. The button can be worn as a keychain, and if you count something you need in the coverage area of ​​your wifi network, it is perfect for this.
      For example, from 7:00 to 9:00, we count the number of associates who came earlier. From 9:00 to 13:00 late. From 13:00 to 15:00 detained at dinner, from 15:00 to 18:00 left early, from 18: 00-21: 00 detained at work. Interesting statistics can come out.
      Or you can consider the number of oral appeals for help to the IT department.


    I would be glad to share your ideas on using these buttons in the comments.

    Also popular now: