Updated README with comprehensive API documentation and latest features

This commit is contained in:
Josh Finlay 2025-01-07 15:35:56 +10:00
parent 18389ed0cb
commit ddb5bdf40e
1 changed files with 107 additions and 45 deletions

152
README.md
View File

@ -1,72 +1,134 @@
# DLB Gate Keeper
A Raspberry Pi-based gate control system with a web interface.
A modern web application for controlling the DLB gate, featuring a beautiful macOS-inspired UI and robust backend.
## Architecture
## Features
- Backend: Python FastAPI server with direct GPIO control
- Frontend: React/TypeScript web interface
- Database: SQLite for event logging and settings
- Service: Systemd service for automatic startup and monitoring
- Single-button gate control with automatic state detection
- Real-time gate status monitoring
- Event logging for all gate operations
- Configurable settings for gate timing
- Mobile-responsive design with glass morphism effects
- Modern macOS-inspired user interface
## Development Setup
## Technical Stack
### Backend (Python)
### Frontend
- React with TypeScript
- Tailwind CSS for styling
- Modern glass morphism design
- Mobile-first responsive layout
1. Install Python dependencies:
```bash
cd backend
pip install -r requirements.txt
```
### Backend
- FastAPI (Python)
- SQLite for data persistence
- RPi.GPIO for hardware control
- Async operations for improved performance
2. Run the development server:
```bash
uvicorn main:app --reload --host 0.0.0.0 --port 3000
```
## API Documentation
### Frontend (React)
### Endpoints
1. Install Node.js dependencies:
```bash
cd frontend
npm install
```
#### Gate Control
- `POST /api/trigger`
- Toggles the gate state (open/close)
- Response: `{ "success": boolean, "currentStatus": boolean }`
2. Start the development server:
```bash
npm run dev
```
#### Gate Status
- `GET /api/status`
- Returns current gate status
- Response: `{ "isOpen": boolean, "lastChanged": string }`
#### Event History
- `GET /api/events`
- Returns gate operation history
- Query Parameters:
- `limit`: number (default: 10)
- Response: Array of `{ "id": number, "timestamp": string, "action": string, "source": string, "success": boolean }`
#### Settings
- `GET /api/settings`
- Returns current settings
- Response: `{ "maxOpenTimeSeconds": string, "triggerDuration": string }`
- `POST /api/settings`
- Updates gate settings
- Body: `{ "maxOpenTimeSeconds": string, "triggerDuration": string }`
- Response: `{ "success": boolean }`
## Installation
1. Clone the repository:
```bash
git clone https://git.athenanetworks.com.au/josh/dlbGatekeeper.git
```
2. Install backend dependencies:
```bash
cd backend
pip install -r requirements.txt
```
3. Install frontend dependencies:
```bash
cd frontend
npm install
```
## Development
1. Start the backend:
```bash
cd backend
python main.py
```
2. Start the frontend development server:
```bash
cd frontend
npm run dev
```
## Deployment
1. Deploy to Raspberry Pi:
Use the deployment script:
```bash
./deploy.sh
```
This will:
- Build the frontend
- Package the Python backend
- Copy files to the Raspberry Pi
- Install Python dependencies
- Set up and start the systemd service
1. Build the frontend
2. Package all files
3. Deploy to the Raspberry Pi
4. Restart the service
## GPIO Setup
## Configuration
The application uses GPIO pin 17 (BCM numbering) by default. You can change this by setting the `RELAY_PIN` environment variable in the systemd service file.
### GPIO Pins
- `RELAY_1_PIN`: 22 (default)
- `RELAY_2_PIN`: 5 (default)
- `STATUS_PIN`: 4 (default)
Make sure the gatekeeper user has access to GPIO:
```bash
sudo usermod -a -G gpio gatekeeper
```
### Timing Settings
- `maxOpenTimeSeconds`: Maximum time the gate stays open (default: 300 seconds)
- `triggerDuration`: Duration of the trigger pulse in milliseconds (default: 500ms)
## API Endpoints
## Status Indicators
- `POST /api/trigger/{direction}` - Trigger gate (direction: "open" or "close")
- `GET /api/events` - Get recent gate events
- `GET /api/settings` - Get current settings
- `POST /api/settings` - Update settings
- Gate Open: Status LED shows HIGH (3.3V)
- Gate Closed: Status LED shows LOW (0V)
## Security
- No authentication required (internal network only)
- CORS enabled for development
- Rate limiting on API endpoints
## Contributing
1. Create a feature branch
2. Make your changes
3. Submit a pull request
## License
MIT
Copyright 2025 DLB. All rights reserved.