This post is a series of posts in which I detail my journey to bring OctoPrint to the Seeed Studio reTerminal.
Day 7
In today’s post we’ll be continuing the addition of a Settings Page so we can set the URL first with the config.yaml
file and also then with a new Template.
Contents
Day 1 – 05–09–22 – Getting Started:
- Getting Started – 05/09/2022
- My Initial Plans
- Cloning the Repos
- A pointer in the right direction from the folks at OctoPrint3D – Plugins
- OctoPrint Plugin Mixin Development Docs
- Getting the Development Environment setup
- Installing Python
- Checking out the OctoPrint Sources
- Creating and Activating a Virtual Environment
- Build Tools for Visual Studio 2019
- Setting up VirtualEnv
- Adding VirtualEnv to the Windows Path
- Upgrading Pip
- Setting up the Virtual Environment
Day 2 – 06–09–22 – Setting up the Environment:
- OctoEverywhere – 06-09-22
- Continuing with VirtualEnv
- Activating the Virtual Environment
- Setting up the Virtual Environment
- Installing Microsoft Visual C++ 14.0
- Using pip to install packages in the Virtual Environment
- Git Pre-Commit
- Git Changes, Blame and Ignore
- Configuring VS Code
- Running OctoPrint for the first time
- Changing the Python Interpreter
- Running the OctoPrint from VS Code
Day 3 – 07–09–22 – Setup Wizard:
- Setting up OctoPrint in the Debug Environment – 07-09-22
- Setup Wizard – Access Control
- Setup Wizard – Online Connectivity
- Setup Wizard – Usage Tracking
- Setup Wizard – Plugin Blacklist
- Setup Wizard – Printer Profile
- Setup Wizard – Please Reload
- Setup Wizard – Setup Printer (Again)
- Setup Wizard – Server Commands
- Setup Wizard – Webcam and Timelapse Recordings
- Setup Wizard – Finish
- Virtual 3d Printer Plugin
- Beginning Plugin Development
Continuing the Settings Page – 12-09-22
We need to replace our init.py file again with the following;
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")
def get_template_vars(self):
return dict(url=self._settings.get(["url"]))
__plugin_name__ = "Hello World"
__plugin_pythoncompat__ = ">=3.7,<4"
__plugin_implementation__ = HelloWorldPlugin()
Where we’ve now added a line to get the template variables with get_template_vars
.
And also replace our templates/helloworld_navbar.jinja2
file with;
<a href="{{ plugin_helloworld_url|escape }}">Hello World!</a>
Where we’re now grabbing the URL from our plugin settings.
Reloading OctoPrint, refreshing the page and hovering over our “Hello World” link we can see that the link is still the same;
Using the OctoPrint config.yaml
We can set the value of our URL setting by adding it to the OctoPrint config.yaml
file within the plugins section. The docs state that we should add that section if it doesn’t exist… Let’s have a look…
I don’t seem to be able to find the config.yaml file in the OctoPrint folder… Looking on the internet, I see that there should be one at %APPDATA%/OctoPrint
so let’s go and have a look there…
Opening up the run dialog with WIN+R;
Hmmm… No luck there;
Searching in the OctoPrint folder in VS Code, I find the documentation for the config.yaml file;
This file says;
If the file is not there, you can just create it – it will only get created by OctoPrint once you save settings that deviate from the default settings
So, I wonder if just changing the settings in OctoPrint through the UI will create the file for us?
Navigating to the Settings page, I’ve had a quick look at the Folders page;
Knowing that the OctoPrint folder isn’t event there, I wonder if just pressing the Test
button beside any of the folders would create either the folder or even the config.yaml
file?
So the path is valid… Now, has it created the folder and/or the config.yaml file?
Sadly not then it seems… Well, let’s try changing one of the OctoPrint settings then eh.
Let’s try something simple like selecting the Remember selected folder in file list
;
Sadly that didn’t work;
I wonder if it’s created anything in the OctoPrint Project Folder?
Sadly, I find nothing there…
Ok, so, the documentation I found says that we can just create the file… So, let’s do that and see if it will use it.
Navigating to my %APPDATA%
folder, I can create an OctoPrint folder, and then a config.yaml file;
Looking back at the Hello World plugin tutorial, we need to add the following to the config.yaml file;
plugins:
helloworld:
url: https://de.wikipedia.org/wiki/Hallo-Welt-Programm
Adding that to the file, saving it and restarting the OctoPrint Server, let’s see if the URL has changed;
Sadly the URL hasn’t changed.
Checking in the settings, our setting we changed earlier has saved ok;
So something is being saved somewhere, but I don’t know where…
Searching in the project codebase for config.yaml
I find it appears in quite a few files;
Looking in settings.py
I can see where the code is defaulting to the base directory of and appending config.yaml
.
Stopping the Server, adding a break point and restarting the server, we can see where the application is expecting to load the config.yaml
file from;
Hovering over self._configfile
we can see that indeed, OctoPrint is looking for the config.yaml
at 'C:\Users\pete_\AppData\Roaming\OctoPrint\config.yaml'
, which is where we’ve created it.
Time to dig a bit deeper… I’m guessing that perhaps our issue is that we don’t have a correctly formatted file perhaps…
Let’s go look what an example config.yaml file looks like.
After having to restart my existing OctoPi Pi, and do some network diagnosis when I couldn’t reach it, I can SSH into the OctoPi using the Terminal;
Navigating to the ~/.octoprint
directory and opening the config.yaml file in nano with nano config.yaml
;
Looking at the docs for the config.yaml file, this looks like what I’ve pasted is ok to be fair.