I am trying to use persistent variables to save my last nozzle temperature so i can use it as an appropriate temperature in my change filament macros.
I have included [save_variables]
filename: ~/printer_data/config/variables.cfg in my printer.cfg. it will save the value to variable.cfg under the heading [variables] but then everything will stop working.
After i restart it says âSection âvariablesâ is not a valid config sectionâ
ive tried renaming stuff and including the variables.cfg in my custom_macros.cfg and my printer.cfg. Not sure what im supposed to do.
Hello there, my goal is not to change the temperature but to record the last temperature printed at, so I can have an appropriate temperature applied when I have the printer change the filament for me. (To keep from over or underheating the filament when it is removed or purged)
I suppose my wording was a little confusing, I meant change between uses of the macro, not during the use of the macro.
I plan to eventually save the filament type and have a preset for each one so the temperature is set perfectly, but as I am still figuring out persistent variables I want to keep it simple
This is exactly what I do and it works great. I think your problem is that when using save_variables, you donât include the variables.cfg in your config file. So per the documentation, your config file would have the [save_variables] section that specifies the filename where the variables will be stored, and thatâs the only reference to that file that should appear in the config. Donât try to also include that file in the config file itself. In fact, I would suggest calling your variables file something like variables.txt just to help remind you that itâs not a cfg file.
The SAVE_VARIABLE command wonât (and shouldnât) make any changes to the config file itself, it simply writes the variable and assigned value to the defined variables file.
I assumed i had to include it because i have to include other files in the printer.cfg so i was doing it to be safe. I removed the [include variables.cfg] from everything and renamed it like you recommended. klipper is no longer complaining about a bad config section, however it does not update the variable. Ive changed the value of LAST_PRINT_TEMP manually and it doesnât change back when i run my start print macro
Iâm not sure what you mean when you say you âchanged the value of LAST_PRINT_TEMP manually,â or what youâre expecting to happen when you execute your macro. If you mean you edited the variable file by hand, that wonât work unless you stop the klipper host process first, make the change, and then restart the host process. Klipper reads the variable values at startup and then assigns them to a dictionary in the printer object. It tracks any changes to the saved variables in memory and writes them to the file when saved (if theyâre changed) but it doesnât re-read from the file unless the host process is restarted.
If you want to test to make sure the macro is working as expected, just issue these three commands one at a time:
yes i did edit the variable by hand, and i understand what you have explained to me for the most part. however i am not sure how to cat my variables.txt file or what that really means. I looked it up so i think i understand what it is but i donât know how to implement it, i couldnt find anything relating specifically to klipper
Sorry, I was making assumptions that I probably shouldnât have. cat is a Linux command that essentially displays the content of a file. I was assuming that you had established an ssh terminal session with the Klipper host machine and had used standard Linux commands to manually edit the variables file, in which case you could simply cat the file to see its current contents.
If you are using a web frontend such as in Mainsail to view or modify file contents, Iâm not sure whether the expected behavior would be different, as Iâm not sure whether Mainsail immediately writes to the local file, caches file contents, etc. Maybe you can see the changes to the stored variable simply by reopening the file in the web frontend, but if not, Iâm not familiar enough with the frontends to know whether thatâs because of a quirk in the frontend or if it necessarily means the file contents hasnât changed on the disk.
ohh I see. I was editing the file through mainsail. i was thinking about it and realized that my save variables was defined in my printer.cfg not in my custom_macros.cfg, i moved it and now all is well. thank you for your help, it seems there were many small issues that needed fixing.
for anyone reading this later, my issues were that i was including my variables.cfg in my printer.cfg, and that i had defined my save variables in the printer.cfg and not in my custom_macros.cfg