2021-03-25
md
OctoPrint on a Raspberry Pi 3 - the Hard Way

The range of my interests has expanded with the purchase of a 3D printer, the ANYCUBIC Mega Zero, that was highly praised especially given its very low cost. There will undoubtedly be more posts about that later. The printer has one unfortunate feature that is apparently shared with many others: the noise level when turned on is too high for continued use near my desktop computer. Consequently, the printer has been banished to a storage space behind a closed door at a safe distance from my work area. This post is a description of how I installed OctoPrint and MJPG-Streamer on a Raspberry Pi 3 B.

Given that the octoprint package will be moved to either a Rock Pi S or an Orange Pi Zero, I proceeded with a manual installation of OctoPrint as a Python package in a Python 3 virtual environment even on the Raspberry Pi 3 B. In other words, this is a practice run before the final installation of OctoPrint on a single-board computer that is not a Raspberry Pi. There's really nothing new here, as for the most part I followed the instructions in the Setting up OctoPrint on a Raspberry Pi running Raspbian or Raspberry Pi OS guide by Gina Häußge (foosel) who is the creator of OctoPrint.

If OctoPrint is to be run on a Raspberry Pi only, then installing the OctoPi Linux image on an SD card is probably the best route. It will certainly be easier and quicker especially for newcomers.

Table of contents

  1. Hardware
  2. Operationg System
  3. Network Configuration
  4. Build and Python Requirements
  5. Install OctoPrint
  6. Install MJPG-Streamer
  7. Octoprint Configuration
  8. Enabling the Services
  9. Next

Hardware toc

The Raspberry Pi 3 B is based on the BCM2837 SoC from Broadcom which contains 4 ARM Cortex A53 cores running at 1.2 GHz. On board there is 1G bytes of RAM, a 100 Mbits Ethernet port and 802.11 b/g/n Wi-Fi and Bluetooth chip. The system, which has a 2015 copyright on it, would be considered underwhelming by current standards, but it should be sufficiently powerful according to the FAQ: [...] are the Raspberry Pi 3, 3+ and 4."

A video feed of the printer in action seems almost mandatory when printing remotely. To that end, I will be using a third-party "Raspberry Pi Camera Rev 1.3" board. It contains a 5-megapixel Omnivision 5647 camera module capable of taking 2592x1944 pixel images, and streaming video at the following resolutions 1080p at 30 fps, 720p at 60 fps and 640x480p 60/90. The camera plugs directly into the camera serial interface of the Pi. For good photographs of how to connect the camera and the Pi with a flat ribbon cable, see Raspberry Pi Camera Module not working (v1.3)

A USB webcam could be used instead. That will be shown below also.

Also needed is a USB cable to connect the Pi to the printer. In my case that is a type A to type mini B cable. And, of course, a decent power supply for the Raspberry Pi is needed. Eventually, it will be necessary to get a case and some sort of holder for the camera. Perhaps they should be printed with the 3D printer? In any case (is that a pun?) that is beyond the scope of this post.

Operating System toc

As usual, I downloaded the current "server" version of the "official" operating system for the Raspberry Pi, called Raspberry Pi OS Lite:

    Release date: January 11th 2021
    Kernel version: 5.4
    Size: 438MB.

I used belenaEtcher to copy the image from the downloaded archive (it is not necessary to extract the image) to an SD card. That's a simple visual point-and-click procedure. Because the Pi will be run as a server without a connected keyboard or monitor, I always attempt to install the OS on the Pi without connecting anything to it except for an Ethernet cable. This means that I had to create a file named ssh in the boot partition that showed up on my Linux desktop computer after Etcher finished creating the file system on the SD card. The ssh file can be empty or contain anything you want; it is its presence when the Pi first boots that enables the SSH server.

I would now recommend using the Raspberry Pi Imager instead of Etcher because not only can ssh be enabled, but many of the options setup with raspi-config, including enabling Wi-Fi, can be accomplished with the imager. Just remember to press the CtrlShiftX key combination to get to the configuration menu.

To boot the Raspberry Pi,

This last step is rather easy if the desktop is a Linux box on which avahi is installed (it is by default in Ubuntu and other similar, or derived, distributions such as Mint).

michel@hp:~$ ssh pi@raspberrypi.local The authenticity of host '192.168.1.195 (192.168.1.195)' can't be established. ECDSA key fingerprint is SHA256:hF/RpKqxzIpMSOgzZk23ngdJNFrOSL2+i/6oQip2v6M. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.1.195' (ECDSA) to the list of known hosts. pi@192.168.1.195's password: raspberry this is not shown on the screen Linux raspberrypi 5.4.83-v7+ #1379 SMP Mon Dec 14 13:08:57 GMT 2020 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. SSH is enabled and the default password for the 'pi' user has not been changed. This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password. Wi-Fi is currently blocked by rfkill. Use raspi-config to set the country before use.

If there are problems establishing that first SSH connection to the Pi, an older post, Installation and Configuration of Raspbian Buster Lite, has an elaborate description of other ways of going about it which remain valid even if an older version of the operating system was used in October 2019.

At this point, I proceeded with the usual system set up. Again, I will not go into much detail here, but here are the usual changes made with the configuration utility.

pi@raspberrypi:~ $ sudo raspi-config
  1. Change the password: 1 System Options / S3 Password
  2. Enable the wireless network: 1 System Options / S1 Wireless LAN
  3. Set the timezone: 5 Localization Options / L2 Timezone
  4. Minimize GPU RAM (16 MB): 4 Performance Options / P2 GPU Memory
  5. Enabled the video camera: 3 Interface Options / P1 Camera
  6. Changed the host name to octoprint-pi: 1 System Options / S4 Hostname

