Things used in this project

Hardware components:
13711 01
SparkFun 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

Arduino Like Function on Kinetis K82 Freedom Stupid Board
Intermediate
  • 89
  • 4

Protip

1000 of K82 Freedom Boards are collecting dust because of the hobbyist unfriendly IDE, pump up the duds with easy Arduino-like functions.

Reducing Arduino Power Consumption
Intermediate
  • 181
  • 5

Full instructions

One the most important feature of portable electronics should be long battery life. We can reduce the current drawn by several ways.

Arduinomated Car Parking with Voice Assistance in Smartphone
Intermediate
  • 721
  • 12

Full instructions

Make an assistant which tells you about how much to drive backwards without any collision through your smartphone by Arduino and 1Sheeld.

Simple Weather Station with amazing web monitoring
Intermediate
  • 773
  • 6

Full instructions

Do you want see from anywhere what is the temperature, pressure and humidity in your house? If yes this project will show you how to do it.

Sigfox Forest Fire Detector
Intermediate
  • 3,014
  • 17

Full instructions

How to prevent forest from burning? A small Sigfox signal can prevent natural disasters. We will use an Arduino MKRFOX + a flame detector.

Happy Plant Notifier
Intermediate
  • 314
  • 5

Full instructions

Get a text or call if your plant is getting too dry, along with a nice LCD display giving information regarding your plant's health.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog