Post your best Lua script examples here

User avatar
By gerardwr
#3925 I have had a pleasant few hours testing the migrated elua webserver. I REALLY, REALLY like it. It’s much more robust and complete as my own developed webbrowser (in the Examples section). Will probably put my own code to "rest" and continue with this as baseline.

It basically works very smoothly. More specific:
- nice and stable
- .htm pages display fine
- .pht files with single-line lua statements embedded in HTML work fine
- .lua files seems to be executed
- .pht files display fine
- new features is a matter of writing HTML/PHT and uploading. No reboot required! Great for prototyping.

What I would like having improved:
- .html files lead to a PANIC reset, both .htm and .html should be accepted
- multiline Lua code is not working now. It's listed on the elua web as a feature, and is used in the example.pht. Probably a bug.
- larger print output (>256 bytes) of an embedded Lua lines leads to a PANIC reset.
- when .lua page is requested it seesm to be executed, but results are not printed to the serial console, as expected. Returned page to the browser is empy.
- when embedded Lua is faulty in browser is printed :>>> Invalid Lua code <<< 1. Please add the line that was faulty both in the browser and console.- provide some debugging in the serial console, like http request. Now testing more or less a shot in the dark.
- if file exists, but NOT .lua or .htm or .html, display the content in the browser. Great to check log files, if you have any.

The list of improvements seems longer than the „like” list. Don’t let this discourage you, is my enthusiasm on the usability of this code for "real world" web based applications. The combination of HTML and LUA is "golden" for that. The pro’s outweigh the cons easily.

Adamjp has done excellent work here, thanks for that!

For reference my updated index.pht and the browser screen it produces.

Schermafbeelding 2014-12-03 om 15.50.08.png


(1.05 KiB) Downloaded 324 times
User avatar
By adamjp
#3942 Wow good testing, thanks for that.

Something to try:

.html files
Add a new entry to the extmap eg: html = "text/html", pretty much just like adding a mime type to the server.
Log Files
Same as above but txt = "text/plain" or log = "text/plain"

As for the other requests I'll keep hacking away at it, suggestions are always welcome.

On a side note has anyone served images from a esp webserver?
Last edited by adamjp on Wed Dec 03, 2014 3:28 pm, edited 1 time in total.
User avatar
By alonewolfx2
#3944
adamjp wrote:Wow good testing, thanks for that.

Something to try:

.html files
Add a new entry to the extmap eg: html = "text/html", pretty much just like adding a mime type to the server.
Log Files
Sam as above but txt = "text/plain" or log = "text/plain"

As for the other requests I'll keep hacking away at it, suggestions are always welcome.

On a side note has anyone served images from a esp webserver?

images are very big files for esp8266. we have just 150kb for filesystem :oops:
i need to catch requested header for http security. how can catch headers have you any idea?
User avatar
By adamjp
#3945 Cheers, may be the same case for large lua files and large in line multiline lua scripts, as for the headers I believe that this:

string.find(request, "Referer: ([^\r\n]+)");

Replacing Referer with the header key of your choice would work.

Found in this library: http://www.steve.org.uk/Software/lua/lua-httpd/, I believe that this library is a little big for our modules but haven't investigated fully.