If the Raspberry Pi is connected with an Ethernet cable to the local area network then there is no need to enable the wireless network in step 2. If using a webcam instead of a Raspberry Pi Camera module, there is no need to enable the camera interface in step 5. It does not really matter in which order these options are set, except that it is best to change the host name last because the system should be rebooted immediately after and the configuration utility will want to do that. Some may be tempted to avoid changing the host name, but it should be done to avoid conflicting names with the default raspberypi.local domain should another Raspberry Pi be added to the network. By the way, this may explain why opening the session with ssh pi@raspberrypi.local connected to a Pi already on the network. The host name of that Pi should have been changed before, but it's a bit late now. Try ssh pi@raspberrypi-2.local because zeroconf system avoids name collisions by appending ever-increasing integer suffixes to the host name.

The utility will want to reboot the system after changing the host name. Open an SSH station and, this is very important, update the list of packages and perform an upgrade.

michel@hp:~ $ ssh pi@octoprint-pi.local ... ssh may complain that it already has an entry for that inteface under a different name, just follow the on-screen instructions to resolve the problem ... pi@octoprint-pi:~ $ sudo apt update; sudo apt upgrade -y ...

You will probably have time to get some refreshments before the task is completed.

Network Configuration toc

It is usual to assign static IP addresses to servers and this section will show how to do it. However, it would be acceptable to leave the default DHCP assigned dynamic address or addresses in place if the devices which will access the OctoPrint Web interface can resolve the .local domain. That's usually the case for Linux and Mac OS systems and for Windows systems that have Bonjour Service enabled. So if the Web browser that will be used to connect to OctoPrint can reach a host with the name octoprint-pi.local then the rest of this section can be skipped.

Luckily, it is quite simple to set static IP addresss in Raspberry Pi OS. One or perhaps two entries in the dhcpcd configuration files is all that needs to be added.

pi@octoprint-pi:~ $ sudo nano /etc/dhcpcd.conf -B

That -B parameter will save the original file under a different name as a backup. Here are the

... interface eth0 static ip_address=192.168.1.28/24 static routers=192.168.1.1 static domain_name_servers=9.9.9.9 1.1.1.1 interface wlan0 static ip_address=192.168.1.29/24 static routers=192.168.1.1 static domain_name_servers=9.9.9.9 1.1.1.1

It is probably not necessary to specify static IP addresses for both the wired and wireless interfaces, but I find this useful during initial testing. To ensure that everything is fine, the Pi should be rebooted. Since both interfaces were assigned static addresses, I rebooted with both interfaces connected, and then twice again with only one and then the other interface enabled. It's easy enough to disconnect the Ethernet cable but to disable the Wi-Fi without disrupting other users on the network, I suggest modifying the SSID in the wpa_supplicant configuration file.

pi@octoprint-pi:~ $ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf -B

These test have shown that it is not possible to "hotplug" the wired connection. In other words, if the Ethernet cable is not connected to the Pi when it boots, the latter will not bring up the wired interface automatically when the cabled connection is made. This may be something that needs further investigation, but right now it is not an important issue.

Build and Python Requirements toc

Could OctoPrint be available in the usual repositories?

pi@octoprint-pi:~ $ sudo apt-cache policy octoprint N: Unable to locate package octoprint pi@octoprint-pi:~ $ sudo apt-cache policy octoprint* N: Unable to locate package octoprint* N: Couldn't find any package by glob 'octoprint*' N: Couldn't find any package by regex 'octoprint*'

As the above shows, there is no octoprint package in the Raspbian repositories. It is necessary to build the application from the source code. There are quite a few prerequisites that are fetched with two apt install commands.

pi@octoprint-pi:~ $ sudo apt install git libyaml-dev build-essential -y ... The following NEW packages will be installed: git git-man libcurl3-gnutls liberror-perl libyaml-0-2 libyaml-dev 0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded. Need to get 6,224 kB of archives. After this operation, 33.2 MB of additional disk space will be used. ... pi@octoprint-pi:~ $ sudo apt install python3-dev python3-venv python3-pip -y Reading package lists... Done ... The following NEW packages will be installed: dh-python gir1.2-glib-2.0 libexpat1-dev libgirepository-1.0-1 libpython3-dev libpython3.7-dev python-pip-whl python3-asn1crypto python3-cffi-backend python3-crypto python3-cryptography python3-dbus python3-dev python3-distutils python3-entrypoints python3-gi python3-keyring python3-keyrings.alt python3-lib2to3 python3-pip python3-secretstorage python3-setuptools python3-venv python3-wheel python3-xdg python3.7-dev python3.7-venv 0 upgraded, 27 newly installed, 0 to remove and 0 not upgraded. Need to get 51.4 MB of archives. After this operation, 84.3 MB of additional disk space will be used. ...

Check that python3 and pip3 are installed correctly.

pi@octoprint-pi:~ $ python3 -V Python 3.7.3 pi@octoprint-pi:~ $ pip3 -V pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)

The package will be run from a Python 3 virtual environment which ensures that none of the numerous Python modules used will be disturbed by any subsequent addition of Python packages. There is more than one way of creating Python 3 virtual environments, I will follow my own instructions in Python 3 virtual environments and, more recently, Working Directories that remain for the most part valid.

pi@octoprint-pi:~ $ mkdir -p .local/bin pi@octoprint-pi:~ $ wget http://sigmdel.ca/michel/program/python/dnld/mkvenv.ubuntu -O .local/bin/mkvenv ... 2021-02-15 18:25:25 (24.8 MB/s) - ‘.local/bin/mkvenv’ saved [899/899] rock@rockpis:~$ chmod +x .local/bin/mkvenv rock@rockpis:~$ nano .bashrc ...

Here is a macro and an alias added to the bash configuration script to facilitate activating and deactivating virtual environments.

# Python3 virtual environment ve() { source $1/bin/activate; } alias ev='deactivate'

Normally, I would reboot or log out at this point to ensure that these changes take effec. Since user pi will be added to new groups in the next step, there is no need to do that now.

Install OctoPrint toc

