Piezoid / klipper-repl

The missing Klipper command line. A CLI G-Code REPL for 3D printers running on Klipper firmware.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

klipper-repl

The missing Klipper command line.

Screenshot of klipper-repl

klipper-repl is a command line reimplementation of the browser-based G-Code console implemented by Klipper frontends like Fluidd and Mainsail. Its features include:

  • Automatic reconnection if Klipper restarts or is unavailable
  • Scripting support
  • Multiple G-Code commands per line -- use , as a separator
  • Syntax highlighting for both G-Code and user-defined macros
  • Tab autocompletion for user-defined macros
  • M112 emergency stop processing
  • Support for multiple printers via GNU Parallel

Installing

Via a Nix flake

If you have the Nix package manager, this package is available as a Nix flake. An example flake.nix for a host running Klipper is:

{
  inputs = {
    nix-doom-emacs.url = "github:unjordy/klipper-repl";
  };

  outputs = {
    self,
    nixpkgs,
    klipper-repl,
    ...
  }: {
    nixosConfigurations.klipperHost = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        {
          environment.systemPackages = [
            klipper-repl.packages.${system}.default
          ];
        }
      ];
    };
  };
}

You can also run klipper-repl without installing it using

nix run github:unjordy/klipper-repl

Via pip

pip install klipper-repl

Usage

Running interactively

Assuming klipper-repl is running on the same host you're currently logged into, and that your Klipper API socker is located at /run/klipper/api, you can get an interactive G-Code REPL with:

klipper-repl /run/klipper/api

Usage in scripts

You can evaluate one line of G-Code as follows. Note that you can use the , character to incorporate multiple G-Code commands into one line, and that G-Code is case-insensitive (but generally gets converted to uppercase by Klipper).

klipper-repl /run/klipper/api g28, screws_tilt_calculate

Emergency stop

Typing the command m112 into klipper-repl will immediately discard the rest of the command buffer and send an emergency stop signal to Klipper.

Running remotely

klipper-repl doesn't provide any of its own facilities for operating on remote systems. Instead, install klipper-repl on each of your Klipper hosts and use ssh to run it remotely. For example, to get a remote interactive REPL:

ssh klipper@klipper-host -t klipper-repl /run/klipper/api

Note that the -t argument to ssh allocates a TTY for klipper-repl, which it needs to properly render its prompt.

For convenience, it's recommended to create a shell function or script that runs klipper-repl for a specific Klipper host and socket. For example:

#!/usr/bin/env bash

ssh klipper@klipper-host -t klipper-repl /run/klipper/api $@

Save this as something like klipper-host-repl and mark it executable, and you can use it exactly like you would klipper-repl.

Sending commands to multiple printers

You can combine klipper-repl with GNU Parallel to run G-Code commands across multiple printers and multiple Klipper hosts. GNU Parallel is an incredibly flexible way to run multiple commands simultaneously and I highly recommend reading its manual, but an example of using it with klipper-repl to control multiple printers is:

parallel klipper-repl /run/klipper/api-{} ::: printer1 printer2

About

The missing Klipper command line. A CLI G-Code REPL for 3D printers running on Klipper firmware.

License:GNU General Public License v3.0


Languages

Language:Python 92.7%Language:Nix 7.3%