CNC Pendant - How To Plugin

Staring a new plugin.

Where do I put the python files for the plugin while I'm developing? Which folder in OctoPrint? Also, how do I get get OctoPrint to reload my plugin whenever my file has been modified?

There are many ways, I'm sure.

The way I develop a plugin is to begin with the cookiecutter as described here. I do this locally on my macOS workstation in a folder I might call OctoPrint-Something.

I'll create a folder on the Pi (~/OctoPrint-Something) and a shell script that will rsync things over to it which might look a bit like:

/local/scripts/syncit (since that folder is in my path on the MacBook):


rsync -avz --no-perms --exclude '.DS_Store' ~/OctoPrint-Something/ pi@octopi.local:~/OctoPrint-Something

In the local folder I'll do a git init to track things.

On the Pi, I'll add an alias in the ~/.bashrc file:

alias begin='source ~/oprint/bin/activate && cd ~/OctoPrint-Something'

...and add a script somewhere in my path there like the /usr/local/bin folder...



cd ~/OctoPrint-Something
python develop
sudo service octoprint restart
tail -f ~/.octoprint/logs/octoprint.log

How things then work each iteration

  1. Using Visual Studio, edit one or more files in the folder on the MacBook
  2. Run a macro which executes that syncit script which will synchronize the files over to the Pi which have changed
  3. Switch to a remote ssh session to the Pi
    • Once per session, run begin to activate the virtual environment and to put me in the correct folder on the Pi
    • If I'm still tail'ing the octopring.log, do a Ctl-C
    • Run cycle which will re-introduce the changes for my plugin to OctoPrint, restart it and tail the log

The cookiecutter application will scaffold things which should work well. You'll end up with something like:

  • OctoPrint-Something
    • <- You only usually end up editing this when the version updates
    • <- This is what people see in the plugin directory
    • something
      • <- Your startup Python is here
      • static
        • js
          • something.js
        • css
          • something.css
      • templates
        • something_settings.jinja2

My workflow involves a locally installed OctoPrint instance on my windows machine setup following the instructions here. I then do the same cookie cutter method linked by @OutsourcedGuru to create the framework for the plugin. Then once I have a point where I think I'm ready to test I zip up the contents of OctoPrint-Something folder into a zip file and then install it via the plugin manager and see what

So let me guess, no attaching a debugger then. Sigh.

I think I have seen ways of doing that here on the forum, but I personally have never used debuggers for my own development. That's why it probably takes me so long to program stuff.

Wow, developing without debugging, that's a "no go" for me!

Very interesting how each developer set up his/her environment.
See this thread for more approaches: Plugin development Tutorial Problem

My two cents about developing plugins:

  • In most cases I don't need real hardware for my plugins. So I develop the plugins on my local Laptop (prev. Windows, now Mac) with installed octoprint and a virtual printer
  • If I need hardware functionality I mocked that thing (e.g. temp-values, buttons, etc.)
  • Setup a new plugin structure is really easy with cookiecutter
  • Starting PyCharm IDE, do some initial configuration and here you go
  • If you change python code you only need to press restart, if you change ui-code, you just need to press reload in the browser
  • For the final test I push everyting to git (without releasing) and use my real-printer/octoprint to install the plugin via plugin-manager

I documented the IDE- and Plugin-Structure-Setup in my KnowledgeBase:


For the record, I do it like @OllisGit

To me not using a debugger is like not washing hands after using the toilet; this is how bugs spread.

I was hoping Ollis (Olli?) would chime in. :slight_smile:

I definitely need the actual hardware for my testing. I'm pushing all the boundaries of performance and cpu/gpu memory on this thing, GPIO, etc. After this month I should be able to share some photos when FormNext is over.

I'm an old programmer and my approach involves log feedback and manually forcing the tests of edge cases. If I had an AI to write automated test cases then I might trust that approach. What I usually see is that nobody has any time to focus on the test cases.

1 Like

I know, it's crazy right? In my approach it requires a lot of installing/restarting, but on windows that doesn't take much time. I do actually debug, just not the traditional approach of using a debugger and depend on errors popping up in console. Probably because I program in Notepad++ rather than PyCharm. I tried setting that up once but never could get it to work right. I'll have to walk through @OllisGit's knowedgebase and see if I can get it to work.

I just started a conversion of old gamepad to cnc pendant by adding esp32 inside of it so I can telnet to duet3d board and control printer .. would be cool to have support for usb based gamepad on octoprint too :smiley:

1 Like

Well it turns out that Marlin has a new joystick feature. It's buggy (and unusable) but I think I can improve on it somewhat. No need to go through OctoPrint.

1 Like