3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Amazon Dash Buttonが販売停止になったので、しかたなくIoTボタンをDIYしてみた

Posted at

はじめに

ついにAmazon Dash Buttonが販売停止になりました。ハックしてボタン一押しでいろんなことができる楽しいガジェットでした。
まだ使えますが代替えを用意しないと。とりあえず3ボタン対応のものをDIYしてみました。

パーツ

配線

Fritzing難しくて途中断念しました...^^;
D1 miniと薄膜パネルスイッチを同じ色同士で結線します。

開発環境

こちらを参考にどうぞ。

luaソースコード

ESP8266 IFTTT Easy Buttonコピペして参考に作りました。

SSIDPASSWORDを環境に合わせて変更します。

init.lua
--init.lua
wifi.setmode(wifi.STATION)
wifi.sta.config {ssid="SSID", pwd="PASSWORD"}
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
    if wifi.sta.getip()== nil then
        print("Waiting for IP...")
    else
        tmr.stop(1)
        print("Your IP  is "..wifi.sta.getip())
        print("Your MAC is "..wifi.sta.getmac())
        print("5 seconds to stop timer 0")
        tmr.alarm(0, 5000, 0, function()
            print("Starting button listener...")
            dofile("button.lua")
        end)
    end
end)

いずれかのボタンを押すとWebhookを叩きます。
RED, YELLOW, GREENは環境に合わせて変更します。

button.lua
--button.lua
buttonPin_red    = 5 -- this is ESP8266, index:5, label:D5, pin:GPIO14
buttonPin_yellow = 2 -- this is ESP8266, index:2, label:D2, pin:GPIO4
buttonPin_green  = 1 -- this is ESP8266, index:1, label:D1, pin:GPIO5

gpio.mode(buttonPin_red,   gpio.INT,gpio.PULLUP)
gpio.mode(buttonPin_yellow,gpio.INT,gpio.PULLUP)
gpio.mode(buttonPin_green, gpio.INT,gpio.PULLUP)

function debounce (func)
    local last = 0
    local delay = 200000

    return function (...)
        local now = tmr.now()
        if now - last < delay then return end

        last = now
        return func(...)
    end
end

function onChange()
    webhook_url = "http://192.168.8.1:5000/cmd/"

    if     gpio.read(buttonPin_red) == 0 then
        print("Red! ")
        myHttpGet(webhook_url.."RED")
        tmr.delay(500000)

    elseif gpio.read(buttonPin_yellow) == 0 then
        print("Yellow! ")
        myHttpGet(webhook_url.."YELLOW")
        tmr.delay(500000)

    elseif gpio.read(buttonPin_green) == 0 then
        print("Green! ")
        myHttpGet(webhook_url.."GREEN")
        tmr.delay(500000)
    end
end

function myHttpGet(url)
    http.get(url, nil, function(code, data)
        if (code < 0) then
            print("HTTP request failed")
        else
            print(code, data)
        end
    end)
end

gpio.trig(buttonPin_red,   "down", debounce(onChange))
gpio.trig(buttonPin_yellow,"down", debounce(onChange))
gpio.trig(buttonPin_green, "down", debounce(onChange))

DIYしてみての感想

良かった点

  • USB給電なのでバッテリ切れを気にする必要がなくなった。
  • 無駄な通信をしない分、応答がすごく速くなった。
  • 3ボタンなので、させることを増やせた。

気になる点

  • 手作り感は出るが、スタイリッシュ感が全くなくなった。

ちなみに

なぜ薄膜パネルスイッチを使ったかというと、曲面でも貼り付けて使えるため。これクルマの中で使おうと思っています。

さいごに

Amazon Dash Buttonとは楽しい思い出がたくさんあるので販売停止はとても残念ですが、これも時代の流れでしょうか。(=^・^=)

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?