Files
pi-pm3/PORT_CONFLICT.md
michael 1da6730735 Add Dangerous Pi MVP implementation - complete backend and system integration
This commit adds the complete Dangerous Pi web management interface with all MVP features implemented and tested locally.

## New Features

### Backend (Python + FastAPI)
- Complete FastAPI backend with async support
- 40+ API endpoints (Health, PM3, WiFi, Updates, UPS, BLE, Plugins)
- 6 managers: Session, WiFi, Update, UPS, BLE, Plugin
- SQLite database with sessions, config, history, crash reports
- Server-Sent Events (SSE) for real-time notifications
- Mock PM3 worker for development without hardware

### WiFi Manager
- Interface detection (USB vs built-in)
- Network scanning with signal strength
- Mode switching (AP/Client/Dual/Auto/Off)
- Network connection with password support
- Hidden SSID and saved networks support
- Static IP and DHCP configuration
- 10 WiFi API endpoints

### Update Manager
- GitHub releases API integration
- Automatic periodic update checks
- Semantic version comparison
- Update download with progress tracking
- SHA256 checksum verification
- Automatic installation with backup and rollback
- PM3 client rebuild after updates
- 6 Update API endpoints

### UPS Manager
- I2C battery monitoring (MAX17040-compatible)
- Battery percentage, voltage, current tracking
- Power source detection (AC/Battery)
- Safe shutdown triggers at configurable thresholds
- Event callbacks for battery warnings
- SSE and BLE notification integration
- 3 UPS API endpoints

### BLE Manager
- Bluetooth Low Energy notification support
- Auto-detects BLE capability
- Multiple notification types (updates, battery, shutdown, etc.)
- BLE advertising management
- Device connection tracking
- 4 BLE API endpoints

### Plugin Framework
- Dynamic plugin loading/unloading
- Plugin lifecycle management (load, enable, disable, unload)
- Hook system for extensibility
- JSON-based metadata
- Example "Hello World" plugin included
- 7 Plugin API endpoints

### Frontend (Remix.js + React)
- Cyberpunk-themed responsive UI
- Dashboard with system status
- PM3 command interface with history
- Settings page with WiFi and Update management
- Command logs viewer
- Theme toggle (Dark/Light/Auto)
- Server-side rendering (SSR)
- Mobile-first responsive design

### System Integration
- Systemd service with security hardening
- Automated install/uninstall scripts
- Environment configuration template
- Hardware access groups (i2c, bluetooth, gpio, dialout)
- Pi-gen stage 04 integration for OS image building
- Port conflict resolution with ttyd-bash
- I2C interface auto-enable for UPS HAT

### Testing
- test_backend.py - Backend API tests
- test_ups.py - UPS manager tests
- test_ble.py - BLE manager tests
- test_plugins.py - Plugin manager tests
- All tests passing locally

### Documentation
- 12 comprehensive documentation files
- claude.md - AI development guide
- WIFI_MANAGER.md - WiFi management guide
- UPDATE_MANAGER.md - Update system guide
- PORT_CONFLICT.md - Port conflict resolution guide
- MVP_COMPLETE.md - MVP implementation summary
- PROJECT_STATUS.md - Project status and roadmap
- systemd/README.md - Service management docs
- pi-gen integration documentation

## Technical Details
- ~5,000+ lines of backend code
- 11 Python dependencies (smbus2 added for UPS)
- FastAPI with async/await throughout
- Type hints and docstrings on all functions
- RESTful API design with SSE for notifications
- Security hardening (non-root, protected dirs, resource limits)

## Next Steps
- Deploy to Raspberry Pi Zero 2 W hardware
- Test with real Proxmark3 device
- Test UPS HAT integration
- Test BLE on Pi hardware
- Build custom OS image with pi-gen
- Performance optimization for Pi Zero 2 W

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 08:11:36 -08:00

5.1 KiB

Port Conflict Resolution

Overview

The existing pi-pm3 setup includes ttyd services that provide web-based terminal access:

  • ttyd-bash on port 8000 - Bash terminal
  • ttyd-pm3 on port 8080 - Proxmark3 terminal
  • RaspAP on port 80 - WiFi management interface

Dangerous Pi's FastAPI backend defaults to port 8000, which conflicts with ttyd-bash.

Resolution Options

You have several options to resolve this conflict:

Use this if: You plan to use Dangerous Pi's web interface instead of the ttyd terminals.

Steps:

sudo systemctl stop ttyd-bash
sudo systemctl disable ttyd-bash

Pros:

  • Simple and clean
  • Frees up port 8000 for Dangerous Pi
  • Reduces resource usage

