Skip to content

DeAlexPesh/ubuntu-octoprint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Prepare Ubuntu 20 Server

sudo apt update && sudo apt -y dist-upgrade

sudo dpkg-reconfigure cloud-init // deselect all

sudo apt purge cloud-init && \
sudo rm -rf {/var/lib/cloud,/etc/cloud} && \
sudo systemctl disable iscsid.service open-iscsi.service && \
sudo apt remove open-iscsi && \
sudo systemctl show -p WantedBy network-online.target
sudo mv /etc/netplan/00-installer-config.yaml /etc/netplan/01-netcfg.yaml && \
sudo nano /etc/netplan/01-netcfg.yaml && \
sudo netplan apply

network:
  version: 2
  ethernets:
    enp0s3:
#     optional: true
      dhcp4: true
      dhcp-identifier: mac
sudo nano /etc/netplan/00-installer-config-wifi.yaml && \
sudo netplan apply

network:
  version: 2
  wifis:
    wlan0:
#     optional: true
      access-points:
        SSID:
          password: "PASS"
      dhcp4: true
      dhcp-identifier: mac
# if need disabled IPv6
sudo nano /etc/default/grub && sudo update-grub
GRUB_CMDLINE_LINUX_DEFAULT="... ipv6.disable=1"
sudo apt install auditd glances bpytop bashtop && \
sudo sed -i "s|-b .*|## \0\n-b 15000|" /etc/audit/rules.d/audit.rules && \
sudo service auditd restart && sudo auditctl -s && sudo service auditd status
sudo nano /etc/sysctl.conf && sudo sysctl -p

# swappiness
vm.swappiness=10
vm.vfs_cache_pressure=1000
sudo systemctl reset-failed && \
sudo journalctl --rotate && \
sudo journalctl --vacuum-time=1s && \
sudo systemctl restart systemd-journald

Ubuntu OCTOPRINT (Python3)

sudo apt -y update && sudo apt -y dist-upgrade

sudo apt -y install net-tools wireless-tools network-manager rfkill git libyaml-dev build-essential i2c-tools acpi
// sudo apt -y install virtualbox-guest-additions-iso
  • AMD drivers

sudo add-apt-repository ppa:oibaf/graphics-drivers
sudo apt update && sudo apt dist-upgrade -qy
  • Intel drivers

sudo add-apt-repository ppa:sundar-nagarajan/cherrytux
sudo apt update && sudo apt dist-upgrade -qy
sudo apt install -qy intel-gpu-tools
  • Wi-Fi drivers

lspci -knn | grep Net -A2
sudo update-pciids

# BCM4312
sudo apt install firmware-b43-installer -y && sudo reboot now

sudo rfkill list all 
sudo rfkill unblock all

iwconfig
  • Buttery

# Battery status
# cat /sys/class/power_supply/axp288_fuel_gauge/capacity
upower -i $(upower -e | grep 'battery' || 'BAT') | grep -E "state|to\ full|percentage"

sudo nano /bin/charge && \
sudo chmod +x /bin/charge
#!/bin/bash
CH=$(acpi -b | grep -oP "(\d+(\.\d+)?(?=%))")
echo "$CH%"

