Advertisement
Guest User

ESP8266 Smartbutton

a guest
Dec 9th, 2015
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.95 KB | None | 0 0
  1. wifi.setmode(wifi.STATION)
  2. wifi.sta.config("ИмяСетиВайФай","ПарольОтВайфай")
  3.  
  4.  
  5. local pin = 4    --> GPIO2
  6.  
  7. function debounce (func)
  8.     local last = 0
  9.     local delay = 400000
  10.  
  11.     return function (...)
  12.         local now = tmr.now()
  13.         if now - last < delay then return end
  14.  
  15.         last = now
  16.         return func(...)
  17.     end
  18. end
  19.  
  20. function onChange ()
  21.     print('The pin value has changed to '..gpio.read(pin))
  22.  
  23.    
  24. conn=net.createConnection(net.TCP, 0)
  25. conn:on("receive", function(conn, payload) print(payload) end)
  26. conn:connect(80,'23.23.215.91')
  27. conn:send("GET /trigger/button_pressed/with/key/ВашКлюч HTTP/1.1\r\n")
  28. conn:send("Host: maker.ifttt.com\r\n")
  29. conn:send("Accept: */*\r\n")
  30. conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
  31. conn:send("\r\n")
  32.  
  33. end
  34.  
  35. gpio.mode(pin, gpio.FLOAT)
  36.  gpio.write(pin, gpio.LOW)
  37. gpio.trig(pin, 'both', debounce(onChange))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement