Skip to content

Instantly share code, notes, and snippets.

@poulou0
Last active June 26, 2023 14:25
Show Gist options
  • Save poulou0/6c26d925ae846e90cec03e0279245822 to your computer and use it in GitHub Desktop.
Save poulou0/6c26d925ae846e90cec03e0279245822 to your computer and use it in GitHub Desktop.
Octoprint (octopi) cheat sheet

Setup openvpn with .ovpn file

pi@octopi:~ $ sudo apt install openvpn
pi@octopi:~ $ sudo mv 11.pi3-octoprint.ovpn /etc/openvpn/11.pi3-octoprint.conf
pi@octopi:~ $ sudo systemctl restart openvpn

Setup wireguard with .conf file

pi@octopi:~ $ sudo apt install wireguard
pi@octopi:~ $ sudo mv pi3_OCTOPI.conf /etc/wireguard/wg0.conf
pi@octopi:~ $ sudo systemctl enable wg-quick@wg0
pi@octopi:~ $ sudo systemctl start wg-quick@wg0

For debugging (might need to install resolvconf)

pi@octopi:~ $ sudo wg-quick up wg0

Set a camera password

  • In /root/bin/webcamd. Carefull with the "-o" parameter quotes

         pushd $MJPGSTREAMER_HOME > /dev/null 2>&1
    -        echo Running ./mjpg_streamer -o "output_http.so -w $camera_http_webroot $camera_http_options" -i "$input"
    -        LD_LIBRARY_PATH=. ./mjpg_streamer -o "output_http.so -w $camera_http_webroot $camera_http_options" -i "$input" &
    +        echo Running ./mjpg_streamer -o "output_http.so -w $camera_http_webroot $camera_http_options -c username:password" -i "$input"
    +        LD_LIBRARY_PATH=. ./mjpg_streamer -o "output_http.so -w $camera_http_webroot $camera_http_options -c username:password" -i "$input" &
  • OctoPrint Settings > Webcam & Timelapse > Timelapse Recordings > Snapshot URL

    http://username:password@127.0.0.1:8080/?action=snapshot

    ..and Test it

  • Restart the service

    pi@octopi:~ $ sudo systemctl restart webcamd.service

Set a camera url token

  • In /etc/haproxy/haproxy.cfg. In the "backend webcam"

         backend webcam
    -        reqrep ^([^\ :]*)\ /webcam/(.*)     \1\ /\2
    +        reqrep ^([^\ :]*)\ /webcam/123456789/(.*)     \1\ /\2
  • Restart the service

    pi@octopi:~ $ sudo systemctl restart haproxy.service
  • OctoPrint Settings > Webcam & Timelapse > Stream > Stream URL

    /webcam/123456789/?action=stream

    ..and Test it

Set the camera to 50Hz

In the nano ~/.octoprint/config.yaml in the event hooks

events:
  enabled: true
  subscriptions:
  - event: Startup
    command: v4l2-ctl --set-ctrl=power_line_frequency=1
    type: system

https://unix.stackexchange.com/a/581939

https://community.octoprint.org/t/b/30389

Camera resolution

To check the supported resolutions

pi@octopi:~ $ v4l2-ctl -d /dev/video0 --list-formats-ext

Change it in octopi.txt

pi@octopi:~ $ sudo nano /boot/octopi.txt

Apply the change

pi@octopi:~ $ sudo systemctl restart webcamd.service

Turn USBs on/off

Clone and compile the amazing uhubctl https://github.com/mvp/uhubctl#compiling

Turn pi3 USBs off

pi@octopi:~ $ sudo uhubctl -l 1-1 -p 2 -a 0

Turn pi3 USBs on

pi@octopi:~ $ sudo uhubctl -l 1-1 -p 2 -a 1

Optionally, make it run without sudo https://github.com/mvp/uhubctl#linux-usb-permissions Tip: If not sure, execute the command with sudo and note down which vid:pid was controlled. In my raspi3b:

SUBSYSTEM=="usb", ATTR{idVendor}=="0424", MODE="0666"

Finally, control everything from the octoprint UI with System Command Editor (it's already in the octoprint repository/plugin manager) https://plugins.octoprint.org/plugins/systemcommandeditor/

Tip: For root commands, example: echo yoursudopassword | sudo -S systemctl restart webcamd.service

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment