Post your best Lua script examples here

User avatar
By manawyrm
#6540 Hello,

being slightly annoyed by the quite slow and error-prone way of downloading files and code to the ESP using the serial port, I've written a quicker and easier way to load code onto the ESP modules.
The library basically consists of two files, http.lua and httpDL.lua.

httpDL.lua allows you to download files to the internal filesystem of the module,
http.lua allows you to get the returned data from a HTTP-get-Request as a string. Also it has the ability to send an array of key->value data to the server.

I have included some sample code on my GitHub Repository:
https://github.com/Manawyrm/ESP8266-HTTP

For downloading code to the ESP module I have written a small function which I put into my init.lua:

Code: Select allfunction download(filename)
  tmr.wdclr()
  httpDL = require("httpDL")
  collectgarbage()
  httpDL.download("10.4.0.5", 80, "/api/esp8266/lichtTreppe/"..filename, filename, function (payload)
    print("OK.")
  end)
  httpDL = nil
  package.loaded["httpDL"]=nil
  collectgarbage()
end


It basically allows you to download a file with a specified name by just calling download("filename.lua") in the console.

Please test the lib and let me know how it works for you.

So long,
Tobias
User avatar
By alonewolfx2
#6542 Thank you for your example. it's working well for me. I wonder one thing. can we download jpeg or different file type?
Edit: It's not working bigger than 1226 Byte.
User avatar
By ChrixXenon
#6700 May I ask a slightly off-topic question? How do you know about httpDL etc.?

There is no mention of it in the NodeMCU stuff at https://github.com/nodemcu/nodemcu-firm ... mcu_api_en, and the only relevant result from a web search for "lua httpDL" is this post.

Thanks, Chris
User avatar
By gry79
#6851 A few days ago I thought: Would be cool to download LUA files from a webserver and here it is :)
Thank you very much for the nice work.

I did some small tests and it works pretty good.

Just a little suggestion:
I just added a
Code: Select allfile.remove(path);
just before
Code: Select allfile.open(path, "w+")
in your httpDL.lua for my needs.
I think it's good practice to delete the file first before downloading.

Maybe you want to add that in you library.

Thanks again and keep up the good work.