Cons:

  • Loses standalone bash terminal (can use Dangerous Pi's terminal instead)

Option 2: Change Dangerous Pi Port to 8001

Use this if: You want to keep both ttyd-bash and Dangerous Pi running simultaneously.

Steps:

# Edit environment file
sudo nano /opt/dangerous-pi/.env

# Change PORT line to:
PORT=8001

# Restart service
sudo systemctl restart dangerous-pi

Access Dangerous Pi at: http://<pi-ip>:8001

Pros:

  • Both services available
  • No modification to existing ttyd setup

Cons:

  • Non-standard port for Dangerous Pi
  • Slightly more complex URL

Option 3: Change ttyd-bash Port to 8002

Use this if: You want Dangerous Pi on the standard port 8000 but still want ttyd-bash available.

Steps:

# Edit ttyd-bash service
sudo nano /etc/systemd/system/ttyd-bash.service

# Find the line with --port 8000 and change to:
# --port 8002

# Reload and restart
sudo systemctl daemon-reload
sudo systemctl restart ttyd-bash

Access ttyd-bash at: http://<pi-ip>:8002

Pros:

  • Dangerous Pi on standard port
  • ttyd-bash still available

Cons:

  • Requires modifying existing service
  • ttyd-bash on non-standard port

Automated Resolution Script

For convenience, use the included resolution script:

/opt/dangerous-pi/scripts/resolve-port-conflict.sh

This interactive script will guide you through the options above.

Port Summary

After resolution, your ports may look like:

Configuration A (Option 1 - Disable ttyd-bash)

  • Port 80 - RaspAP
  • Port 8000 - Dangerous Pi
  • Port 8080 - ttyd-pm3
  • ttyd-bash - Disabled

Configuration B (Option 2 - Dangerous Pi on 8001)

  • Port 80 - RaspAP
  • Port 8000 - ttyd-bash
  • Port 8001 - Dangerous Pi
  • Port 8080 - ttyd-pm3

Configuration C (Option 3 - ttyd-bash on 8002)

  • Port 80 - RaspAP
  • Port 8000 - Dangerous Pi
  • Port 8002 - ttyd-bash
  • Port 8080 - ttyd-pm3

Pi-gen Build Integration

If you're building a custom image with pi-gen, you can pre-configure the resolution:

Edit /home/work/dangerous-pi/pi-gen/stageDTPM3/04-dangerous-pi/01-run-chroot.sh and uncomment the desired option:

# Option 1: Disable ttyd-bash
if systemctl is-enabled ttyd-bash 2>/dev/null; then
    systemctl disable ttyd-bash
fi

# OR Option 2: Change Dangerous Pi port
sed -i 's/^PORT=.*/PORT=8001/' /opt/dangerous-pi/.env

# OR Option 3: Change ttyd-bash port
sed -i 's/--port 8000/--port 8002/' /etc/systemd/system/ttyd-bash.service

Then rebuild the image.

Verification

After making changes, verify the configuration:

Check which services are listening on which ports:

sudo netstat -tlnp | grep :80

Check Dangerous Pi status:

sudo systemctl status dangerous-pi

Check ttyd-bash status:

sudo systemctl status ttyd-bash

Test access:

# Dangerous Pi (adjust port as needed)
curl http://localhost:8000/api/health

# ttyd-bash (if enabled, adjust port as needed)
curl http://localhost:8000

Recommendations

For most users: We recommend Option 1 (disable ttyd-bash) because:

  • Dangerous Pi provides a more comprehensive web interface
  • It includes PM3 command capabilities
  • Simpler configuration
  • Fewer services running = better performance on Pi Zero 2 W

For advanced users: If you need both interfaces for specific workflows, use Option 2 or Option 3.

Troubleshooting

Service won't start - "Address already in use"

Check which service is using the port:

sudo lsof -i :8000

Stop the conflicting service before starting Dangerous Pi.

Can't access after changing port

  1. Verify the service is running:

    sudo systemctl status dangerous-pi
    
  2. Check the port in the environment file:

    grep PORT /opt/dangerous-pi/.env
    
  3. Check firewall rules (if enabled):

    sudo iptables -L -n
    

Changes not taking effect

After modifying configurations, always:

# If you changed service files:
sudo systemctl daemon-reload

# Restart the service:
sudo systemctl restart dangerous-pi

Future Considerations

In future versions, we may:

  • Auto-detect port conflicts on startup
  • Dynamically select an available port
  • Provide a web-based port configuration tool
  • Integrate or replace ttyd entirely

For now, manual configuration provides the most flexibility.