plc-checkweigher 1.37.3 → 1.37.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/setup.sh +66 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plc-checkweigher",
3
- "version": "1.37.3",
3
+ "version": "1.37.5",
4
4
  "description": "One-command installer for the PLC Check-Weigher system on Raspberry Pi (PREEMPT_RT kernel, Python stack, WiFi, SMB, systemd RT services)",
5
5
  "scripts": {
6
6
  "postinstall": "node bin/cli.js"
package/setup.sh CHANGED
@@ -277,6 +277,42 @@ setup_wifi() {
277
277
  fi
278
278
  }
279
279
 
280
+ # ── 5b. Ethernet — static IP for PLC communication ───────────────────────────
281
+ setup_eth0_static() {
282
+ step "Ethernet (eth0) — static IP for PLC"
283
+
284
+ local ETH_CON="plc-eth"
285
+ local ETH_IP="192.168.3.10"
286
+ local ETH_PREFIX="24" # 255.255.255.0
287
+
288
+ if ! ip link show eth0 &>/dev/null; then
289
+ warn "No eth0 found — skipping static IP setup."
290
+ return
291
+ fi
292
+
293
+ # Remove any existing managed connection on eth0 to start clean.
294
+ nmcli -t -f NAME,DEVICE con show \
295
+ | awk -F: '$2=="eth0"{print $1}' \
296
+ | while read -r CON; do
297
+ nmcli connection delete "$CON" 2>/dev/null || true
298
+ done
299
+
300
+ nmcli connection add \
301
+ type ethernet \
302
+ ifname eth0 \
303
+ con-name "${ETH_CON}" \
304
+ ipv4.method manual \
305
+ ipv4.addresses "${ETH_IP}/${ETH_PREFIX}" \
306
+ ipv4.gateway "" \
307
+ ipv4.dns "" \
308
+ ipv6.method disabled \
309
+ connection.autoconnect yes \
310
+ connection.autoconnect-priority 100 2>/dev/null
311
+
312
+ nmcli connection up "${ETH_CON}" 2>/dev/null || true
313
+ ok "eth0 → ${ETH_IP}/${ETH_PREFIX} (static, no gateway — PLC subnet only)"
314
+ }
315
+
280
316
  # ── 6b. Web maintenance terminal access code ─────────────────────────────────
281
317
  setup_console_passwd() {
282
318
  step "Maintenance console access code ..."
@@ -460,9 +496,38 @@ EOF
460
496
  chown "${PI_USER}:${PI_USER}" "${INSTALL_DIR}/plc_selfheal.service"
461
497
  ok "plc_selfheal.service (auto-repair · cores 0-2 · Nice=10)"
462
498
 
499
+ # ── Report cleanup timer (daily 02:00 — zip + SMB push + delete >10d files) ─
500
+ cat > /etc/systemd/system/plc_cleanup.service << 'EOF'
501
+ [Unit]
502
+ Description=PLC Report Cleanup — zip + delete files older than 10 days, push backup to SMB
503
+ After=network-online.target
504
+ Wants=network-online.target
505
+
506
+ [Service]
507
+ Type=oneshot
508
+ User=root
509
+ ExecStart=/home/pi/plc_env/bin/python3 /home/pi/plc_checkweigher/report_cleanup.py
510
+ StandardOutput=journal
511
+ StandardError=journal
512
+ EOF
513
+
514
+ cat > /etc/systemd/system/plc_cleanup.timer << 'EOF'
515
+ [Unit]
516
+ Description=PLC Report Cleanup — daily at 02:00
517
+
518
+ [Timer]
519
+ OnCalendar=*-*-* 02:00:00
520
+ Persistent=true
521
+
522
+ [Install]
523
+ WantedBy=timers.target
524
+ EOF
525
+
463
526
  systemctl daemon-reload
464
527
  systemctl enable plc_watcher.service plc_web.service plc_selfheal.service
528
+ systemctl enable plc_cleanup.timer
465
529
  ok "All services enabled — start automatically after reboot"
530
+ ok "plc_cleanup.timer (daily 02:00 — archive + delete reports >10 days)"
466
531
 
467
532
  cp /etc/systemd/system/plc_watcher.service "${INSTALL_DIR}/plc_watcher.service"
468
533
  chown "${PI_USER}:${PI_USER}" "${INSTALL_DIR}/plc_watcher.service"
@@ -988,6 +1053,7 @@ main() {
988
1053
  setup_dirs # 4
989
1054
  install_cli # 5 — plc_checkweigher status command
990
1055
  setup_wifi # 6 — interactive WiFi picker
1056
+ setup_eth0_static # 6b — eth0 static 192.168.3.10/24 for PLC comms
991
1057
  setup_smb # 7 — interactive SMB config → smb_config.py
992
1058
  setup_console_passwd # 7b — web maintenance terminal access code
993
1059
  setup_network_online # 8