Post your best Lua script examples here

User avatar
By andmpo
#9968 You can declare a global variable and use it like:
<?lua print(variable) ?>

Also you may want to call a external script:

<?lua dofile("script.lua") ?>

The variable declared inside the script will be avaible.
User avatar
By p_r
#10890 I made some modifications to the script to support NodeMCU 0.9.5 build 20150213.

New Features:
  • Multiline lua code support (with start-tag "<?lua" and end-tag "?>")
  • Url Parameter (url parameter are in a lua table "get". For example: get["gpio"])

I added some easy examples to the zip.

I have problems with random hard resets when the script is running.
Can anybody confirm that? (maybe there is a problem with my ESP8266 or power supply)
Attachments
httpd.lua ... modified lhttpd.lua script
httpd_min.lua ... minified script
*.html ... examples

(2.6 KiB) Downloaded 360 times
User avatar
By andmpo
#10979
p_r wrote:I made some modifications to the script to support NodeMCU 0.9.5 build 20150213.

New Features:
  • Multiline lua code support (with start-tag "<?lua" and end-tag "?>")
  • Url Parameter (url parameter are in a lua table "get". For example: get["gpio"])

I added some easy examples to the zip.

I have problems with random hard resets when the script is running.
Can anybody confirm that? (maybe there is a problem with my ESP8266 or power supply)


Working fine for me with latest firmware version, no random restarts so far.
Found two problems:
    Anything on the same line before and after <?lua ?> is not sent to the response
    If any query string is sent empty there is an error and a restart

Added code to github with a example form, where you can simulate both erros: https://github.com/andrempo/lhttpd