# Intel ACPI Intrrupts
grep '' /sys/firmware/acpi/interrupts/*
crontab -e
@reboot echo "disable" > /sys/firmware/acpi/interrupts/gpe(?)
  • Screen

sudo bash -c 'echo "10" > /sys/class/backlight/intel_backlight/brightness'
  • Wi-Fi connection

sudo lshw -C network

nmcli d
nmcli r wifi on
nmcli d wifi list
sudo nano /usr/local/bin/wlan-connect.sh && sudo chmod +x /usr/local/bin/wlan-connect.sh

#!/bin/bash
nmcli -f in-use,ssid,bssid,signal,bars dev wifi && \
read -er -p 'SSID: ' WSSID && \
read -er -p 'PASS: ' WPASS && \
sudo nmcli d wifi connect "$WSSID" password "$WPASS" && \
nmcli d

wlan-connect.sh
# Old Wlan card
sudo wpa_cli -i wlan0 SCAN && \
sudo wpa_cli -i wlan0 SCAN_RESULTS

sudo wpa_cli -i wlan0 LIST_NETWORKS
  • Case settings (notebooks)

# man logind.conf 
sudo apt -y install pm-utils && \
sudo cp /etc/systemd/logind.conf /etc/systemd/logind.conf.back

# Wlan powersave off
sudo nano /etc/pm/power.d/wireless_power_management_off && \
sudo chown root:root /etc/pm/power.d/wireless_power_management_off && \
sudo chmod 700 /etc/pm/power.d/wireless_power_management_off
#!/bin/bash
/sbin/iwconfig wlan0 power off

sudo nano /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
[connection]
wifi.powersave = 2
sudo nano /etc/systemd/logind.conf

# do nothing then noteboock is closed
HandleLidSwitch=ignore
# set period backlight is off (sec)
sudo nano /etc/default/grub && sudo update-grub
GRUB_CMDLINE_LINUX_DEFAULT="... quiet consoleblank=300 acpi=strict"

sudo systemctl restart systemd-logind.service
# Ubuntu 16

sudo apt-key adv --refresh-keys --keyserver keyserver.ubuntu.com
sudo apt -y install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update && \
sudo apt -y install python3.9 python3.9-distutils
// sudo apt remove python3.5-minimal -y
ln -sf /usr/bin/python3.9 /usr/local/bin/python3

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \
python3.9 get-pip.py && \
rm get-pip.py

which python3 && python3 --version && pip -V
sudo apt -y install python3-pip python3-dev python3-setuptools python3-virtualenv python3-venv

sudo useradd -m -d /opt/octoprint -s /bin/bash octoprint && \
sudo usermod -a -G tty octoprint && \
sudo usermod -a -G dialout octoprint && \
sudo su - octoprint
virtualenv --python=/usr/bin/python3 venv3
source venv3/bin/activate
pip install pip --upgrade
pip install OctoPrint

# curl -LO https://bootstrap.pypa.io/get-pip.py && python get-pip.py --user
# python -m pip install --user --trusted-host files.pythonhosted.org --trusted-host pypi.org --trusted-host pypi.python.org --upgrade pip
# python -m pip install --user --trusted-host files.pythonhosted.org --trusted-host pypi.org --trusted-host pypi.python.org OctoPrint

deactivate && exit
  • OCTOPRINT actions

REBOOT: sudo shutdown -r now
SHUTDOWN: sudo shutdown -h now

sudo visudo -f /etc/sudoers.d/octoprint-shutdown

octoprint ALL=NOPASSWD:/sbin/shutdown
octo ALL=NOPASSWD:/sbin/shutdown

OCTORESTART: sudo service octoprint restart

sudo visudo -f /etc/sudoers.d/octoprint-service

octoprint ALL=NOPASSWD:/usr/sbin/service octoprint restart
octo ALL=NOPASSWD:/usr/sbin/service octoprint restart

octoprint.default

wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.default && \
sudo mv octoprint.default /etc/default/octoprint
sudo nano /etc/default/octoprint

OCTOPRINT_USER=octoprint
BASEDIR=/opt/octoprint/.octoprint
CONFIGFILE=/opt/octoprint/.octoprint/config.yaml
DAEMON=/opt/octoprint/venv3/bin/octoprint

octoprint.init

wget https://github.com/foosel/OctoPrint/raw/master/scripts/octoprint.init && \
sudo mv octoprint.init /etc/init.d/octoprint && \
sudo chmod +x /etc/init.d/octoprint && \
sudo update-rc.d octoprint defaults && \
sudo service octoprint start
  • OCTOPRINT CuraEngine Legacy - GIT

sudo apt install cura-engine

Path: /usr/bin/CuraEngine
  • OCTOPRINT Macro - GIT

HOME X Y Z
G28 ;Парковка
M84 ;Отключить моторы
HOME X Y
G28 X Y ;Парковка
M84 ;Отключить моторы
PID AUTOTUNE
G28 ;Парковка
G91 ;Относительные координаты
M83 ;Относительные координаты экструдера
M104 S220 ;Ожидание нагрева до 220 градусов
M109 S220 ;Удержание нагрева до 220 градусов
M106 S160 ;Включить обдув
G1 Z10 E-5 F4500 ;Поднять ось Z на 10 мм и ретракт
M400 ;Ожидание завершения
M303 E0 S230 C8 ;Калибровка экструдера
M106 S0 ;Выключить обдув
M303 E-1 S110 C8 ;Калибровка стола
M500 ;Сохранить в EEPROM
M82 ;Абсолютные координаты экструдера
G90 ;Абсолютные координаты
G28 ;Парковка
M84 ;Отключить моторы
M117 Done! ;Вывести текст
M300 S200 P1000 ;Проиграть звук
RETRACT
G28 ;Парковка
G91 ;Относительные координаты
M83 ;Относительные координаты экструдера
G0 Z5 F4500 ;Поднять ось Z на 5 мм
M104 S220 ;Ожидание нагрева до 220 градусов
M109 S220 ;Удержание нагрева до 220 градусов
G0 E-800 F300 ;Ретракт 800 мм со скоростью 300мм/м
M400 ;Ожидание завершения
M104 S0 ;Сброс температуры
G92 E0 ;Сброс длины
M82 ;Абсолютные координаты экструдера
G90 ;Абсолютные координаты
M117 Done! ;Вывести текст
M300 S200 P1000 ;Проиграть звук
EXTRUDE
G28 ;Парковка
G91 ;Относительные координаты
M83 ;Относительные координаты экструдера
G0 Z30 F4500 ;Поднять ось Z на 30 мм
M104 S220 ;Ожидание нагрева до 220 градусов
M109 S220 ;Удержание нагрева до 220 градусов
M300 S200 P100 ;Проиграть звук
M300 S200 P1000
G4 S10 ;Ожидание 10 секунд
G0 E800 F300 ;Выдавить 800 мм со скоростью 300мм/м
M400 ;Ожидание завершения
M104 S0 ;Сброс температуры
G92 E0 ;Сброс длины
M82 ;Абсолютные координаты экструдера
G90 ;Абсолютные координаты
M117 Done! ;Вывести текст
M300 S200 P1000 ;Проиграть звук
  • OCTOPRINT plugins shell install (example)

sudo su - octoprint

source venv/bin/activate
pip install "https://github.com/.../master.zip"
exit
  • OCTOPRINT Web-camera

sudo apt -y install snapd

sudo nano /etc/environment

... :/snap/bin
sudo snap install mjpg-streamer && sudo snap connect mjpg-streamer:camera
sudo apt -y install ffmpeg v4l-utils && sudo v4l2-ctl --list-devices
sudo nano /usr/local/bin/stream.sh && sudo chmod +x /usr/local/bin/stream.sh

#!/bin/bash
RESOLUTION="640x480"
FRAMERATE="25"
VIDEO="/dev/video0"
MJPG_WEB_ROOT="/tmp"
PORT="8080"
LISTEN="0.0.0.0"
DAEMON="mjpg_streamer"
case "$1" in
  start)
    mjpg-streamer -i "input_uvc.so -d $VIDEO -f $FRAMERATE -r $RESOLUTION -yuv -n -timestamp" -o "output_http.so -w $MJPG_WEB_ROOT -p $PORT"
  ;;
  stop)
    pkill -x ${DAEMON}
  ;;
esac
sudo nano /etc/systemd/system/stream.service

[Unit]
Description=Stream
After=network.target

[Service]
CPUWeight=50
CPUQuota=50%
IOWeight=50
MemorySwapMax=0
ExecStart=/usr/local/bin/stream.sh start
ExecStop=/usr/local/bin/stream.sh stop
Restart=on-failure

[Install]
WantedBy=default.target
sudo visudo -f /etc/sudoers.d/camera-service

octoprint ALL=NOPASSWD:/usr/sbin/service stream start
octoprint ALL=NOPASSWD:/usr/sbin/service stream restart
octoprint ALL=NOPASSWD:/usr/sbin/service stream stop
octo ALL=NOPASSWD:/usr/sbin/service stream start
octo ALL=NOPASSWD:/usr/sbin/service stream restart
octo ALL=NOPASSWD:/usr/sbin/service stream stop
sudo apt install jq
sudo nano /usr/local/bin/opower.sh && sudo chmod +x /usr/local/bin/opower.sh

#!/bin/bash
XDOM="http://192.168.0.0"
XNAME="admin"
XPASS="admin"
XURL="$XDOM/cm?user=$XNAME&password=$XPASS&cmnd="
if [ -z "$1" ]; then
  echo 'Need arguments!'
  exit 1
fi
xhr() {
  echo "$(curl ${XURL}${1} -s -H 'Accept: application/json' | jq '.POWER')"
}
RES=$(xhr "POWER")
if [[ ${RES,,} != *"${1,,}"* ]]; then
  xhr "POWER%20${1^^}"
else
  echo "Already ${1^^}..."
fi
sudo nano /opt/octoprint/.octoprint/config.yaml

system:
  actions:
  - name: CAMERA ENABLE
    action: CAMERA ENABLE
    command: sudo service stream start
    confirm: false
  - name: CAMERA DISABLE
    action: CAMERA DISABLE
    command: sudo service stream stop
    confirm: false
  - name: POWER ON
    action: POWER ON
    command: /usr/local/bin/opower.sh on
    confirm: false
  - name: POWER OFF
    action: POWER OFF
    command: /usr/local/bin/opower.sh off
    confirm: true
sudo systemctl daemon-reload && sudo reboot now

http://octoprint:8080/?action=stream
http://octoprint:8080/?action=snapshot

  • OCTOPRINT GCodes

BEFORE PRINT JOB STARTS
M300 S200 P100
AFTER PRINT JOB COMPLETES
M300 S200 P100
AFTER PRINT JOB IS CANCELLED
M84 ;Отключить двигатели
{% snippet 'disable_hotends' %}
{% snippet 'disable_bed' %}
M106 S0 ;Выключить обдув
G90 ;Абсолютные координаты
G28 X Y ;Парковка
AFTER PRINT JOB IS PAUSED
{% if pause_position.x is not none %}
G91 ;Относительные координаты
M83 ;Относительные координаты экструдера
G1 Z+5 E-5 F4500 ;Поднятие сопла и ретракт
M82 ;Абсолютные координаты экструдера
G90 ;Абсолютные координаты
G28 X Y ;Парковка
{% endif %}
BEFORE PRINT JOB IS RESUMED
{% if pause_position.x is not none %}
M83 ;Относительные координаты экструдера
G1 E-5 F4500 ;Ретракт
G1 E5 F4500 ;Возврат ретракта
M82 ;Абсолютные координаты экструдера
G90 ;Абсолютные координаты
G92 E{{ pause_position.e }} ;Возврат метража
G1 X{{ pause_position.x }} Y{{ pause_position.y }} Z{{ pause_position.z }} F4500 ;Возврат осей
{% if pause_position.f is not none %}G1 F{{ pause_position.f }}{% endif %} ;Возврат экструдера
{% endif %}
AFTER CONNECTION TO PRINTER IS ESTABLISHED
M501 ;Чтение EEPROM
M300 S200 P100
BEFORE CONNECTION TO PRINTER IS CLOSED
M300 S200 P100
  • Kiosk

sudo apt -y install --no-install-recommends chromium-browser && \
sudo apt -y install getty-run
sudo nano /lib/systemd/system/[email protected]

[Service]
...
ExecStart=-/sbin/agetty -a !!!USERNAME!!! --noclear %I $TERM
...
sudo apt -y install --no-install-recommends xserver-xorg x11-xserver-utils xinit openbox
sudo nano /etc/xdg/openbox/autostart

# Disable any form of screen saver
xset s off
# Disable screen blanking
xset s noblank
# Disable power management
xset -dpms
# Allow quitting the X server with CTRL-ATL-Backspace
setxkbmap -option terminate:ctrl_alt_bksp
setxkbmap -option startx:alt_x
# Start Chromium in kiosk mode
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' ~/.config/chromium/'Local State'
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/; s/"exit_type":"[^"]\+"/"exit_type":"Normal"/' ~/.config/chromium/Default/Preferences
chromium-browser --disable-infobars --kiosk 'http://localhost:5000/'
cd && sudo nano .bash_profile

[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && startx
  • Matrix screensaver

sudo apt -y install cmatrix && cd && sudo nano .bash_profile

if [ -n "$BASH_VERSION" ]; then
  if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
  fi
fi
[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && ms
  • Alias for Kiosk and Matrix

sudo nano ~/.bash_aliases && source ~/.bashrc

alias ms='cmatrix -s -b'
alias xs='startx'
sudo nano ~/.bashrc

...
if [ -f ~/.bash_aliases ]; then
  . ~/.bash_aliases
fi

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages