Logic Machine Forum
save the value of a variable in the LM - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: save the value of a variable in the LM (/showthread.php?tid=2016)



save the value of a variable in the LM - camilo - 09.04.2019

Hi,

I would like to know how I can save the value of a variable inside the memory of the LM, but that this value will never be erased.
the idea is that I keep the value of a meter variable one month (for example March), the next month (for example April) I create another variable and I keep the value of that month in that variable. Then I take the value of the first variable and I make a difference between the first and the second variable. this to make a comparison of consumption.

I've been looking for a similar example but I have not found anything.

thank you Big Grin


RE: save the value of a variable in the LM - Daniel - 09.04.2019

Hi
Just use trend and counter and all this will be done for you automatically
BR


RE: save the value of a variable in the LM - camilo - 09.04.2019

Hello,
Thank you, but I do not know if you have an example of how to use the trend and the accountant is honestly new to this
I would really apreciate it


RE: save the value of a variable in the LM - Daniel - 10.04.2019

Hi
How do you want to display the data? If via trend then in there you have ready solution to compare the same trend with different period. If you want the value itself then fetch the data via this. http://openrb.com/docs/trends-new.htm


RE: save the value of a variable in the LM - camilo - 08.05.2019

Hi.
I have tried with the trends but it does not give me the desired result.
Is there another way to carry out this process without the tendencies?
that is, for example with the storage library, save in a position X of the LM the value of the month and that the next month be stored in a position Y of the LM without affecting the previous value.
With the above, can data be stored for more than 2 years?
thank you


RE: save the value of a variable in the LM - admin - 09.05.2019

You can use storage for any kind of data. For example you can store a Lua table there, where each table key is year-month pair:
Code:
key = os.date('%Y-%m') -- YYYY-MM format
value = 123 -- current value

values = storage.get('values', {})
values[ key ] = value
storage.set('values', values)



RE: save the value of a variable in the LM - camilo - 21.05.2019

good day.

Thank you very much, the code was very helpful.
Now I would like to know how I can do so that the data in the table are global.
since I try to read them in another script but it gives me null values


RE: save the value of a variable in the LM - Daniel - 21.05.2019

All storage is available in every script. If you have null this is what the storage contain then.


RE: save the value of a variable in the LM - camilo - 18.07.2019

good day.

Thank you very much, now I would like to know if there is a way to eliminate what is stored inside the storage code, since until now I do it through the storage application that the LogicMachine store has.
Another thing, I've noticed that as I store the information with storage, this increases:

https://drive.google.com/open?id=1gVOgmC_77qlh1EZrCAVwia8TxbsAuhYd

I looked and I realized that memory is increasing according to what is saved with storage, but I do not understand why in "disk" is increasing, which function meets "disk" and there is a way to clean that part since sometimes it reaches 85% and the LogicMachine becomes very slow.


RE: save the value of a variable in the LM - Daniel - 18.07.2019

Code:
storage.delete(key)
Storage is saved in redis database which is saved every half an hour to Disk which is the SPI flash.