Things used in this project

Hardware components:
13711 01
SparkFun ESP8266 Thing - Dev Board
×1
Mini Pushbutton Switch
×1
LiPo 200mAh
×1
10k SMD resistor
needed to adjust the charging current - limited to 100mA, replace R4 with this 10K
×1

Custom parts and enclosures

Bottom part of housing
Attention: you do need to cut out a small area by hand if you like to plug in the LiPo connector to the THING ... for guidance check the main picture of the project, you see the LiPo connector close to the USB port
Top part of housing
Mount for push button
This plate will keep the push button on distance and position needed

Code

init.luaLua
replace both <YOURSSID> <YOURWIFIKEY> with your wifi access data, e.g. wifi.sta.config("HOMESSID","1234567890")
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)
ifttt_sw.luaLua
the core function - if GPIO4 connected button was pressed fire an HTTP post ... in this case to IFTTT, replace with your ideas, in case your are using IFTTT app replace <YOUREVENT> <YOURKEY> with your IFTTT credentials, if you don't know how check our other project on IFTTT ...
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 )

Credits

Guido web
fab-lab.eu

Maker!

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Starry Night Prom
Intermediate
  • 2,299
  • 18

How did I stand out at prom? In a light up dress of course!

Third Eye for The Blind
Intermediate
  • 997
  • 13

Full instructions

An innovative wearable technology for visually impaired peoples.

DIY Fidget LED Display
Intermediate
  • 1,564
  • 11

Full instructions

Fidget spinners, the simple spinning toy that came out of nowhere. I thought it'd be cool give it some flare and make it a POV display.

ArduRadio AlarmClock
Intermediate
  • 2,172
  • 2

Full instructions

Build an FM radio with alarm clock.

Scrumtato: Make Daily Stand-Ups Agile Again
Intermediate
  • 802
  • 10

Scrumtato is an ATtiny85-based gadget to keep overly passionate developers from excessively talking during daily stand-up meetings.

Home Automation Using Wiscore and OpenHab
Intermediate
  • 279
  • 2

Protip

This project will help you setup your very own Alexa controlled Home Appliances using the wonderful Wiscore Module from RAK Wireless.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login