The default user pi needs to be added to the tty group (although I haven't verified that this is strictly required). This addition will not take effect until the system is rebooted or until the user logs out and then logs back in.

pi@octoprint-pi:~ $ sudo adduser pi tty Adding user `pi' to group `tty' ... Adding user pi to group tty Done. pi@octoprint-pi:~ $ logout Connection to 192.168.1.29 closed. michel@hp:~$ ssh pi@192.168.1.29 pi@192.168.1.29's password: ******** Linux octoprint-pi 5.4.83-v7+ #1379 SMP Mon Dec 14 13:08:57 GMT 2020 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Mon Feb 15 18:33:54 2021 from 192.168.1.100 pi@octoprint-pi:~ $ groups pi adm tty dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi

Almost there, create a virtual environment and activate it and finally install the octoprint package with pip3 (renamed pip in the environment).

pi@octoprint-pi:~ $ mkvenv OctoPrint creating virtual environment /home/pi/OctoPrint updating virtual environment /home/pi/OctoPrint pi@octoprint-pi:~ $ ve OctoPrint (OctoPrint) pi@octoprint-pi:~ $ cd OctoPrint (OctoPrint) pi@octoprint-pi:~/OctoPrint $ pip install octoprint Collecting octoprint ... Successfully installed Babel-2.9.0 Click-7.1.2 Flask-Assets-2.0 Flask-Babel-1.0.0 ...

The number of Python packages installed in the process is pretty big. And while the procedure took a considerable amount of time, it completed without any problem.

Basically OctoPrint is a service that runs in the background. For a first test, the service will be started manually. Note that we are still in the OctoPrint virtual environment.

(OctoPrint) pi@octoprint-pi:~/OctoPrint $ octoprint serve 2021-02-15 18:48:35,638 - octoprint.startup - INFO - ****************************************************************************** 2021-02-15 18:48:35,640 - octoprint.startup - INFO - Starting OctoPrint 1.5.3 2021-02-15 18:48:35,641 - octoprint.startup - INFO - ****************************************************************************** 2021-02-15 18:48:35,651 - octoprint.util.connectivity.connectivity_checker - INFO - Connectivity state is currently: online 2021-02-15 18:48:35,652 - octoprint.util.connectivity.connectivity_checker - INFO - Connecting to 8.8.8.8:53 is working 2021-02-15 18:48:35,652 - octoprint.util.connectivity.connectivity_checker - INFO - Resolving octoprint.org is working 2021-02-15 18:48:35,708 - octoprint.plugin.core - INFO - Loading plugins from /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins, /home/pi/.octoprint/plugins and installed plugin packages... 2021-02-15 18:48:37,155 - octoprint.startup - INFO - Added settings overlay from plugin firmware_check 2021-02-15 18:48:37,157 - octoprint.plugin.core - INFO - Found 17 plugin(s) providing 17 mixin implementations, 34 hook handlers 2021-02-15 18:48:37,237 - octoprint.server.heartbeat - INFO - Starting server heartbeat, 900.0s interval 2021-02-15 18:48:37,269 - octoprint.server - INFO - Intermediary server started 2021-02-15 18:48:37,271 - octoprint.printer.profile - ERROR - Profile _default does not exist, creating _default again and setting it as default 2021-02-15 18:48:37,375 - octoprint.filemanager.storage - INFO - Initializing the file metadata for /home/pi/.octoprint/uploads... 2021-02-15 18:48:37,377 - octoprint.filemanager.storage - INFO - ... file metadata for /home/pi/.octoprint/uploads initialized successfully. 2021-02-15 18:48:37,380 - octoprint.server - INFO - Added new permission from plugin action_command_notification: PLUGIN_ACTION_COMMAND_NOTIFICATION_SHOW (needs: "Need(method='role', value='plugin_action_command_notification_show')") 2021-02-15 18:48:37,381 - octoprint.server - INFO - Added new permission from plugin action_command_notification: PLUGIN_ACTION_COMMAND_NOTIFICATION_CLEAR (needs: "Need(method='role', value='plugin_action_command_notification_clear')") 2021-02-15 18:48:37,382 - octoprint.server - INFO - Added new permission from plugin action_command_prompt: PLUGIN_ACTION_COMMAND_PROMPT_INTERACT (needs: "Need(method='role', value='plugin_action_command_prompt_interact')") 2021-02-15 18:48:37,382 - octoprint.server - INFO - Added new permission from plugin announcements: PLUGIN_ANNOUNCEMENTS_READ (needs: "Need(method='role', value='plugin_announcements_read')") 2021-02-15 18:48:37,383 - octoprint.server - INFO - Added new permission from plugin announcements: PLUGIN_ANNOUNCEMENTS_MANAGE (needs: "Need(method='role', value='plugin_announcements_read'), Need(method='role', value='plugin_announcements_manage')") 2021-02-15 18:48:37,383 - octoprint.server - INFO - Added new permission from plugin appkeys: PLUGIN_APPKEYS_ADMIN (needs: "Need(method='role', value='plugin_appkeys_admin')") 2021-02-15 18:48:37,384 - octoprint.server - INFO - Added new permission from plugin backup: PLUGIN_BACKUP_ACCESS (needs: "Need(method='role', value='plugin_backup_access')") 2021-02-15 18:48:37,384 - octoprint.server - INFO - Added new permission from plugin firmware_check: PLUGIN_FIRMWARE_CHECK_DISPLAY (needs: "Need(method='role', value='plugin_firmware_check_display')") 2021-02-15 18:48:37,385 - octoprint.server - INFO - Added new permission from plugin logging: PLUGIN_LOGGING_MANAGE (needs: "Need(method='role', value='plugin_logging_manage')") 2021-02-15 18:48:37,386 - octoprint.server - INFO - Added new permission from plugin pi_support: PLUGIN_PI_SUPPORT_STATUS (needs: "Need(method='role', value='plugin_pi_support_check')") 2021-02-15 18:48:37,388 - octoprint.server - INFO - Added new permission from plugin pluginmanager: PLUGIN_PLUGINMANAGER_MANAGE (needs: "Need(method='role', value='plugin_pluginmanager_manage')") 2021-02-15 18:48:37,389 - octoprint.server - INFO - Added new permission from plugin pluginmanager: PLUGIN_PLUGINMANAGER_INSTALL (needs: "Need(method='role', value='plugin_pluginmanager_install'), Need(method='role', value='plugin_pluginmanager_manage')") 2021-02-15 18:48:37,391 - octoprint.server - INFO - Added new permission from plugin softwareupdate: PLUGIN_SOFTWAREUPDATE_CHECK (needs: "Need(method='role', value='plugin_softwareupdate_check')") 2021-02-15 18:48:37,393 - octoprint.server - INFO - Added new permission from plugin softwareupdate: PLUGIN_SOFTWAREUPDATE_UPDATE (needs: "Need(method='role', value='plugin_softwareupdate_update')") 2021-02-15 18:48:37,394 - octoprint.server - INFO - Added new permission from plugin softwareupdate: PLUGIN_SOFTWAREUPDATE_CONFIGURE (needs: "Need(method='role', value='plugin_softwareupdate_configure')") 2021-02-15 18:48:38,456 - octoprint.util.pip - INFO - Using "/home/pi/OctoPrint/bin/python3 -m pip" as command to invoke pip 2021-02-15 18:48:39,399 - octoprint.util.pip - INFO - Version of pip is 21.0.1 2021-02-15 18:48:39,401 - octoprint.util.pip - INFO - pip installs to /home/pi/OctoPrint/lib/python3.7/site-packages (writable -> yes), --user flag needed -> no, virtual env -> yes 2021-02-15 18:48:39,401 - octoprint.util.pip - INFO - ==> pip ok -> yes 2021-02-15 18:48:39,493 - octoprint.plugin.core - INFO - Initialized 17 plugin implementation(s) 2021-02-15 18:48:39,724 - octoprint.plugin.core - INFO - 17 plugin(s) registered with the system: | Action Command Notification Support (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins/action_command_notification | Action Command Prompt Support (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins/action_command_prompt | Announcement Plugin (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins/announcements | Anonymous Usage Tracking (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins/tracking | Application Keys Plugin (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins/appkeys | Backup & Restore (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins/backup | Core Wizard (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins/corewizard | Discovery (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins/discovery | Error Tracking (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins/errortracking | File Check (2020.8.7) (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint_file_check | Firmware Check (2021.2.4) (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint_firmware_check | GCode Viewer (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins/gcodeviewer | Logging (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins/logging | Pi Support Plugin (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins/pi_support | Plugin Manager (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins/pluginmanager | Software Update (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins/softwareupdate | Virtual Printer (bundled) = /home/pi/OctoPrint/lib/python3.7/site-packages/octoprint/plugins/virtual_printer Prefix legend: ! = disabled, # = blacklisted, * = incompatible 2021-02-15 18:48:39,770 - octoprint.environment - INFO - Detected environment is Python 3.7.3 under Linux (linux). Details: | hardware: | cores: 4 | freq: 1200.0 | ram: 905310208 | os: | bits: 32 | id: linux | platform: linux | plugins: | pi_support: | model: Raspberry Pi 3 Model B Rev 1.2 | throttle_state: '0x0' | python: | pip: 21.0.1 | version: 3.7.3 | virtualenv: /home/pi/OctoPrint 2021-02-15 18:48:39,784 - octoprint.server - INFO - Reset webasset folder /home/pi/.octoprint/generated/webassets... 2021-02-15 18:48:39,785 - octoprint.server - INFO - Reset webasset folder /home/pi/.octoprint/generated/.webassets-cache... 2021-02-15 18:48:41,185 - octoprint.server - INFO - Shutting down intermediary server... 2021-02-15 18:48:41,284 - octoprint.server - INFO - Intermediary server shut down 2021-02-15 18:48:41,286 - octoprint.events - INFO - Processing startup event, this is our first event 2021-02-15 18:48:41,287 - octoprint.events - INFO - Adding 1 events to queue that were held back before startup event 2021-02-15 18:48:41,292 - octoprint.filemanager - INFO - Adding backlog items from all storage types to analysis queue... 2021-02-15 18:48:41,297 - octoprint.server.util.watchdog - INFO - Running initial scan on watched folder... 2021-02-15 18:48:41,301 - octoprint.filemanager - INFO - Added 0 items from storage type "local" to analysis queue 2021-02-15 18:48:41,303 - octoprint.server.util.watchdog - INFO - ... initial scan done. 2021-02-15 18:48:42,131 - octoprint.plugins.discovery - INFO - Registered 'OctoPrint instance on octoprint-pi._http._tcp.local.' for _http._tcp.local. 2021-02-15 18:48:43,007 - octoprint.plugins.discovery - INFO - Registered 'OctoPrint instance on octoprint-pi._octoprint._tcp.local.' for _octoprint._tcp.local. 2021-02-15 18:48:43,031 - octoprint.plugins.discovery - INFO - Registered OctoPrint instance on octoprint-pi for SSDP 2021-02-15 18:48:43,063 - octoprint.server - INFO - Listening on http://0.0.0.0:5000 and http://:5000 2021-02-15 18:48:43,666 - octoprint.plugins.announcements - INFO - Loaded channel _important from https://octoprint.org/feeds/important.xml in 0.58s 2021-02-15 18:48:44,110 - octoprint.util.pip - INFO - Using "/home/pi/OctoPrint/bin/python3 -m pip" as command to invoke pip 2021-02-15 18:48:44,112 - octoprint.util.pip - INFO - pip installs to /home/pi/OctoPrint/lib/python3.7/site-packages (writable -> yes), --user flag needed -> no, virtual env -> yes 2021-02-15 18:48:44,112 - octoprint.util.pip - INFO - ==> pip ok -> yes 2021-02-15 18:48:44,120 - octoprint.plugins.softwareupdate - INFO - Minimum free storage across all update relevant locations is 12.3GB. That is considered sufficient for updating. 2021-02-15 18:48:44,120 - octoprint.plugins.softwareupdate - INFO - Fetching check overlays from https://plugins.octoprint.org/update_check_overlay.json 2021-02-15 18:48:44,176 - octoprint.plugins.pluginmanager - INFO - Loaded plugin repository data from https://plugins.octoprint.org/plugins.json 2021-02-15 18:48:44,337 - octoprint.plugins.announcements - INFO - Loaded channel _releases from https://octoprint.org/feeds/releases.xml in 0.57s 2021-02-15 18:48:45,118 - octoprint.plugins.announcements - INFO - Loaded channel _blog from https://octoprint.org/feeds/octoblog.xml in 0.63s 2021-02-15 18:48:46,141 - octoprint.plugins.announcements - INFO - Loaded channel _plugins from https://plugins.octoprint.org/feed.xml in 0.88s 2021-02-15 18:48:46,501 - octoprint.util.pip - INFO - Using "/home/pi/OctoPrint/bin/python3 -m pip" as command to invoke pip 2021-02-15 18:48:46,507 - octoprint.util.pip - INFO - pip installs to /home/pi/OctoPrint/lib/python3.7/site-packages (writable -> yes), --user flag needed -> no, virtual env -> yes 2021-02-15 18:48:46,507 - octoprint.util.pip - INFO - ==> pip ok -> yes 2021-02-15 18:48:46,697 - octoprint.plugins.softwareupdate - INFO - Saved version cache to disk 2021-02-15 18:48:47,238 - octoprint.plugins.pluginmanager - INFO - Loaded plugin notices data from https://plugins.octoprint.org/notices.json 2021-02-15 18:48:47,827 - octoprint.plugins.announcements - INFO - Loaded channel _octopi from https://octoprint.org/feeds/octopi.xml in 0.56s 2021-02-15 18:50:59,001 - octoprint.server.util.flask.PreemptiveCache - INFO - Adding entry for / and {'path': '/', 'base_url': 'http://192.168.1.29:5000/', 'query_string': 'l10n=en', '_timestamp': 1613429459.0009646, '_count': 1} 2021-02-15 18:51:22,619 - octoprint.server.util.sockjs - INFO - New connection from client: 192.168.1.100 2021-02-15 18:51:23,683 - tornado.access - WARNING - 403 GET /api/printerprofiles/_default (192.168.1.100) 12.07ms

Those last two messages were shown as I opened the OctoPrint Web page. That's simple enough to do: just use the following URL 192.168.1.29:5000 (using the proper for the static address of course) or octoprint-pi.local:5000 if your desktop system and web browser support local domain names.

As can be seen, that initial start of OctoPrint starts with a setup wizard. That subject will be examined later. For the time being, just close the web page, stop octoprint on the Pi with the CtrlC keyboard combination and de-activate the virtual environment.

^C 2021-02-15 18:52:12,034 - octoprint.server - INFO - Shutting down... 2021-02-15 18:52:12,455 - octoprint.server - INFO - Calling on_shutdown on plugins 2021-02-15 18:52:12,459 - octoprint.events - INFO - Processing shutdown event, this will be our last event 2021-02-15 18:52:12,462 - octoprint.events - INFO - Event loop shut down 2021-02-15 18:52:13,003 - octoprint.server - INFO - Goodbye! (OctoPrint) pi@octoprint-pi:~/OctoPrint $ ev pi@octoprint-pi:~/OctoPrint $ cd ..

Install MJPG-Streamer toc

First let's test that the Raspberry Pi camera module is working by taking a snapshot. Of course, the module has to be connected with the Pi as explained above. Be careful, I understand the module can be damaged with static electricity, so power off the Pi before connecting the module and make sure everything is grounded to avoid sparks.

pi@octoprint-pi:~ $ which raspistill /usr/bin/raspistill pi@octoprint-pi:~ $ raspistill -o image.jpg total 2256 -rw-r--r-- 1 pi pi 2300813 Feb 15 19:46 image.jpg ...

Looks like it's working, because a JPEG file was created. Time to install mjpg_streamer. Again, the package will be built from source code and there are prerequisites.

pi@octoprint-pi:~ $ sudo apt-get install cmake libjpeg8-dev -y ... upgraded, 8 newly installed, 0 to remove and 0 not upgraded. Need to get 4,914 kB of archives. After this operation, 23.2 MB of additional disk space will be used. ... pi@octoprint-pi:~ $ git clone https://github.com/jacksonliam/mjpg-streamer.git Cloning into 'mjpg-streamer'... remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Compressing objects: 100% (5/5), done. remote: Total 2958 (delta 0), reused 1 (delta 0), pack-reused 2953 Receiving objects: 100% (2958/2958), 3.48 MiB | 3.99 MiB/s, done. Resolving deltas: 100% (1878/1878), done. pi@octoprint-pi:~ $ cd mjpg-streamer/mjpg-streamer-experimental/ pi@octoprint-pi:~/mjpg-streamer/mjpg-streamer-experimental $ make [ -d _build ] || mkdir _build ... pi@octoprint-pi:~/mjpg-streamer/mjpg-streamer-experimental $ sudo make install make -C _build install ... make[1]: Leaving directory '/home/pi/mjpg-streamer/mjpg-streamer-experimental/_build'

Let's locate the executable and its input and output libraries.

pi@octoprint-pi:~/mjpg-streamer/mjpg-streamer-experimental $ cd ~ pi@octoprint-pi:~ $ which mjpg_streamer /usr/local/bin/mjpg_streamer pi@octoprint-pi:~ $ ls /usr/local/lib/mjpg-streamer input_file.so input_raspicam.so output_file.so output_rtsp.so input_http.so input_uvc.so output_http.so output_udp.so

We are now in a position to test the video streaming service with default values.

pi@octoprint-pi:~ $ mjpg_streamer -o "output_http.so" -i "input_raspicam.so" MJPG Streamer Version: git rev: 5554f42c352ecfa7edaec6fc51e507afce605a34 i: fps.............: 5 i: resolution........: 640 x 480 i: camera parameters..............: Sharpness 0, Contrast 0, Brightness 50 Saturation 0, ISO 0, Video Stabilisation No, Exposure compensation 0 Exposure Mode 'auto', AWB Mode 'auto', Image Effect 'none' Metering Mode 'average', Colour Effect Enabled No with U = 128, V = 128 Rotation 0, hflip No, vflip No ROI x 0.000000, y 0.000000, w 1.000000 h 1.000000 o: www-folder-path......: disabled o: HTTP TCP port........: 8080 o: HTTP Listen Address..: (null) o: username:password....: disabled o: commands.............: enabled i: Starting Camera Encoder Buffer Size 81920

A 5 frames/second 640x480 pixels stream is not exactly earth-shattering but it's good enough for a test. The video stream can be seen on a web browser running on a computer connected to the same local network using the following URL http://192.168.1.29:8080/?action=stream. On my Linux desktop, the following URL also works http://octoprint-pi.local:8080/?action=stream. Changing the action from stream to snapshot will result in a single image being displayed. These two links are all that is used by OctoPrint for its visual real time monitoring and time-lapse photography. Note that these are not secure connections. A user name and password can be required but the connection will still use the plain text HTTP protocol without encoding.

What if a WebCam is used instead of a Raspberry Pi camera module? It is just as simple; just use a different input module.

pi@octoprint-pi:~ $ mjpg_streamer -o "output_http.so" -i "input_uvc.so" MJPG Streamer Version: git rev: 5554f42c352ecfa7edaec6fc51e507afce605a34 i: Using V4L2 device.: /dev/video0 i: Desired Resolution: 640 x 480 i: Frames Per Second.: -1 i: Format............: JPEG i: TV-Norm...........: DEFAULT UVCIOC_CTRL_ADD - Error at Pan (relative): Inappropriate ioctl for device (25) UVCIOC_CTRL_ADD - Error at Tilt (relative): Inappropriate ioctl for device (25) UVCIOC_CTRL_ADD - Error at Pan Reset: Inappropriate ioctl for device (25) UVCIOC_CTRL_ADD - Error at Tilt Reset: Inappropriate ioctl for device (25) UVCIOC_CTRL_ADD - Error at Pan/tilt Reset: Inappropriate ioctl for device (25) UVCIOC_CTRL_ADD - Error at Focus (absolute): Inappropriate ioctl for device (25) UVCIOC_CTRL_MAP - Error at Pan (relative): Inappropriate ioctl for device (25) UVCIOC_CTRL_MAP - Error at Tilt (relative): Inappropriate ioctl for device (25) UVCIOC_CTRL_MAP - Error at Pan Reset: Inappropriate ioctl for device (25) UVCIOC_CTRL_MAP - Error at Tilt Reset: Inappropriate ioctl for device (25) UVCIOC_CTRL_MAP - Error at Pan/tilt Reset: Inappropriate ioctl for device (25) UVCIOC_CTRL_MAP - Error at Focus (absolute): Inappropriate ioctl for device (25) UVCIOC_CTRL_MAP - Error at LED1 Mode: Inappropriate ioctl for device (25) UVCIOC_CTRL_MAP - Error at LED1 Frequency: Inappropriate ioctl for device (25) UVCIOC_CTRL_MAP - Error at Disable video processing: Inappropriate ioctl for device (25) UVCIOC_CTRL_MAP - Error at Raw bits per pixel: Inappropriate ioctl for device (25) o: www-folder-path......: disabled o: HTTP TCP port........: 8080 o: HTTP Listen Address..: (null) o: username:password....: disabled o: commands.............: enabled

Despite all the error messages that have to do with non-existent capabilities of my old WebCam, the video stream can be seen on a web browser at the same URLs mentioned above: http://192.168.1.29:8080/?action=stream or http://octoprint-pi.local:8080/?action=stream.

While mjpg_streamer produces images, octoprint needs another rather big package, ffmpeg, to stitch together the images into a time-lapse video. This is easily added. Check where the package is installed because that path must be added to the octoprint settings later.

pi@octoprint-pi:~ $ sudo apt install ffmpeg -y Reading package lists... Done ... 0 upgraded, 149 newly installed, 0 to remove and 0 not upgraded. Need to get 69.3 MB of archives. After this operation, 714 MB of additional disk space will be used. ... very long rocessing triggers for libgdk-pixbuf2.0-0:armhf (2.38.1+dfsg-1) ... pi@octoprint-pi:~ $ which ffmpeg /usr/bin/ffmpeg

The usual CtrlC keyboard combination stops the daemon.

.. o: HTTP TCP port........: 8080 o: HTTP Listen Address..: (null) o: username:password....: disabled o: commands.............: enabled CtrlC ^Csetting signal to stop i: cleaning up resources allocated by input thread force cancellation of threads and cleanup resources o: cleaning up resources allocated by server thread #00 done

Octoprint Configuration toc

Time to configure and minimally test OctoPrint. To do this properly connect the Pi to the 3D printer with the appropriate USB cable. There have been reports of "back powering" issues. Should the Pi be connected to a printer that is not powered up, its controller board may try to obtain power from the Pi. This is a bit strange because the 5 V USB bin should not be tied to the controller Vcc. But apparently it is. My printer is not on listed in Printers known to have back powering issues, but I nevertheless followed the advice in Put tape on the 5 V pin - Why and how. Once this safeguard is in place here is what needs to be done.

  1. Connect the camera module to the Pi
  2. Connect the Pi to the 3D printer
  3. Start the Raspberry Pi
  4. Start the printer
  5. Open an SSH session with the Pi from the desktop and start mjpg-streamer on the Pi:
    pi@octoprint-pi:~ $ mjpg_streamer -o "output_http.so" -i "input_raspicam.so"
  6. Open a second SSH sessions, activate the virtual environment and start octoprint on the Pi:
    pi@octoprint-pi:~ $ ve OctoPrint pi@octoprint-pi:~ $ octoprint serve
  7. Connect to the OctoPrint Web interface at URL: 192.168.1.29:5000 with a web browser

The start page of the Setup Wizard should be displayed again.

Click on the Next button to start the basic configuration of OctoPrint. If for some reason, the wizard is not visible then clicking on the wrench icon (the hint Settings pops up when the mouse pointer hovers over the icon), will bring up the complete OctoPrint Settings menu which contains many settings pages including those displayed by the wizard when the program is first used.

Since I had never used OctoPrint before, the next step which allows for restoring the program settings from a backup was of no use to me.

But seeing this means that it is a good idea to save the settings in order to simplify future installations of OctoPrint. Pressing the Next button brings up the following mandatory step:

Don't forget the user name and password as these will be required from now on whenever logging into the OctoPrint web interface. Once those values have been entered, click on the Create Account and then the Next buttons.

Click on the Enable... or the Disable Anonymous Usage Tracking button according to your preference and then move on to the Next step.

The Next setting is about protecting the OctoPrint instance from undesirable third party plugins.

That seemed like a good idea so I enabled the blacklist processing and moved on to the Next set of settings that have to do with the 3D printer.

The settings in the General tab identify the default profile printer. I left the _default Identifier value and changed the Name and Model to reasonable values given the only 3D printer that will be used for at least the next few months.

In the second tab, Print bed & build volume, I unchecked Heated Bed and modified the print volume. I didn't change anything in the Axes and the Hotend & extruder tabs.

I entered the suggested server commands that should work for all instances of OctoPrint running on Debian based Linux distributions such as Raspberry Pi OS.

The last setup wizard settings page is used to configure the webcam and time-lapse recording. I set the following three values:

    Stream URL        http://192.168.1.29:8080/?action=stream
    Snapshot URL      http://192.168.1.29:8080/?action=Snapshot
    Path to FFMPGE    /usr/bin/ffmpeg 

These values will need to be adapted for each particular installation. And that's about it for the setup wizard. The next page merely confirms that the process is finished.

At this point, I suggest closing the web interface and opening it again. It will be necessary to log in with the user name and password according to the Access Control settings.

Once the correct credentials are entered, the web interface will be displayed.

The window is divided into four main parts. There is a title bar across the top containing 3 icons for settings, announcements and the user account. Below that bar, there are three panels. The left panel is where the user will perform tasks such as connecting to the printer, upload files to it, start prints and so on. The middle panel is used to monitor the printer's temperature, view the video stream if a camera has been connected, view the GCode, and so on. The right-hand panel contains information about the availability of OctoPrint updates and new plugins.

On my simple system, establishing the serial connection over USB is as easy as clicking on the Connect button in Connection section of the left panel. Even if neither the Serial Port nor the Baudrate is specified (they are both set to AUTO), octoprint has no problem finding the 3D printer.

As soon as the serial connection is established, the printer sends the temperature of the nozzle which is plotted on the graph. Clicking on the Terminal tab will show the temperature reports as they come in every two seconds or so. Check the Suppress temperature messages and it will be easier to see the information octoprint obtained from the printer. Here is a line that seemed important.

Recv: FIRMWARE_NAME:Marlin V0.0.4 (Github) SOURCE_CODE_URL:https://github.com/MarlinFirmware/Marlin PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mega Zero EXTRUDER_COUNT:1

Clearly, the printer firmware, the ubiquitous Marlin, is rather old. There are newer versions available for the Mega Zero, but that's beyond the scope of this discussion. In the central panel Control tab sheet, there were buttons that made it possible to move the nozzle along the three axes. Because I had not modified the nozzle temperature (which can be in the Temperature tab sheet), I did not test extruding or retracting the filament. I did try to turn the fan off but that produced no effect. I checked in the terminal and saw that the correct GCode was sent to the printer:

Send: M106 S0 Recv: ok ...

It responded with an OK but the fan remained on. I was not too surprised by that; the printer menu choice to turn off the fan does not work. Something to look into. I then moved on to Control tab in the Web interface.

If a black border appears around the images, the correct stream aspect ratio may be specified in the OctoPrint Webcam & Timelapse Settings as shown below.

That particular page is reached by clicking on the spanner icon at the top of the Web page and then selecting the Webcam & Timelapse in the list on the left. Note that the image can be rotated if needed in the same page. Do not forget to clik on the Save button at the bottom of the page.

If there is something wrong, the following will be displayed.

The instructions on the screen provide a good starting point to find the error:

  1. Is mjpg_streamer running? Try
  2. pi@octoprint-pi:~ $ pidof mjpg_streamer 1184
    If no pid number is shown, then the daemon is not running.
  3. If the streamer is running then perhaps the wrong input module specified. Use input_raspicam.so for the Raspberry Pi Camera Module and input_uvc.so for a webcam.
  4. Check the URL.

Enabling the Services toc

It is very practical if both OctoPrint and MJPG-Streamer are started automatically when the Raspberry Pi is booted. Here is the suggested systemd service file for octoprint.

[Unit] Description=The snappy web interface for your 3D printer After=network-online.target Wants=network-online.target [Service] Environment="LC_ALL=C.UTF-8" Environment="LANG=C.UTF-8" Type=simple User=pi ExecStart=/home/pi/OctoPrint/venv/bin/octoprint [Install] WantedBy=multi-user.target

It is easily downloaded and modified to run in the virtual Python environment that we created in a different directory.

pi@octoprint-pi:~ $ wget https://github.com/OctoPrint/OctoPrint/raw/master/scripts/octoprint.service pi@octoprint-pi:~ $ nano octoprint.service -B

The last command launches my favourite editor do modify the ExecStart command must correspond to the location of the executable.

ExecStart=/home/pi/OctoPrint/bin/octoprint

After that change, the service file has to be moved to the correct directory and the service has to be enabled.

pi@octoprint-pi:~ $ sudo mv octoprint.service /etc/systemd/system/octoprint.service pi@octoprint-pi:~ $ sudo systemctl enable octoprint.service Created symlink /etc/systemd/system/multi-user.target.wants/octoprint.service → /etc/systemd/system/octoprint.service.

From now on, octoprint will be started automatically when the Pi is booted. As far as the video streamer, I will admit to being lazy. I tried creating a service file without success, so I basically recycled a startup bash script from a previous installation of the video streamer: Secure Webcam streaming with MJPG-Streamer on a Raspberry Pi, 5. A New Script. Here it is.

#!/bin/bash # adjust these : if [ -e "/dev/video0" ]; then INPUT_PLUGIN="input_uvc.so"; #DEVICE="-d /dev/video0"; #FRAMES="-f 10"; #RESOLUTION="-r 1280x720"; else INPUT_PLUGIN= "input_raspicam.so"; #FRAMES="-f 10"; #RESOLUTION="-r 1280x720"; fi OUTPUT_PLUGIN="output_http.so"; #PORT="-p 8085"; #CREDENTIALS="-c user_name:user_password" # the following are defaults and should not need to be changed EXEC="/usr/local/bin/mjpg_streamer" WEB_DIR="-w /usr/local/share/mjpg-streamer/www" LIB_DIR="/usr/local/lib/mjpg-streamer/" # mjgp_streamer often does not start on first try. Why ? start_streamer(){ for i in {1..5} # try up to 5 times do # echo ${EXEC} -b -i "${LIB_DIR}${INPUT_PLUGIN} -n ${DEVICE} ${FRAMES} ${RESOLUTION}" -o "${LIB_DIR}${OUTPUT_PLUGIN} ${PORT} ${WEB_DIR} ${CREDENTIALS}" ${EXEC} -b -i "${LIB_DIR}${INPUT_PLUGIN} -n ${DEVICE} ${FRAMES} ${RESOLUTION}" -o "${LIB_DIR}${OUTPUT_PLUGIN} ${PORT} ${WEB_DIR} ${CREDENTIALS}" > /dev/null 2>&1 sleep $((1+i)) # waiting progressively longer if pgrep mjpg_streamer > /dev/null then echo "mjpg_streamer started" return fi done echo "could not start mjpg_streamer" } # Carry out specific functions when asked to by the system case "$1" in start) if pgrep mjpg_streamer > /dev/null then echo "mjpg_streamer already running" else start_streamer fi ;; stop) if pgrep mjpg_streamer > /dev/null then killall mjpg_streamer echo "mjpg_streamer stopped" else echo "mjpg_streamer is not running" fi ;; restart) if pgrep mjpg_streamer > /dev/null then killall mjpg_streamer echo "mjpg_streamer stopped" else echo "mjpg_streamer is not running" fi start_streamer ;; status) pid=`ps -A | grep mjpg_streamer | grep -v "grep" | grep -v mjpg_streamer. | awk '{print $1}' | head -n 1` if [ -n "$pid" ]; then echo "mjpg_streamer is running with pid ${pid}" echo "mjpg_streamer was started with the following command line" cat /proc/${pid}/cmdline ; echo "" else echo "mjpg_streamer is not running" fi ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 ;; esac exit 0

The old script was modified so that it would work with a Webcam or the Raspberry Pi camera module. It is not a very sophisticated script and it will "find" the webcam only if it is connected to the Pi when the latter is booted. If a webcam is not found, then it is assumed that a camera module is connected without checking. As shown, the camera will be started in default mode. The script can be edited to set the frame rate and resolution

pi@octoprint-pi:~ $ mkdir scripts pi@octoprint-pi:~ $ wget https://sigmdel.ca/michel/ha/rpi/dnld/webcam_script -O scripts/webcam ... pi@octoprint-pi:~ $ chmod +x scripts/webcam pi@octoprint-pi:~ $ sudo nano /etc/rc.local

Again, the nano editor is invoked to add a line to start the camera in the local run-control script just before it exits as shown below.

... /home/pi/scripts/webcam start exit 0

I gather that using the rc.local script is considered rather bad form with systemd. However, it will have to do until I figure out how to get a proper service file working, if I even bother.

Previously, I would have placed the webcam script in a directory such as ~/.local/bin which is in the search path. It is in the specially created ~./scripts directory just in case it could be preferable to add the ability to start and stop the video feed from within OctopPrint. If that is what is desired, then see section Optional: Webcam in Setting up OctoPrint on a Raspberry Pi running Raspbian or Raspberry Pi OS.

Next toc

Very shortly, I should be able to put up a post on installing OctopPrint on the very small and reasonably priced Rock Pi S. I am just waiting for the arrival of a USB-C male to Type-A female adapter to finalize things. If I were impatient, I could go to a local retail outlet to get such a adapter but prices are exorbitant often twice as much as what I paid for the Rock Pi!

Then I will write about 3D printing from a personal point of view: that of an digital electronics enthusiast with absolutely no experience with 3D printer and no interest in printing bobbles, sci-fi paraphernalia, toys and so on. I was not certain that I could justify getting into 3D printing when looking at the cost involved and the time that would need to be invested to learn. However, the cost for American readers of the ANYCUBIC Mega Zero is currently amazingly low. Be aware that the current price of $119 will not last, as version 1 of the printer, no longer available in Canada, has been replaced with version 2. As for the time investment, well learning is the whole idea. I'll just postpone learning to layout PCB for a while. Check out the review on Ben Heck Hacks to see how easily the printer is assembled. It was that video that prompted me to purchase the printer. Since I am a total neophyte, I would recommend that you check out other reviews easily on the Web before proceeding.