plc-checkweigher 1.3.0 → 1.5.0

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 (3) hide show
  1. package/bin/cli.js +3 -1
  2. package/package.json +1 -1
  3. package/setup.sh +78 -14
package/bin/cli.js CHANGED
@@ -45,8 +45,10 @@ console.log(`${Y}This will:${NC}`);
45
45
  console.log(' 1. Install the PREEMPT_RT real-time kernel (reboots once)');
46
46
  console.log(' 2. Install all Python dependencies');
47
47
  console.log(' 3. Clone / update the plc-checkweigher repo');
48
- console.log(' 4. Configure WiFi, SMB file sharing');
48
+ console.log(' 4. Configure WiFi, SMB file sharing (credentials → smb_config.py)');
49
49
  console.log(' 5. Install systemd services with RT scheduling priority');
50
+ console.log(' 6. Set up live dashboard → http://<pi-ip>:8080/live');
51
+ console.log(' 7. Set up PDF report viewer with instant auto-refresh');
50
52
  console.log('');
51
53
  console.log(`${Y}Sudo password required to make system-level changes.${NC}`);
52
54
  console.log('');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plc-checkweigher",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
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
  "bin": {
6
6
  "plc-checkweigher": "bin/cli.js"
package/setup.sh CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bash
2
2
  # =============================================================================
3
- # PLC Check-Weigher — Full Stack Installer v1.3
3
+ # PLC Check-Weigher — Full Stack Installer v1.4
4
4
  # =============================================================================
5
5
  # Run on any fresh Raspberry Pi:
6
6
  #
@@ -16,9 +16,10 @@
16
16
  # 7. SMB — enter host IP, share name, credentials → smb_config.py
17
17
  # 8. NetworkManager-wait-online
18
18
  # 9. systemd services (plc_watcher + plc_web)
19
- # 10. Boot logo — Plymouth theme with logo.png + "SAI SAMARTH ENGG"
20
- # 11. PREEMPT_RT kernel ← installed last so only one reboot is needed
21
- # 12. REBOOT
19
+ # 10. Boot logo — Plymouth theme with logo.png + "SAI SAMARTH ENGG"
20
+ # 11. Display — LightDM priority, CPU isolation, utmpx, GPU memory
21
+ # 12. PREEMPT_RT kernel ← installed last so only one reboot is needed
22
+ # 13. REBOOT
22
23
  # =============================================================================
23
24
 
24
25
  set -euo pipefail
@@ -82,7 +83,7 @@ prompt_secret() {
82
83
 
83
84
  # ── 0. Pre-flight ─────────────────────────────────────────────────────────────
84
85
  preflight() {
85
- banner "PLC Check-Weigher Installer v1.2"
86
+ banner "PLC Check-Weigher Installer v1.4"
86
87
  [[ "${EUID}" -eq 0 ]] || die "Run via npx plc-checkweigher (asks for sudo password)"
87
88
  [[ "$(uname -m)" == "aarch64" ]] || die "Requires 64-bit Raspberry Pi (aarch64). Got: $(uname -m)"
88
89
  [[ -d "${HOME_DIR}" ]] || die "Home ${HOME_DIR} not found. Set PI_USER= to override."
@@ -444,7 +445,64 @@ EOF
444
445
  || { echo ""; warn "initramfs warnings — see /tmp/initramfs.log"; }
445
446
  }
446
447
 
447
- # ── 11. RT kernel installed LAST so only one reboot is needed ───────────────
448
+ # ── 11. DisplayLightDM priority, CPU isolation, utmpx, GPU memory ────────
449
+ setup_display() {
450
+ step "Display priority & LightDM ..."
451
+
452
+ # Install display stack if not present
453
+ DEBIAN_FRONTEND=noninteractive apt-get install -y -qq \
454
+ lightdm labwc pi-greeter xserver-xorg 2>/dev/null || true
455
+
456
+ # ── Remove network dependency from LightDM ───────────────────────────────
457
+ # Display manager must not wait for network — it is independent of PLC services.
458
+ mkdir -p /etc/systemd/system/lightdm.service.d/
459
+ rm -f /etc/systemd/system/lightdm.service.d/wait-for-network.conf
460
+
461
+ cat > /etc/systemd/system/lightdm.service.d/display-priority.conf << 'EOF'
462
+ [Unit]
463
+ # Start after hardware udev settles (HDMI/DSI detected) — not after network.
464
+ After=systemd-udev-settle.service local-fs.target acpid.socket dbus.service
465
+ Wants=systemd-udev-settle.service
466
+
467
+ [Service]
468
+ # Generous restart policy — display should always recover.
469
+ StartLimitBurst=20
470
+ StartLimitIntervalSec=120
471
+ Restart=on-failure
472
+ RestartSec=3
473
+
474
+ # CPU cores 0-2 only — core 3 is reserved for SCHED_FIFO PLC process.
475
+ CPUAffinity=0 1 2
476
+
477
+ # Elevated priority — display stays responsive under PLC RT workload.
478
+ Nice=-5
479
+
480
+ LimitNOFILE=65536
481
+ EOF
482
+ ok "LightDM: CPUAffinity=0-2, Nice=-5, network dep removed"
483
+
484
+ # ── Fix utmpx — PAM needs /run/utmp to track sessions ───────────────────
485
+ cat > /etc/tmpfiles.d/utmp-fix.conf << 'EOF'
486
+ f /run/utmp 0664 root utmp -
487
+ EOF
488
+ systemd-tmpfiles --create /etc/tmpfiles.d/utmp-fix.conf 2>/dev/null || true
489
+ ok "/run/utmp fixed (utmpx PAM session tracking)"
490
+
491
+ # ── GPU memory — 128 MB: enough for 1080p desktop and HMI use ───────────
492
+ sed -i '/^gpu_mem=/d' "${BOOT_FW}/config.txt"
493
+ if grep -q "### PLC-RT-BLOCK-START ###" "${BOOT_FW}/config.txt"; then
494
+ sed -i '/### PLC-RT-BLOCK-START ###/i gpu_mem=128' "${BOOT_FW}/config.txt"
495
+ else
496
+ echo "gpu_mem=128" >> "${BOOT_FW}/config.txt"
497
+ fi
498
+ ok "gpu_mem=128 set in config.txt (128 MB VRAM)"
499
+
500
+ systemctl daemon-reload
501
+ systemctl enable lightdm.service 2>/dev/null || true
502
+ ok "LightDM enabled — starts on every boot when display is connected"
503
+ }
504
+
505
+ # ── 12. RT kernel — installed LAST so only one reboot is needed ───────────────
448
506
  install_rt_kernel() {
449
507
  step "PREEMPT_RT kernel (final step before reboot) ..."
450
508
 
@@ -502,17 +560,22 @@ do_reboot() {
502
560
  echo ""
503
561
  banner "Setup Complete"
504
562
  echo ""
505
- printf " ${G}%-32s${NC} %s\n" "Repo:" "${INSTALL_DIR}"
506
- printf " ${G}%-32s${NC} %s\n" "Python venv:" "${VENV_DIR}"
507
- printf " ${G}%-32s${NC} %s\n" "Reports output:" "${REPORTS_DIR}"
508
- printf " ${G}%-32s${NC} %s\n" "RT kernel:" "kernel8-rt.img (active after reboot)"
563
+ PI_IP="$(hostname -I | awk '{print $1}' 2>/dev/null || echo '<pi-ip>')"
564
+ printf " ${G}%-32s${NC} %s\n" "Repo:" "${INSTALL_DIR}"
565
+ printf " ${G}%-32s${NC} %s\n" "Python venv:" "${VENV_DIR}"
566
+ printf " ${G}%-32s${NC} %s\n" "Reports output:" "${REPORTS_DIR}"
567
+ printf " ${G}%-32s${NC} %s\n" "SMB config:" "${INSTALL_DIR}/smb_config.py"
568
+ printf " ${G}%-32s${NC} %s\n" "RT kernel:" "kernel8-rt.img (active after reboot)"
509
569
  printf " ${G}%-32s${NC} %s\n" "Stock kernel fallback:" "kernel8-stock.img"
510
- printf " ${G}%-32s${NC} %s\n" "Web dashboard (after reboot):" \
511
- "http://$(hostname -I | awk '{print $1}' 2>/dev/null || echo '<pi-ip>'):8080"
570
+ echo ""
571
+ echo -e " ${Y}Web interfaces (after reboot):${NC}"
572
+ printf " ${C}%-32s${NC} %s\n" "Report viewer:" "http://${PI_IP}:8080/"
573
+ printf " ${C}%-32s${NC} %s\n" "Live dashboard:" "http://${PI_IP}:8080/live"
512
574
  echo ""
513
575
  echo -e " ${Y}After reboot:${NC}"
514
576
  echo " journalctl -u plc_watcher -f # live logs"
515
577
  echo " sudo chrt -p \$(systemctl show -p MainPID --value plc_watcher) # verify RT"
578
+ echo " cat ${INSTALL_DIR}/procedure.md # full setup guide"
516
579
  echo ""
517
580
 
518
581
  echo -e "${G}"
@@ -543,8 +606,9 @@ main() {
543
606
  setup_network_online # 7
544
607
  install_services # 8
545
608
  setup_boot_logo # 9 — Plymouth: logo + "SAI SAMARTH ENGG"
546
- install_rt_kernel # 10 — LAST, so only one reboot needed
547
- do_reboot # 11 — single reboot applies everything
609
+ setup_display # 10 — LightDM priority, CPU isolation, utmpx, GPU
610
+ install_rt_kernel # 11 — LAST, so only one reboot needed
611
+ do_reboot # 12 — single reboot applies everything
548
612
  }
549
613
 
550
614
  main "$@"