2025年11月11日 星期二

安裝 CNCJS

 在 Orange Pi One 上安裝 CNCJS

參考

個人測試安裝

官方文件的資訊,已嚴重落後,如支援的 Node.js 的版本為 v4。目前透過 npm 安裝的 cncjs 是 1.10.5,在 github 的 package.json 中,要求的 Node.js 是 ">=18"。

"engines": {
  "node": ">=18"
},

安裝 "Node Version Manager" 來管理多個 Node.js 版本。

# 安裝 nvm
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
$ source .profile
$ source .bashrc

#安裝最新的 node.js
$ nvm install 22
$ nvm use 22

# 執行 node 會出現錯誤
# node: error while loading shared libraries: libatomic.so.1: cannot open shared object file: No such file or directory

$ sudo apt install libatomic1

# 更新 npm
$ npm install npm@latest -g

# 安裝 cncjs
$ npm install -g cncjs

# 更新 cncjs
$ npm install -g cncjs@latest

以上的安裝,只能以個人的身分執行。

執行後,在網頁上看到的畫面。



Global 安裝

為了自動啟始服務,使用 global 安裝。
# 設定網路之後,更新系統
$ sudo apt update
$ sudo apt upgrade 

# 安裝所需套件及 cncjs
$ sudo apt install nodejs npm git
$ sudo npm install -g cncjs --unsafe-perms 

# CNCjs Test Run
$ cncjs --allow-remote-access -p 8080 

# give us permissions to run on port 80 without root
$ sudo setcap CAP_NET_BIND_SERVICE=+eip /usr/bin/node 

# give permissions to use the serial port
$ sudo usermod -a -G dialout cncjs 

# 建立及啟動 CNCjs Systemd Service
$ sudo touch /etc/systemd/system/cncjs.service
$ sudo chmod 664 /etc/systemd/system/cncjs.service
$ sudo nano /etc/systemd/system/cncjs.service
$ sudo systemctl daemon-reload
$ sudo systemctl start cncjs
$ sudo systemctl enable cncjs 
 
# 下載 tinyweb 套件
$ cd ~
$ git clone https://github.com/cncjs/cncjs-pendant-tinyweb

建立 /etc/systemd/system/cncjs.service 如下。

[Unit]
Description=CNC Controller Web UI
After=network-online.target

[Service]
ExecStart=cncjs -p 80 -m /tinyweb:/home/cncjs/cncjs-pendant-tinyweb/src
User=cncjs
WorkingDirectory=/home/cncjs
Restart=always

[Install]
WantedBy=multi-user.target 

設定 tinyweb 

enable 的 service,連結放在 /etc/systemd/system/multi-user.target.wants


安裝 tineweb


安裝所需的 X window 的 package。

sudo apt install xinit xinput x11-xserver-utils \
    xserver-xorg-input-evdev xserver-xorg-input-libinput \
    xserver-xorg-legacy xserver-xorg-video-fbdev  \
    xdg-utils  chromium-browser 

修改 /etc/X11/Xwrapper.config,"allowed_users=anybody"


-------------
# 建立 start_tinyweb.sh
chromium-browser --noerrdialogs --disable-suggestions-service --disable-translate --disable-save-password-bubble --disable-session-crashed-bubble --disable-infobars --touch-events=enabled --disable-gesture-typing --kiosk http://localhost:8000/pendant/
-------------

cncjs -m /tinyweb:/home/klipper/cncjs-pendant-tinyweb-1.2.4/src &

執行 xinit ./start_tinyweb.sh。

Add a shutdown widget to CNCjs

Go to Settings > Commands, click "+ New," title it "Shutdown," and enter  "sudo shutdown -h now" as the command.

sudo visudo

your_username ALL=NOPASSWD: /sbin/shutdown





網誌存檔