After suddenly realising I could make a whole complicated APP based on a single Lua timer (even though today’s Lua update which I’m using can handle 7 timers), I realised that the only thing that stopped it being practical was the lack of non-volatile variables in the current LUA interpreter for ESP8266.
My first thoughts were…. create a global variable file (which would be small), read it during INIT then when something needs saving – write to another file making updates and then when confirmed done, delete the original and rename the new file.. NO, SORRY – no rename facility in this Lua.
But as you’ll see that’s only part of it. Then I thought – ok I REALLY don’t want to use up RAM but I will – so we’ll read the file into an array (or two arrays in this case as I didn’t want to get TOO clever) – (hope the power does not go off and delete the original) – write the array to a new copy of the globals file and BOBS YOUR UNCLE.
But NO, after having SO much success with my little APP – TWO of us with completely different setups have FAILED to get this to work – I can’t even get past line TWO!!
The idea to call the file “globals.lua” is mine – and if we ever get past this point I’ll detail fully WHY this is needed and how my app can form the basis of your next App!!! But for now…
while x~=nil do
if items[counter]==newitem then values[counter]=newvalue .. “\n” end
while items[counter]~=nil do
file.writeline(items[counter] .. “=” .. values[counter])
Clearly – the result should be 3 lines showing 1, AHAH!!!!! and 3. So the second line has been updated.
But I’ll bet you can’t get that far.
WHY??? – my friend’s system bombs half way through – while I’m running a simple temperature sensor and TCP/IP link in the background with no less than 13k of RAM available, I can’t get past line two!!!!!