Post your best Lua script examples here

User avatar
By Mikael Rasmussen
#29467 Hi,

To allow output from scripts to be printed to the 'run' page I added a redirect of outout so that it writes to the page.

if vars=="run" then
conn:send("<verbatim>")
function s_output(str)
if(conn~=nil)
then conn:send(str)
end
end
node.output(s_output, 0) -- re-direct output to function s_ouput.


local st, result=pcall(dofile, url)

node.output(nil)

conn:send(tostring(result))
User avatar
By Luc Volders
#30206 Hi I just tried to upload it to my ESP8266-01 but there seem to be some problems.

First I had to delete the first lines which contain the [] tokens at the beginning of the program.

Next it gave a compile error:

stdin:1: '=' expected near '<'w([[ end ]]);

And that occured at the line where it says:
conn:send("<button onclick=\"tag('Saving');x.open('POST',location.pathname,true);\nx.onreadystatechange=function(){if(x.readyState==4) tag(x.responseText);};\nx.send(new Blob([document.getElementsByName('t')[0].value],{type:'text/plain'}));\">Save</button><a href='?run'>run</a><w></w>")

Anyone expieriencing the same problem.

As a result it also said:
> dofile("webedit.lua");
not enough memory

Any toughts ???

Update at October 4

Uploaded with Lualoder as described in previous post.
Program now works however the error code keeps appearing.
In the same line as above described.
Result:

The Save button is missing. So I am not able to save changes or new programs........

Luc
User avatar
By ardhuru
#48374 Hello!

The mini Web IDE works beautifully for its intended purpose. But, I thought of adding an LED blinker to indicate that the ESP is in the Web IDE mode.

Code: Select allfunction blink()
  gpio.write(3, gpio.HIGH)
  tmr.delay(20000)          -- wait 20,000 us = .02 second
  gpio.write(3, gpio.LOW)
end
tmr.alarm(2,300,1,blink)    -- Use timer2, every 300ms second


This works fine too. BUT, if I change the gpio to 4 (the actual pin on my ESP I'd like to put the LED on), it does not work.

The above routine works for both gpios if run by itself.

I dont see gpio 4 being used for anything else in the Web Ide, so I'm wondering where the problem is?

Any pointers would be highly appreciated, guys!

Regards.