Post your best Lua script examples here

User avatar
By kieranc
#34176 DuckDNS.org allow you to update your IP by requesting "https://duckdns.org/update/exampledomain/yourtoken", it also works via HTTP so I've used this to create a simple updater for the ESP8266. Hope someone else finds it useful.

Code: Select alldr=net.createConnection(net.TCP, 0)
dr:dns("www.duckdns.org",function(conn,ip)
myip=ip
end)
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end)
conn:connect(80,myip)
conn:send("GET /update/your-domain-here/your-token-goes-here HTTP/1.1\r\n")
conn:send("Host: www.duckdns.org\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")


Since conn:connect only seem to work with an IP address, the first part resolves the IP for duckdns.org, then creates the http request.
The IP address for the update is determined automatically by DuckDNS, you can also specify it manually as a 3rd argument to the http request if you like.
User avatar
By Varcon
#59607 This is exactly what i am lookin for, but in Arduino IDE.
Can somebody help me? I have ESP in Station mode connected to my wifi network, now i just need to update my DuckDDNS, how to do this in Arduino IDE?
User avatar
By josmaroal
#84045 Hola amigo, me interesa mucho tu aporte por favor podrias darme indicaciones como instalarlo en mi programa, estoy trabajando en ESP-12 con ESPBasic, pero si tengo que aprender el lenguaje que usas, ayudame.
Saludos y gracias .
Jose