Saving Variable Values Across Resets – Is It Possible?
-
Hi, I have a general question about whether I'm doing something wrong or if this is simply not possible. I'm also not sure if this is the right place to ask this question, so if there’s a more appropriate location, feel free to move the post there.
I want to save a variable or, more specifically, the value of a variable, and keep it stored even after a board reset. The variable accumulates values during printing, and I want this value to persist until a manual reset via G-code.
I declared the variable in the config as follows:
global totalDistance = 0
After resetting or restarting the board, I want the saved value to be restored. I tried two approaches:
Using save_variables.g: M28 "0:/sys/saved_variables.g" echo "set global.totalDistance = " ^ {global.totalDistance} M29
However, the problem here is that it only saves the text and does not store the actual value behind {global.totalDistance}. When I send the command manually:
echo "set global.totalDistance = " ^ {global.totalDistance}
it outputs:
set global.totalDistance = 2357
But after restarting the board, the config resets the variable to 0, and I cannot figure out how to reload the state or value of the variable after the restart.
I also tried using M500 to save the variable's value, but this only saves axis-related information.
So my question is: Is there a way to save the value of a variable?
Some information about my hardware, although it’s irrelevant to the question:
Hardware in use:
Duet 3 Mini 5+ with RepRapFirmware 3.5.4
Duet 3 Expansion 1HCL 3.5.4
Duet Web Control 3.5.4 -
@tino_ber48 try something like this
echo >"save_variables.g" "set global.totalDistance = " ^ global.totalDistance
see here https://docs.duet3d.com/en/User_manual/Reference/Gcode_meta_commands#echo-command
-
Ok WOW, many thanks, @jay_s_uk ! The syntax works, and it saves the value correctly in save_variables.g! Many thanks again, I was already on the verge of giving up and searched forever for a solution, but I hadn't thought of the meta commands. Thanks again!
-
@tino_ber48 you're welcome. glad its working!
-
undefined Phaedrux moved this topic from General Discussion