Uploading a .lua file to the esp (nodemcu)

A project log for Fiddling with the esp8266

A place to scribble down my notes when playing with the esp8266 wifi chip. Might be helpfull to others as well...

AndroidersAndroiders 02/25/2015 at 12:100 Comments

nodemcu is a great firmware, but i need to add programs to it. And I want to make these programs locally and upload them. Lets do that.

First i wrote a simple program (or actually, someone else wrote the program. I stole it and put it in a file on my computer).

This is the program

   if string.find(payload,"?myarg=") then
    m="<br/>Value= " .. string.sub(payload,string.find(payload,"?myarg=")+7,string.find(payload,"HTTP")-2)
 conn:send("<h1> Hello, this is Androiders's web page.</h1>How are you today.<br/> Count=" .. mycounter .. m .. "Heap="
.. node.heap()) 
conn:on("sent",function(conn) conn:close() end) 
I saved it to a file called main.lua

Then i downloaded luatool from here

Luatool is a tool to put files on the esp where nodemcu can find them and execute them.

The script takes a file (defaults to main.lua) and uploads it and stores it with the same name. So simply executeing ./luatool puts a file named main.lua (in the same dir) on the esp.

After it was done i connected to the serial port again and exectuted node.restart().

Then, the magic comman, dofile("main.lua") executes the file.

Since the program was a small webserver it was easy to verify. First i got the ip adress from the esp using print(wifi.sta.getip()), then i entered that ip in the browser. Voila!

The restart and dofile commands can be set as arguments to the luatool. I will check it out later.