Amazon Dash Button has been released and various people are hacking it, but the weak point of this device is that it is a simple UI that pushes a button, so I do not know the amount ...
Amazon prices change frequently, so you want to buy as cheaply as possible, right? So I physically hacked the Amazon Dash Button and created a device that will automatically purchase when the price drops to the specified amount.
name | parts | price |
---|---|---|
Amazon Dash Button | ¥500 | |
Raspberry Pi 3 | ¥4,800 | |
Micro Servo SG92G | ¥500 | |
Arduino Uno | ¥3,240 |
For the time being, the servo motor and Amazon Dash Button are fixed with a cable tie.
I didn't have enough parts to connect to GPIO of Raspberry Pi, so it's a little troublesome, but I decided to operate the servo motor via Arduino. Arduino is not necessary if you are prepared properly.
When ʻA` is received by serial communication, the servo motor is moved a little and the Amazon Dash Button is pressed.
#include <Servo.h>
const int pin = 8;
Servo myservo;
void setup() {
myservo.attach(pin);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
byte res = Serial.read();
if (res == 'A') {
myservo.write(20);
delay(500);
}
} else {
int val = myservo.read();
if (val != 0) {
myservo.write(0);
}
}
}
When I actually send ʻA` from the serial monitor of Arduino IDE The servo motor works like this
This is the procedure to connect the Raspberry Pi and Arduino with a USB cable and operate the servo motor via serial communication.
First, install the necessary libraries on the Raspberry Pi side.
$ sudo apt-get install python-pip
$ sudo pip install pyserial
dmesg
Connect the Raspberry Pi and Arduino with a USB cable and check the connection.
When you type the command, it will be displayed as straw, but you can see that it is connected with the device name ttyACM0
around where ʻArduino` is displayed.
$ dmesg
[ 3401.469507] usb 1-1.5: new full-speed USB device number 4 using dwc_otg
[ 3401.583400] usb 1-1.5: New USB device found, idVendor=2341, idProduct=0043
[ 3401.583420] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=220
[ 3401.583433] usb 1-1.5: Manufacturer: Arduino (www.arduino.cc)
[ 3401.583446] usb 1-1.5: SerialNumber: 554313134383513061F0
[ 3401.601770] cdc_acm 1-1.5:1.0: ttyACM0: USB ACM device
For serial.Serial
, set the device name obtained earlier and the value specified in Arduino.
dashpush.py
import serial
import time
ser = serial.Serial('/dev/ttyACM0', 9600)
time.sleep(3)
ser.write(b'A')
ser.close()
Try to move
$ sudo python dashpush.py
If the servo motor works with everything connected, you're ready to go.
Use Amazon Product Advertising API to get the price of the product and If it is cheaper than the set amount, we will make it so that you can purchase it by pressing the button.
Get the ASIN of the product set in the Amazon Dash Button. Copy it because it is in the product information on the page
This Suntory Tennensui
In the case of, it becomes B0043TXMWM
.
Install bottlenose and BeautifulSoup with pip
$ sudo pip install bottlenose
$ sudo pip install BeautifulSoup
Parse the XML of Amazon product information obtained with bottlenose
with Beautiful Soup
If the price of water is less than 1200 yen, I will throw the serial communication and buy it.
dashpush.py
import serial
import time
from bottlenose import api
from BeautifulSoup import BeautifulStoneSoup
AMAZON_ACCESS_KEY_ID = "xxxxxxxxxx"
AMAZON_SECRET_KEY = "xxxxxxxxxx"
AMAZON_ASSOC_TAG = "corelar-22"
ASIN = "B0043TXMWM"
PURCHASE_PRICE = 1200
# get api
amazon = api.Amazon(AMAZON_ACCESS_KEY_ID, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG, Region="JP")
res = amazon.ItemLookup(ItemId=ASIN, ResponseGroup="Offers")
# xml parse
soup = BeautifulStoneSoup(res)
price = soup.find("item").find("offer").find("price").find("amount").text
# push button
if int(price) < PURCHASE_PRICE:
ser = serial.Serial('/dev/ttyACM0', 9600)
time.sleep(3)
ser.write(b'A')
ser.close()
I was able to purchase it.
At this rate, we will always buy infinitely regardless of the stock status. Allows you to change the threshold for the amount of products purchased from your smartphone.
For example --Be sure to purchase (set to 10,000 yen) --Purchase if less than 1200 yen (set to 1200 yen) --Do not purchase (set to 0 yen)
If you create an API on AWS Lambda, update this amount from the iOS app, and make it readable from the Raspberry Pi, you will not have to worry about continuous purchases.
When the button is pressed, just return to 0 yen specification from Raspberry Pi
.
Track the price of each item and buy it when it's the cheapest in the last month! You can also do something like **
This time I checked once every 30 minutes.
$ crontab -e
In the case of raspbian, the editor selection screen is displayed at the first startup,
If you press enter properly without reading, nano
is selected and it is about to get stuck
You can reselect with vim by hitting the select-editor
command
crontab
*/30 * * * * sudo python dashpush.py > /dev/null 2>&1
The rest is left ...
Advent Calendar was just in time ... Until now, there was no purchase API, but I'm happy that I can finally purchase it.
It was an application before Tweaking Pokemon GO Plus, but it became a completely neglected device.
Amazon has been focusing on AWS Greengrass and AWS IoT Button. I have Finally, the Raspberry Pi Zero will be sold in Japan next year, I want Japan to come to the official version as soon as possible.
Recommended Posts