Site icon 14core.com

Running the ESP8266 LUA Script Automatically

In this guide we will going to run the LUA script automatically after flashing the ESP8266. When the ESP8266 boots. It runs the init.lua file, it will create a file called init.lua which runs the file with the instructions, also a good place to initialize any code variable you are using such as SSID of the access point. While debugging it is good to use a timer to call the script after a few seconds, if you make mistake it will cause a crash, you will have a few seconds to stop the timer with the tmr.stop button before the script starts running again.

For this example only one line will do this job.
tmr.alarm(0,10000,0,function() dofile(‘httpget.lua’)end) // Alarm timer number 0 to execute the function: dofile(‘httpget.lua’) in 10 seconds.

Note: if you wanted the script to execute automatically when the ESP8266 starts, named it to init.lua, however the danger to doing this kind of procedure if there is a bug in the script that locks the ESP8266 start then you cannot remove and modify the script. If this happen the only way to access is to reflash the ESP8266 using NodeMCU, or ESP Flash Tool.

I recommend that you need to name your script for a test to successful initialization. Youscript.lua test it remove all possible bugs then after you done the test, you can call it to init.lua by putting dofile(‘myscript.lua’) in init.lua file.

Running the ESP8266 LUA Script Automatically
Exit mobile version