Post your best Lua script examples here

User avatar
By Werquinx
#4584 Get notifications on your smartphone with Prowl (http://www.prowlapp.com/) when a button is pressed on GPIO 0 ...

Made an "instructable" and a short video to show how it works :

http://www.instructables.com/id/Portabl ... fications/



Requires a small mod on the ESP-01 module :

Image

Code is very simple :

init.lua

Code: Select allgpio.mode(9,gpio.OUTPUT)
gpio.write(9,gpio.LOW)
wifi.sta.autoconnect(1)
print("Xavier’s ESP8266 LUA module")
tmr.alarm(4000, 0, function() dofile("interupt.lua") end)


interupt.lua

Code: Select allfunction ok(level)
 gpio.mode(8,gpio.OUTPUT)
 gpio.write(9,gpio.LOW)
 conn=net.createConnection(net.TCP, 0) 
 conn:on("receive", function(conn, payload) print(payload) end)
 conn:connect(80,'209.20.89.148') 
 conn:send("GET /publicapi/add?apikey=<your API key>&application=ESP8266&event=Button+pressed&priority=0 HTTP/1.1\r\n")
 conn:send("Host: prowl.weks.net\r\n") 
 conn:send("Accept: */*\r\n")
 conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
 conn:send("\r\n") 
 tmr.delay(500000)
 gpio.write(9,gpio.HIGH)
 gpio.trig(8,"down",ok)
end

gpio.write(9,gpio.HIGH)
gpio.mode(8,gpio.INPUT)
gpio.trig(8,"down",ok)
User avatar
By sigrokBlack
#10340 You can do the same with Notify my android:
http://www.notifymyandroid.com/
Just use an other url:
Code: Select allconn:connect(80,"50.116.34.97")
     conn:send("GET /publicapi/notify?apikey=APIKEY&application=ESP8266&event=START&description=Der%20Schalter%20wurde%20gedrückt\r\n"
          .."Connection: keep-alive\r\nAccept: */*\r\n\r\n")


Greetings
Joshua
User avatar
By MK1888
#10346 Maybe use GPIO.2 for the switch and GPIO.0 for the LED so you don't accidentally throw it into "flash firmware" mode?