User Tools

Site Tools


bdev:octoprint_setup

Warning: Undefined array key 13 in /var/www/html/dokuwiki/inc/html.php on line 1453

Warning: Undefined array key -1 in /var/www/html/dokuwiki/inc/html.php on line 1458

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
bdev:octoprint_setup [2021/09/28 15:47]
richard created
bdev:octoprint_setup [2021/10/28 15:25] (current)
richard
Line 1: Line 1:
 ====== Octoprint ====== ====== Octoprint ======
 +
 +
 +\\
 +
 +
 +The problem with installing manually is if you want to use the Arducam motorized focus camera. 
 +
  
 **Installing manually** **Installing manually**
Line 7: Line 14:
   - Creating a virtual environment somewhere: python -m venv OctoPrint   - Creating a virtual environment somewhere: python -m venv OctoPrint
   - Installing OctoPrint into that virtual environment: OctoPrint/bin/pip install OctoPrint   - Installing OctoPrint into that virtual environment: OctoPrint/bin/pip install OctoPrint
-  - OctoPrint may then be started through ./OctoPrint/bin/octoprint serve or with an absolute path /path/to/OctoPrint/bin/octoprint serve+  - OctoPrint may then be started through //./OctoPrint/bin/octoprint serve// or with an absolute path ///path/to/OctoPrint/bin/octoprint serve// 
 + 
 +**This starts it up manually** \\ 
 + 
 +/path/to/OctoPrint/bin/octoprint serve 
 + 
 +https://community.octoprint.org/t/setting-up-octoprint-on-a-raspberry-pi-running-raspbian-or-raspberry-pi-os/2337 
 +\\ 
 + 
 +**Basic Installation**\\ 
 + 
 +<code> 
 +cd ~ 
 +sudo apt update 
 +sudo apt install python3-pip python3-dev python3-setuptools python3-venv git libyaml-dev build-essential 
 +mkdir OctoPrint && cd OctoPrint 
 +python3 -m venv venv 
 +source venv/bin/activate 
 +</code> 
 + 
 + 
 +OctoPrint and it's Python dependencies can then be installed using pip: \\ 
 + 
 + 
 +<code> 
 +pip install pip --upgrade 
 +pip install octoprint 
 + 
 +</code> 
 + 
 +**Note** 
 + 
 +<code> 
 +If this installs an old version of OctoPrint, pip probably still has something cached. In that case add --no-cache-dir to the install command, e.g. 
 + 
 +pip install --no-cache-dir octoprint 
 +To make this permanent, clean pip's cache: 
 + 
 +rm -r ~/.cache/pip 
 +</code> 
 + 
 +**Starting the server for the first time**\\ 
 + 
 +<code> 
 +pi@raspberrypi:~ $ ~/OctoPrint/venv/bin/octoprint serve 
 +2020-11-03 17:39:17,979 - octoprint.startup - INFO - *************************** 
 +2020-11-03 17:39:17,980 - octoprint.startup - INFO - Starting OctoPrint 1.4.2 
 +2020-11-03 17:39:17,980 - octoprint.startup - INFO - *************************** 
 +</code> 
 + 
 +**Automatic start up**\\ 
 + 
 +Download the init script files from OctoPrint's repository, move them to their respective folders and make the init script executable:\\ 
 + 
 +<code> 
 +wget https://github.com/OctoPrint/OctoPrint/raw/master/scripts/octoprint.service && sudo mv octoprint.service /etc/systemd/system/octoprint.service 
 +</code> 
 + 
 +Adjust the paths to your octoprint binary in /etc/systemd/system/octoprint.service. If you set it up in a virtualenv as described above make sure your\\ 
 +///etc/systemd/system/octoprint.service// looks like this: 
 +<code> 
 +ExecStart=/home/pi/OctoPrint/venv/bin/octoprint 
 +</code> 
 + 
 +Then add the script to autostart using //sudo systemctl enable octoprint.service//
 + 
 +This will also allow you to start/stop/restart the OctoPrint daemon via\\ 
 + 
 +<code> 
 +sudo service octoprint {start|stop|restart} 
 +</code> 
 +\\ 
 + 
 +**Make everything accessible on port 80** 
 + 
 +If you want to have nicer URLs or simply need OctoPrint to run on port 80 (http's default port) due to some network restrictions, I recommend using HAProxy 593 as a reverse proxy instead of configuring OctoPrint to run on port 80. This has the following advantages:\\ 
 +  * OctoPrint does not need to run with root privileges, which it would need to to be able to bind to port 80 thanks to Linux privileged port restrictions 
 +  * You can make mjpg-streamer accessible on port 80 as well 
 +  * You can add authentication to OctoPrint 
 +  * Depending on the HAProxy version you can also use SSL to access OctoPrint 
 + 
 +Setup on Raspbian is as follows: 
 +<code> 
 +pi@raspberrypi ~ $ sudo apt install haproxy 
 +</code> 
 +I'm using the following configuration in /etc/haproxy/haproxy.cfg, for further examples take a look at the post here 385:\\ 
 + 
 +<code> 
 +global 
 +        maxconn 4096 
 +        user haproxy 
 +        group haproxy 
 +        daemon 
 +        log 127.0.0.1 local0 debug 
 + 
 +defaults 
 +        log     global 
 +        mode    http 
 +        option  httplog 
 +        option  dontlognull 
 +        retries 3 
 +        option redispatch 
 +        option http-server-close 
 +        option forwardfor 
 +        maxconn 2000 
 +        timeout connect 5s 
 +        timeout client  15min 
 +        timeout server  15min 
 + 
 +frontend public 
 +        bind :::80 v4v6 
 +        use_backend webcam if { path_beg /webcam/ } 
 +        default_backend octoprint 
 + 
 +backend octoprint 
 +        reqrep ^([^\ :]*)\ /(.*)     \1\ /\2 
 +        option forwardfor 
 +        server octoprint1 127.0.0.1:5000 
 + 
 +backend webcam 
 +        reqrep ^([^\ :]*)\ /webcam/(.*)     \1\ /\2 
 +        server webcam1  127.0.0.1:8080 
 +</code> 
 + 
 + 
 + 
 +This will make OctoPrint accessible under http://<your Raspi's IP>/ and make mjpg-streamer accessible under http://<your Raspi's IP>/webcam/. You'll also need to modify /etc/default/haproxy and enable HAProxy by setting ENABLED to 1. After that you can start HAProxy by issuing the following command 
 +\\ 
 + 
 +<code> 
 +sudo service haproxy start 
 +</code> 
 + 
 +Pointing your browser to http://<your Raspi's IP> should greet you with OctoPrint's UI. Now open the settings and switch to the webcam tab or alternatively open ~/.octoprint/config.yaml. Set the webcam's stream URL from http://<your Raspi's IP>:8080/?action=stream to /webcam/?action=stream (leave the snapshotUrl at http://127.0.0.1:8080/?action=snapshot!) and reload the page. 
 + 
 +\\ 
 + 
 +If everything works you can add the following lines to ~/.octoprint/config.yaml (just create it if it doesn't exist yet) to make the server bind only to the loopback interface: 
 +\\ 
 +<code> 
 +server: 
 +    host: 127.0.0.1 
 +</code> 
 + 
 +Restart the server. OctoPrint should still be available on port 80, including the webcam feed (if enabled). 
 +\\ 
 +**Updating & changing release channels & rolling back** 
 +\\ 
 +OctoPrint should offer to update itself automatically and also allow you to switch to other Release Channels out of the box.\\ 
 +If for whatever reason you want or need to perform any of this manually however, perform the following commands to install <version> of OctoPrint\\ 
 +<code> 
 +source ~/OctoPrint/venv/bin/activate 
 +pip install octoprint==<version> 
 +</code> 
 + 
 +e.g. 
 + 
 +<code> 
 +source ~/OctoPrint/venv/bin/activate 
 +pip install octoprint==1.4.0 
 +</code> 
 +\\ 
 +**Support restart/shutdown through OctoPrint's system menu** 
 +\\ 
 + 
 +In the UI, under Settings > Commands, configure the following commands: 
 +  * Restart OctoPrint: //sudo service octoprint restart// 
 +  * Restart system: //sudo shutdown -r now// 
 +  * Shutdown system: //sudo shutdown -h now// 
 + 
 + 
 +**Optional: Webcam**\\ 
 +If you also want webcam and timelapse support, you'll need to download and compile MJPG-Streamer: 
 +\\ 
 +<code> 
 +cd ~ 
 +sudo apt install subversion libjpeg62-turbo-dev imagemagick ffmpeg libv4l-dev cmake 
 +git clone https://github.com/jacksonliam/mjpg-streamer.git 
 +cd mjpg-streamer/mjpg-streamer-experimental 
 +export LD_LIBRARY_PATH=. 
 +make 
 +</code> 
 + 
 +\\ 
 + 
 +<code> 
 +Heads-up 
 + 
 +The required packages depend on the underlying version of Debian! The above is what should work on the current Debian Stretch or Buster based images of Raspbian. 
 + 
 +For Jessie use: 
 + 
 +sudo apt install subversion libjpeg62-turbo-dev imagemagick libav-tools libv4l-dev cmake 
 +For Wheezy or older (you should update...) use: 
 + 
 +sudo apt install subversion libjpeg8-dev imagemagick libav-tools libv4l-dev cmake 
 +</code> 
 + 
 + 
 +This should hopefully run through without any compilation errors. You should then be able to start the webcam server using:\\ 
 + 
 +<code> 
 +./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so" 
 +</code> 
 + 
 +For some webcams (including the PS3 Eye) you'll need to force the YUV mode by using the following start command:\\ 
 +<code> 
 +./mjpg_streamer -i "./input_uvc.so -y" -o "./output_http.so"  
 +</code>
  
  
bdev/octoprint_setup.1632844068.txt.gz · Last modified: 2021/09/28 15:47 by richard