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

User avatar
By scargill
#4242 If you create a file using a serial terminal you can easily make default values for variables on power up. But while using a variable in a Lua programming legs say to control a light how do you make that non volatile so it stays put through power cycling???
User avatar
By yes8s
#4243
scargill wrote:If you create a file using a serial terminal you can easily make default values for variables on power up. But while using a variable in a Lua programming legs say to control a light how do you make that non volatile so it stays put through power cycling???


The only way is to write variables to a file and load these on init. I don't think there is any other way in Lua.
User avatar
By scargill
#4411 Ok, I have figured it all out - I'm so chuffed I have a working App - got the structure - (almost) everything I need and I'm about to do a blog to explain what I've done - you'll love it - BUT firstly I need to read and or update a lua file..

I need 2 routines - one to update or add a line to a lua file if not there - the other to read a value.

So lets say the lua file has the following in it

a=1
b=2

Open the file - that's easy - read ta line at a time - that's easy - and that's where I went wrong.

a="pin=9"
item,value=string.gmatch(a, "(%w+)=(%w+)")
print(item)
print(value)


Doesn't work - bear in mind I'm rubbish at Lua and I don't want to add a library - need the simplest route... Why doesn't the above split the line into "a" and "9"
??

So what I'm after is to end up with 2 short functions..

x=readvar("a")
updatevar("a","45)

Anyone feeling ambitious - remember it needs to be short and fast?

And before anyone says you should make a temporary file - we don't have file.rename !!

I think someone needs to put in a request...ZERODAY are you looking in?