Left for archival purposes.

User avatar
By scargill
#4434 I think I've just spotted a BIT problem with files...

I realised today that in order to remember the state of anything in Lua on the ESP8266, you need to have as part of your start up, a "globals.lua" file for want of a better title . A short file in which globals are initialised. That way by changing that file programmatically you end up with non-volatile data. But you don't want to be messing with the original file in case of corruption..

So a simple way to handle this would be to read the file line by line into a temporary file and if a line matched a query, write in the new value instead of the old.

When all done, close both files, delete the original and rename the new. Job done.

Only two big problems..

1. We don't have file handles - so how can we work on two files at once??
2. There does not appear to be a RENAME function??

I'm in the process of putting a blog together to demonstrate how to get around a lot of problem with Lua including inability to block callbacks - and in the process realised that many apps will need to remember their status on power up - this seems the logical way to do it .... but --- with issues (1) and (2) above I don't see any way to do this?