As the title says... Chat on...

User avatar
By moeen
#38288 Hello all
I have a problem about nodemcu board
I wrote a script and executed on board but when I turn off the board and again turn it on the program has been deleted
what can I do? I don't want use avr to send commands or eeprom external memory
Thanks
User avatar
By TerryE
#38377 You write your script to a file, then execute it from your init.lua. It's worth adding a small delay before executing it, just in case you've an error in your script which causes a restart, because this would create a reboot loop. For example your init.Lua might be
Code: Select alltmr.alarm(1,2000,0, function() dofile "myapp.Lua" end)
User avatar
By Eyal
#38381 A bit OT but I do not like delays so my programs always have something like this:
Code: Select alllocal function init()
    local pin = 1   -- GPIO5, whatever
    gpio.mode (pin, gpio.INPUT, gpio.PULLUP)
    if 0 == gpio.read (pin) then dofile ("myapp.lua") end
end
init()

Now, when in trouble, ground this "magic pin" to stop the restart loop. Alternatively, one can hide init.lua on button press:
Code: Select alllocal pin = 1   -- GPIO5, whatever
gpio.mode (pin, gpio.INPUT, gpio.PULLUP)
if gpio.read (pin) > 0 then file.rename ("init.lua", "i.lua") end

-- rest of init.lua or dofile ("myapp.Lua")
User avatar
By moeen
#38393 No I didn't mean this I mean that how can I save my script. Into nodemcu memory for all the time like programming avr,of course I don't want to use any microcontrollers to send commands to node mcu I want to use it's memory. is it possible?
Did I explain clearly?