Coder Social home page Coder Social logo

plugin-examples's Introduction

OctoPrint Plugin Examples

This repository collects the sources of examples for writing plugins for OctoPrint.

Currently the following example plugins and more can be found here:

  • add_tornado_route: Single file plugin (place it in ~/.octoprint/plugins) that shows how to utilize the octoprint.server.http.routes hook to add additional routes with custom RequestHandlers to the server configuration.
  • custom_action_command: Single file plugin (place it in ~/.octoprint/plugins) that shows how to utilize the octoprint.comm.protocol.action hook hook and how to register hook handlers that are part of a mixin implementation. The plugin will listen for firmware messages of the form // action:custom and if received will log that it received the "custom" action from the firmware.
  • custom_template_consumer: Single directory plugin (place it in ~/.octoprint/plugins) that shows how to have a plugin inject itself into custom places provided through other plugins in the web interface through utilizing a custom template type if the presence of the provider of that template is detected.
  • custom_template_provider: Single directory plugin (place it in ~/.octoprint/plugins) that shows how to provide a custom template type through the octoprint.ui.web.templatetypes hook and how to display templates of that type.
  • helloworld: A simple plugin that injects itself into various places in OctoPrint's web interface to display "Hello World". Shows the basic structure of a plugin, how plugins can execute code at startup, inject themselves into the interface and how they can control when their content is shown based on internal state of the UI such as login information.
  • increase_bodysize: Single file plugin (place it in ~/.octoprint/plugins) that shows how to increase the maximum allowed request body size for specific endpoints by utilizing the octoprint.server.http.bodysize hook.
  • message_on_connect: Single file plugin (place it in ~/.octoprint/plugins) that shows how to utilize the octoprint.comm.protocol.scripts hook by adding an M117 OctoPrint connected to the GCODE script sent to the printer after OctoPrint connected to it.
  • rewrite_m107: Single file plugin (place it in ~/.octoprint/plugins) that shows how to utilize the octoprint.comm.protocol.gcode hook by swapping the (deprecated) M107 command with the equivalent M106 S0.
  • strip_all_comments: Single file plugin (place it in ~/.octoprint/plugins) that shows how to utilize the octoprint.filemanager.preprocessor hook by removing the comments (and empty lines) from all uploaded/generated GCODE files ending on the name postfix "_strip".

Further Links

License

These examples are licensed under the MIT license. See also LICENSE in the source folder.

plugin-examples's People

Contributors

foosel avatar kantlivelong avatar mscalora avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plugin-examples's Issues

Missing example how to replace one gcode line with multiple lines

The octoprint.comm.protocol.gcode hook allows removing or rewriting gcode during printing. But how do I replace one gcdoe with multiple?

The problem I want to solve is the backlash correction for the M3D printer. The current plugin corrects this during slicing, resulting in a totaly eratic tool path in the gcode viewer. I want to do this during printing instead so the viewer still sees the clear code. But for this little movement commands must be inserted before changes in direction. E.g. if I have
G1 X0 E0
G1 X10 E10
G1 X0 E20
then the head will not end up at X0 due to backlash. Before the 3rd line a "G1 X9" must be inserted followed by "G1 X-1 E20". So I need to both insert and rewrite. Do I just return "G1 X9\nG1 X-1 E20" then? Is that allowed? Is there a better way?

Example of how to retrieve settings from Non SettingsPlugin classes?

I'm creating a variation on the Comment Remover plugin, but it also needs a handful of settings. octoprint.filemanager.util.LineProcessorStream doesn't appear to have easy access to self._settings, though, so retrieving them when it's time to actually process things is a bit tricky.

Is there a recommended/correct way to retrieve them outside of the plugin class itself?

License

This repo doesn't have a license file. Are these examples public domain/MIT/etc. or AGPL like the rest of OctoPrint?

Machine Type example problematically

In the read_m115_response.py line 10
the given d.split(':') is problematically and can cause an exception:

Example Response:
FIRMWARE_NAME:Repetier_1.0.0dev FIRMWARE_URL:https://github.com/repetier/Repetier-Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Core_XY EXTRUDER_COUNT:1 REPETIER_PROTOCOL:3

Important part:
FIRMWARE_URL:https://github.com/repetier/Repetier-Firmware/

as you can see this line contains 2 colons which leads to a split like this:
["FIRMWARE_NAME", "https", "//github.com/repetier/Repetier-Firmware/"]

this can't be processed by the dict() and therefore leads to an exception.

proposed change, replace the oneliner with this code or similiar:

split_line = line.split(' ')
printer_data = dict()
for d in split_line:
	data = d.split(':')
	printer_data[data[0]] = ':'.join(data[1:])

This also affects the wiki entry.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.