fix: Resolve Pi server connection issues and add comprehensive diagnostics #88
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🐛 Fixes
Critical: Server Container Crash on Fresh Pi Image
Root Cause: Missing requests dependency caused ModuleNotFoundError on startup
Fix: Added requests==2.31.0 to server/requirements.txt
Impact: Server containers now start successfully on Pi
Unreliable LabLink Service Startup
Problem: lablink.service used Type=oneshot with no restart policy, insufficient wait times
Fix: Enhanced systemd service configuration in build-pi-image.sh:
Changed to Type=forking for proper container process management
Added Restart=on-failure with 10s exponential backoff
Extended timeouts: 120s start, 30s stop
Improved health checks: waits up to 30s for containers to be healthy
Added Docker daemon readiness check: waits up to 60s before starting
Impact: LabLink automatically recovers from failures and handles boot timing issues
✨ New Features
Comprehensive Pi Diagnostics System
Added integrated diagnostic tooling accessible directly from the LabLink client GUI:
System information (hostname, uptime, Pi model)
Network status (IP addresses, connectivity, DNS)
Docker status and daemon health
LabLink installation verification
Service and container status
Port listener detection
Recent logs analysis
Automated recommendations for common issues
2. Server API (POST /api/diagnostics/pi-diagnostics)
Executes diagnostic script on Pi server
60-second timeout with full output capture
Returns structured results with exit codes
3. Client API (client.run_pi_diagnostics())
90-second timeout for network latency
Clean error handling
4. GUI Integration (Diagnostics Panel)
"Run Pi Diagnostics" button in Diagnostics tab
Beautiful results dialog featuring:
Scrollable monospace output
Copy to clipboard button
Save to timestamped file (e.g., pi-diagnostics-20251120-142530.txt)
Color-coded success/failure status
Clear error messages with troubleshooting hints
🎯 Benefits
✅ No more "Connection Refused" errors on fresh Pi images
✅ Automatic service recovery if containers crash
✅ One-click troubleshooting without SSH access
✅ Streamlined debugging with comprehensive system reports
✅ Easy issue sharing via copy/save functionality
✅ Better resilience to boot timing issues on slower Pi models
📝 Testing
For Existing Pi (with crash issue):
cd /opt/lablink
sudo docker compose down
sudo docker compose build --no-cache
sudo docker compose up -d
lablink-status
For New Pi Images:
Rebuild Pi image using the updated build-pi-image.sh
All fixes automatically included
For GUI Diagnostics:
Connect to Pi server in LabLink client
Navigate to Diagnostics tab
Click "Run Pi Diagnostics"
View/copy/save comprehensive report
🔧 Files Changed
server/requirements.txt - Added requests dependency
build-pi-image.sh - Enhanced systemd service and first-boot script
diagnose-pi.sh - New comprehensive diagnostic script
server/api/diagnostics.py - New Pi diagnostics endpoint
client/api/client.py - New run_pi_diagnostics() method
client/ui/diagnostics_panel.py - GUI integration with results dialog