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>
This commit is contained in:
michael
2025-11-26 08:11:36 -08:00
parent 0a586c5360
commit 1da6730735
68 changed files with 12673 additions and 5 deletions

167
README_DEV.md Normal file
View File

@@ -0,0 +1,167 @@
# Dangerous Pi - Development Guide
## Quick Start
### 1. Install Dependencies
```bash
# Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install Python dependencies
pip install -r requirements.txt
```
### 2. Run Tests
```bash
# Test backend components
python test_backend.py
```
### 3. Start Backend Server
```bash
# Development mode with auto-reload
python -m app.backend.main
# Or using uvicorn directly
uvicorn app.backend.main:app --reload --host 0.0.0.0 --port 8000
```
### 4. Test API Endpoints
```bash
# Health check
curl http://localhost:8000/api/health
# System info
curl http://localhost:8000/api/system/info
# PM3 status (uses mock when no hardware present)
curl http://localhost:8000/api/pm3/status
# Create session
curl -X POST http://localhost:8000/api/system/session/create \
-H "Content-Type: application/json" \
-d '{"force_takeover": false}'
# Execute PM3 command (mock)
curl -X POST http://localhost:8000/api/pm3/command \
-H "Content-Type: application/json" \
-d '{"command": "hw version", "session_id": "your-session-id"}'
# SSE events stream
curl -N http://localhost:8000/sse/events
```
## Project Structure
```
dangerous-pi/
├── app/
│ ├── backend/ # FastAPI backend
│ │ ├── main.py # App entry point
│ │ ├── config.py # Configuration
│ │ ├── api/ # REST endpoints
│ │ ├── sse/ # SSE endpoints
│ │ ├── workers/ # PM3 worker
│ │ ├── managers/ # Business logic
│ │ └── models/ # Database models
│ ├── frontend/ # Web UI (TBD)
│ ├── plugins/ # Optional plugins
│ └── scripts/ # Helper scripts
├── data/ # SQLite database
├── logs/ # Application logs
├── pi-gen/ # OS image builder
├── requirements.txt # Python deps
├── test_backend.py # Backend tests
└── claude.md # AI dev guide
```
## API Documentation
Once the server is running, visit:
- **Swagger UI**: http://localhost:8000/docs
- **ReDoc**: http://localhost:8000/redoc
## Development Workflow
### Backend Development
1. **Add new endpoint**:
- Create/edit router in `app/backend/api/`
- Register router in `app/backend/main.py`
- Test with curl or Swagger UI
2. **Add new manager**:
- Create manager in `app/backend/managers/`
- Use in API endpoints
- Add tests
3. **Add SSE event**:
- Add helper function in `app/backend/sse/events.py`
- Call from managers/workers
- Test with `curl -N`
### Testing on Raspberry Pi
1. **Transfer code**:
```bash
rsync -avz --exclude 'venv' --exclude '__pycache__' \
. dt@10.3.141.1:/home/dt/dangerous-pi/
```
2. **SSH into Pi**:
```bash
ssh dt@10.3.141.1
```
3. **Install and run**:
```bash
cd dangerous-pi
pip3 install -r requirements.txt
python3 -m app.backend.main
```
## Mock vs Real PM3
The backend automatically uses `MockPM3Worker` when the `pm3` module is not available. This allows development without Proxmark3 hardware.
To use real PM3:
- Ensure Proxmark3 client is installed with Python support
- The `pm3` module must be importable
- Set `PM3_DEVICE` environment variable to your device path
## Environment Variables
Copy `.env.example` to `.env` and customize:
```bash
cp .env.example .env
nano .env
```
See [claude.md](claude.md) for full list of environment variables.
## Next Steps
See [claude.md](claude.md) for:
- Detailed architecture
- Implementation roadmap
- PM3 API usage
- Integration guidelines
## Troubleshooting
### Port 8000 already in use
The existing pi-pm3 uses ttyd on port 8000. Either:
- Change PORT in config to 8001
- Stop ttyd: `sudo systemctl stop ttyd-bash`
### PM3 module not found
Expected during development. The mock worker will be used automatically.
### Database locked
Stop all running instances of the backend.