Skip to content

Commit f4b7e78

Browse files
committed
Making the pi installer ready
1 parent f09ac02 commit f4b7e78

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

gateway/install.sh

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,36 @@ sudo iw dev wlan0 set power_save off 2>/dev/null || true # best-effort; persis
3232
sudo nmcli connection modify "$(nmcli -t -f NAME connection show --active | head -n1)" \
3333
802-11-wireless.powersave 2 2>/dev/null || true
3434

35-
# 5. systemd service: auto-start on boot, auto-connect, restart on crash
36-
# (WorkingDirectory in the unit is /home/pi/PenPlotter271 — edit it if your path differs)
37-
sudo cp gateway/plotter-gateway.service /etc/systemd/system/plotter-gateway.service
35+
# 5. systemd service — GENERATED with this machine's actual user, repo path and
36+
# node path, so it works regardless of username/location (the static
37+
# gateway/plotter-gateway.service is just a reference template).
38+
# PLOTTER_PATH is left unset → the daemon auto-detects the ttyUSB/ttyACM device.
39+
# Pin it (e.g. /dev/plotter from the udev rule) by uncommenting the line below.
40+
NPX="$(command -v npx)"
41+
sudo tee /etc/systemd/system/plotter-gateway.service >/dev/null <<EOF
42+
[Unit]
43+
Description=PenPlotter271 gateway daemon
44+
After=network-online.target
45+
Wants=network-online.target
46+
47+
[Service]
48+
Type=simple
49+
User=$USER_NAME
50+
SupplementaryGroups=dialout
51+
WorkingDirectory=$REPO
52+
ExecStart=$NPX tsx gateway/server.ts
53+
Environment=GATEWAY_PORT=8717
54+
Environment=GATEWAY_HOST=127.0.0.1
55+
Environment=PLOTTER_STATE=$REPO/gateway/.plotter-state.json
56+
# Environment=PLOTTER_PATH=/dev/plotter
57+
Restart=always
58+
RestartSec=3
59+
StandardOutput=journal
60+
StandardError=journal
61+
62+
[Install]
63+
WantedBy=multi-user.target
64+
EOF
3865
sudo systemctl daemon-reload
3966
sudo systemctl enable --now plotter-gateway
4067

@@ -46,5 +73,4 @@ echo "Reach the web app from your laptop (same WiFi) via an SSH tunnel:"
4673
echo " ssh -L 8717:localhost:8717 $USER_NAME@$(hostname).local"
4774
echo " then open http://localhost:8717"
4875
echo "Logs: journalctl -u plotter-gateway -f"
49-
echo "NOTE: if the WorkingDirectory in the unit doesn't match $REPO, edit"
50-
echo " /etc/systemd/system/plotter-gateway.service and 'sudo systemctl daemon-reload'."
76+
echo "Serial device detected:"; ls -l /dev/serial/by-id/ 2>/dev/null || ls -l /dev/ttyUSB* /dev/ttyACM* 2>/dev/null || echo " (none — plug in / power on the plotter)"

0 commit comments

Comments
 (0)