Things used in this project
Amazon(TM) announced a while back a "Dashbutton" - a thing that you can be placed, pressed, followed by a send notification via HTTP to order automated supplies needed ... https://www.amazon.com/oc/dash-button
That sounds like an closed shop system just to order supplies needed from one single vendor - but we can build an WiFi enabled button based on the #ESP8266 just for a couple of bucks while having also access to GPIOs and an open platform to do what ever you want with a button in the brave new #IoT world. Beyond it will support the #IFTTT application and its Maker Channel but also any LAMP based DIY backend.
There are tons of daily interactions where you simply would like to press a button:
- coffee is fresh
- bread is fresh from the bakery
- call me
- switch things on / off
- lunch is ready
- vote for anything
- add yours
There are some of these button already out in the market but we make it cheaper and open to add your ideas ...
Let's go .... and build one! Yours ...
We do need a housing for the EPS8266 Thing - but not just a housing, we want to have an integrated button, which is water resistant and is flat in design too. Here you go - the STL can be downloaded from this webpage, printed on any 3D printer and mounted with little glue later on. Mount the distance shield just by pressing it firmly into position and use little glue to fix the micro switch in the center. This will position the micro switch just behind the surface of the case in perfect distance. So if you press with your thumb onto the surface you will trigger the switch.
So the cool thing about this is - you don't see a physical button or switch from the outside, just push the case and it will trigger the button hidden inside the case - it's magic ;-)
Flash the LUA files on the #Dashbutton like ESP8266 Thing!
Using nodeMCU firmware an python based toolchain it looks like this (don't forget the 3.3V FTDI):
$ python /home/pi/esp/luatool-master/luatool/luatool.py --port /dev/ttyUSB0 --src init.lua --dest init.lua --verbose
$ python /home/pi/esp/luatool-master/luatool/luatool.py --port /dev/ttyUSB0 --src init.lua --dest ifttt_sw.lua --verbose
Restart your ESP8266 Thing and your are up and running!
Press carefully on to the surface the button is hidden off and wait for your IFTTT message, if you don't get a message check first if while you press the "button" a green light inside is confirming input on GPIO4. You might need to press for max. 5 secs.
Have fun with your new button - stick it where you want ... ;-) put a comment if you have a great idea to share ...
Putting all together and earlier tests:
Custom parts and enclosures
print('init.lua ver 1.2') wifi.setmode(wifi.STATION) print('set mode=STATION (mode='..wifi.getmode()..')') print('MAC: ',wifi.sta.getmac()) print('chip: ',node.chipid()) print('heap: ',node.heap()) -- wifi config start wifi.sta.config("<YOURSSID>","<YOURWIFIKEY>") -- wifi config end wifi.sta.connect() tmr.alarm(1, 1000, 1, function() if wifi.sta.getip()== nil then print("IP unavaiable, Waiting...") else tmr.stop(1) print("ESP8266 mode is: " .. wifi.getmode()) print("The module MAC address is: " .. wifi.ap.getmac()) print("Config done, IP is "..wifi.sta.getip()) print("*** You've got 5 sec to stop timer 0 ***") -- this wait trick before starting application makes re-flashing easier tmr.alarm(0, 5000, 0, function() print("Executing lua") dofile("ifttt_sw.lua") end) end end)
port = 80 gpio.mode(1, gpio.OUTPUT) gpio.mode(2, gpio.INPUT) gpio.write(1, gpio.HIGH) tmr.delay(500000) -- wait 1,000,000 us = 1 second gpio.write(1, gpio.LOW) tmr.delay(500000) -- wait 1,000,000 us = 1 second gpio.write(1, gpio.HIGH) tmr.delay(500000) -- wait 1,000,000 us = 1 second gpio.write(1, gpio.LOW) tmr.delay(500000) -- wait 1,000,000 us = 1 second function sendData() -- dummy value not used in this sample t1 = 0 -- GPIO4 is the switch connected with pull-up resistor local pinValue = gpio.read(2) if pinValue == gpio.LOW then print 'GPIO4 is low' else print 'GPIO4 is high' end -- conection to IFTTT channel -- don't change this code section, needed to allow LUA to resolve the hostname -- without it just ran work with IP addresses print("Sending data to IFTTT channel") conn=net.createConnection(net.TCP, 0) conn:on("receive", function(conn, payload) print(payload) end) conn:connect(80,'maker.ifttt.com') conn:on("connection", function(conn, payload) if pinValue == gpio.HIGH then print("Connected, sending event") conn:send("GET /trigger/<YOUREVENT>/with/key/<YOURKEY>?value1="..t1.." HTTP/1.1\r\n") conn:send("Host: maker.ifttt.com\r\n") conn:send("Accept: */*\r\n") conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.)\r\n") conn:send("\r\n") gpio.write(1, gpio.HIGH) tmr.alarm(1, 1000, 0, function() -- time index 1 gpio.write(1, gpio.LOW) end) end end) conn:on("sent",function(conn) print("Closing connection") conn:close() end) conn:on("disconnection", function(conn) print("Got disconnection...") end) end -- send data every X ms to thing speak --- checks every 5000 sec for a press of button tmr.alarm(0, 5000, 1, function() sendData() end )
Did you replicate this project? Share it!I made one
Love this project? Think it could be improved? Tell us what you think!