OctoPrint for the Seeed Studio reTerminal – Live Blog – Day 6

This post is a series of posts in which I detail my journey to bring OctoPrint to the Seeed Studio reTerminal.

Day 6

In today’s post we’ll be doing some more with the Hello World Plugin including adding a Settings Page so we can set the URL first with the config.yaml file and also then with a new Template.

Contents

Adding a Settings Page to Hello World – 10-09-22

Next in the tutorial, we go on to add a settings page to our plugin as well as allow the Wikipedia url to be set and delivered to our template.

For this part of the tutorial we’ll be implementing the SettingsPlugin plugin mixin;

Including the SettingsPlugin mixin allows plugins to store and retrieve their own settings within OctoPrint’s configuration.

We can also then override the get_settings_defaults() function.

The Tutorial shows to replace our plugin code with;

import octoprint.plugin

class HelloWorldPlugin(octoprint.plugin.StartupPlugin,
                       octoprint.plugin.TemplatePlugin,
                       octoprint.plugin.SettingsPlugin):
    def on_after_startup(self):
        self._logger.info("Hello World! (more: %s)" % self._settings.get(["url"]))

    def get_settings_defaults(self):
        return dict(url="https://en.wikipedia.org/wiki/Hello_world")

__plugin_name__ = "Hello World"
__plugin_pythoncompat__ = ">=3.7,<4"
__plugin_implementation__ = HelloWorldPlugin()

This new code will spit out the Wikipedia URL to the console on startup.

So, replacing our init.py content and restarting OctoPrint;

OctoPrint – Hello World Plugin – Settings Console Log

We can see we have an extra section to our console log now beginning with the word more.

Next up we’re going to make use of Knockout Data Bindings to deliver our new settings to the plugin template.

Leave a Reply