Chat freely about anything...

User avatar
By faramon
#64643 Hi,

I read that is better for develop NodeMcu to have test.lua script at first and when all is done then put init.lua with content as test has. I read about this that when init.lua is uploaded then nothing can be changed. Or can, but this became so hard to change. Why? My test.lua has include config.lua and application.lua.
Is this realy problem? If I upload init.lua, can I modify and upload this other scripts easy or is problem as I read?

This works, I have wifi connection in setup.lua and parameters for application in config.lua. In application.lua is code for reading MQTT topic and set on or off my connected LED.

This is my test that has to be replaced with init:
Code: Select all-- ESP8266

print("ESP8266 module start")

app = require("application")
config = require("config")
setup = require("setup")

setup.start() 


Thanx, I'am new here.
Faramon
User avatar
By daniel_ezsbc
#64721 If init.lua crashes badly then it may be difficult to regain control over the module. You can always get back control by re-programming the module. If you put your untrusted code in a different file you have to invoke it manually and if it crashes badly all you need to do is to press the Reset button and upload a revised version. It is quicker than flashing Lua again.
User avatar
By faramon
#64830 Hi, thanx for the answer.

I found some tutorials that say if put the code with timer in init that you have enough time to delete init or rename it with Snipped buttons in ESPlorer like this what I have put into test-lua that replace init.lua for now:

print("ESP8266 module start, please wait...")
--
app = require("application")
config = require("config")
setup = require("setup")
--
function startup()
setup.start()
end
--
tmr.alarm(0,9000,0,startup)

Now I have 9 seconds to hit the button to rename init.lua to old one and upload it again.
Faramon
Last edited by faramon on Tue Apr 25, 2017 6:32 am, edited 1 time in total.
User avatar
By faramon
#64831 Then in snippet1 I put the code:

file.remove('init.old')
file.rename('init.lua', 'init.old')

and this will work, I suppose