mmone / OctoprintKlipperPlugin

A plugin for a better integration of Klipper into OctoPrint.
GNU General Public License v3.0
83 stars 62 forks source link

[Feature request] Configuration File Edit #6

Closed JustAnother1 closed 6 years ago

JustAnother1 commented 6 years ago

I would like to be able to edit the Klipper configuration file from the Octoprint Web Interface.

Use Case:

I have a delta printer running Klipper. To do the bed leveling I need to change the position of the end stop in the configuration file. If the nozzle at G1 Z0 is still too high I need to increase the position of the three end stops. if the nozzle is already touching the print bed then I need to lower the position. As all three end stop positions need to be altered every time this is a bit unpleasant.

possible solutions:

One way to solve it would be a "Text editor Window" that has the contents of the configuration file and lets me edit it just like every text editor. The other way would be a fancy window that has buttons and spinners and check boxes and whatever it needs to set all the settings possible in a configuration file. If the user then clicks save the check boxes and spinners are parsed and a configuration file is created with the configured settings. This would probably be easier for people that don't know the configuration file by hearth. If the fancy dialog does not have all the settings (to not confuse the user) the text editor could be used as "Expert mode" view of the fancy window.

next steps:

What would be the next steps to make this happen? What can I do to help make this happen?

mmone commented 6 years ago

Hi,

a config file editor would be an interesting thing. As far as file permissions go it shouldn't be a problem to read/write the config file with the plugin.

For your specific use case Klipper might already have a suitable solution though: delta-calibration

A texteditor integrated into the plugin settings is certainly the most straitforward solution and could be a good testcase to get into OctoPrint plugin development. The documentation is quite good and comes with a tutorial: OctoPrint documentation.

A form based editor is definitely doable but would create quite some initial work and ongoing maintenance as the klipper interface is still evolving. One hurdle there is the ancient Bootstrap version OctoPrint uses that makes creating forms a pain.

Last but not least I think editing the config file via SSH lets you iterate pretty fast also. If you prefer to use a non commandline Interface you can use a sftp capable file browser like Cyberduck. This allows you to edit your file locally with your preferred text editor and upload automatically when you hit save.

In conclusion: I have no immediate plans/time to implement this feature but would very much like a PR :-)

Martin

JustAnother1 commented 6 years ago

For your specific use case Klipper might already have a suitable solution though: delta-calibration

I assume that that needs a bed level sensor, that I don't have.

The documentation is quite good and comes with a tutorial: OctoPrint documentation.

I will look into that.

oderwat commented 6 years ago

I also use an external editor for editing files on the RasPi. As it happens that I wrote some small post about that in a FB user group I think it can't hurt to re-post it here:

Little trick for you OctoPrint (+ Klipper) user. If you know how to work the terminal there is a pretty comfortable way to edit files on your Raspberry Pi with an editor on your normal Computer. At the same time you may want to check out one of the best editors currently available (and it is from Microsoft, so I would never say this if it weren't true, cause I am a hard core OS X and Linux user).

The setup makes it possible to for example simply type code printer.cfg on the terminal on the RasPi to edit the file on you computer:

  1. You need Vistual Studio Code (an "Atom" like Editor from Microsoft. It is just great and available for Windows, Mac, Linux): https://code.visualstudio.com/

  2. You need to install the Remove VSCode Plugin: https://marketplace.visualstudio.com/items

  3. You need to change the user setting of the plugin by adding the following lines to your user config:

"remote.host": "0.0.0.0",
"remote.onstartup": true,
"remote.dontShowPortAlreadyInUseError": true,
  1. You need to login to you RaspPi by SSH and run the following commands:
sudo wget https://raw.githubusercontent.com/…/rmate-…/master/bin/rmate -O /usr/local/bin/rmate
sudo chmod a+x /usr/local/bin/rmate
  1. From there on you can edit a file on the RasPi by typing:
rmate --host <the local network ip of you computer> <filename>

The file will load in Visual Studio Code and can be edited and saved as usual. You should check out the other options with:

rmate --help

The local IP is most likely something like 192.168.x.y and should be visible in the network settings of your computer. It may change though and usually can be set to a fixed address.

I added a line like the following to my ~/.bashrc script on the RasPi:

alias code='rmate --host 192.168.2.100 '
alias sucode='sudo rmate --host 192.168.2.100 '

This way I can very easily edit my files doing a:

code printer.cfg

Just wanted to let you know :) Not sure how many people here are actually capable and interested to follow this tip :)

outlookhazy commented 6 years ago

@mmone One possibility on the configuration/form front might be to only support editing of values for existing keys in the config file, and potentially only certain subsets of those (i.e. calibration/adjustment values).

My biggest annoyance with the remote text editor/ssh approach is editing the config in one window, resetting klipper in another window to apply the settings, then controlling klipper with yet another to test said settings. Potentially more than that with a slicer open etc.

An integrated solution would be able to automatically apply a restart command after applying changes. There's also the added benefit of data validation. Once you have an "in" to the config file at the k/v pair level, implementing things like automatically applying PID calibration values is pretty trivial. Unfortunately my version of this was a .NET app that used a tweaked INI parser for the config. Unfortunately the multiline script sections (i.e. probe) break the parser library I'm using, and I don't really feel like writing one from scratch.

mmone commented 6 years ago

I need no convincing that an integrated editor might be a convenient thing to have, though I personally don't seem to miss this feature as much as others do. To be quite honest it's just that other projects are more pressing/interesting at the moment. I'm still hoping that someone might be able to contribute this feature.

Maybe I should write some code overview doc to lower the entry barrier. The server/client separation might be a hurdle in the beginning. I still think though that the official plugin tutorial mentioned above is much better than what I could provide.

Your idea to limit editing to existing keys would definitely reduce the effort and the maintenance impact of a still evolving Klipper interface. It would also do the same for it's usefulness in my opinion as the first hurdle for a new user is rather to get an overview of the available options and get them right then to modify a working config.

If I could dream up a solution that would be for Klipper to provide some kind of introspection capability that would allow a client to query for available configuration keys/commands and their parameters and accepted values. I have looked briefly into what changes that would entail on the Klipper side of things and as expected these would be quite significant so I wouldn't expect Kevin to accept this as a PR at the moment.

mmone commented 6 years ago

With 0.1.5 I've integrated a simple config editor and amongst other things cleaned up the code a bit. Testers are very welcome. To update just reinstall with the plugin manager from this url: https://github.com/mmone/OctoPrintKlipper/archive/master.zip. Existing settings should be automatically migrated. Starting with this release the plugin will also inform about available updates in OctoPrint when they become available. I will probably add at least basic syntax highlighting to the config editor soon.

Providing a meaningful status display in the header is still a problem. Klipper is just not very talkative when it comes to its status. E.g. after a "Restart" it logs "Preparing to restart" but never acknowledges when it is done.

Martin

outlookhazy commented 6 years ago

@mmone Very cool, I'll try to remember to check it out this weekend (lots of other projects going on)

mmone commented 6 years ago

Closing this as a basic config editor is now part of the plugin. Down the road there is probably gonna be a form based editor as well.