Advice on writing/altering klipper code: dev tools, best practices, etc

New here and to Klipper. I started converting an old printer (Monoprice Maker Ultimate) to use Klipper and want to do a bit of development. I have programming experience, but not much in the embedded world. I’m looking for advice on how to start doing some Klipper development. I read through the developer documentation, but it wasn’t what I needed.

  1. Thoughts on an IDE, or how to go about coding without plugging a keyboard/monitor into the RPi? VSCode + Remote SSH plugin?
  2. Tips for quickly being able to test new python code? For example, it took a very long time to figure out that I had to delete the cached files for my changes to be reflected. (I’m all C++, in the process of learning Python). Feels like I am maybe missing something fundamental, like a “developer mode”.
  3. Tips on logging/debugging? I’m sure for an experienced user, the log files are great. I end up with a MASSIVE log file after a while, where 99.99% of the information is irrelevant. Lets say I just want to log a couple variables, and the time they occurred…is there a good way to do that? Is there a way to restart a log file?
  4. Any information on the underlying structure of klipper? I have many questions about this. For now, I’m just trying to understand how information flows. Say I add a module. Take the heater.py module, for example. From where is that called? How often? Is it a fixed rate? Can I change the rate? How can I obtain information about the state of the machine? etc.

I understand these may seem like silly questions, but overall I’m just struggling to get started. I’m working to improve my understanding, but I’m hoping for a (big) push in the right direction. Any help and general advice is appreciated!

I’m curious, what kind of development do you want to do?

It seems that you are very new to Klipper and I’m wondering why you feel you see needed changes when you have minimal experience with it?

First and foremost, it’s less “need” and more “want” and “interested”. I’d love to learn and contribute. I am indeed very new to Klipper, but that doesn’t mean I don’t want to learn.

In terms of what kind of development I want to do, first on the docket is the heater code. Will it ever make it to a pull request? Maybe not. Is it necessary in order to get my setup running? Nope. Would I love to implement a controller other than PID? Absolutely.

Really the goal is to learn. With any luck, I’ll eventually be able to give back to the community in some small way. Even if that’s building a better understanding to be a more qualified reviewer for pull requests.

VSCode for C and for running tasks like deployments.

I use rsync to deploy code between my dev laptop and the test printer.
After the rsync I restart the klipper process so it picks up the new code.

Every time I deploy I wipe the log file so I don’t have to wade through a endless file.

You can see the tasks I have here: klipper-voron2.4-config/.vscode/tasks.json at nextruder-hx717 · garethky/klipper-voron2.4-config · GitHub

Got it, I’ll have to take a look. I’m on windows (for now…) so I may have to find an alternative to rsync.

I am curious, though. When I change Python code (using nano, for example) and restart Klipper (using Fluidd, not in the terminal), it does not pick up the new code. I have to use the terminal to stop klipper, delete the Python cache, and start klipper again. Is that normal?

@rtf0004

Also, if you’re looking into creating a custom Klippy extra, I wrote a guide here.

1 Like

That looks extremely helpful. I kept thinking “if only there were a ‘hello world’ equivalent to get started,” and that’s it! I guess I didn’t realize there was a klipper vs klippy, either. I’d suppose that for now I’m trying to play with klippy. Eventually I want to get into klipper, too, though.

1 Like

If you restart the klippers service it will automatically rebuild the cache on startup. Once you have passwordless SSH access set up you can run a command on the development machine to do this remotely:

ssh pi@your-printer.local 'sudo service klipper restart'

My “:package: + :play_or_pause_button: Deploy & Restart Klipper” chains together deploying the config, deploying the code, wiping the log file and restarting the klipper service. Saves hours of wasted time.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.