Updated README with comprehensive API documentation and latest features
This commit is contained in:
parent
18389ed0cb
commit
ddb5bdf40e
134
README.md
134
README.md
|
|
@ -1,72 +1,134 @@
|
||||||
# DLB Gate Keeper
|
# 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
|
- Single-button gate control with automatic state detection
|
||||||
- Frontend: React/TypeScript web interface
|
- Real-time gate status monitoring
|
||||||
- Database: SQLite for event logging and settings
|
- Event logging for all gate operations
|
||||||
- Service: Systemd service for automatic startup and monitoring
|
- 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:
|
### Backend
|
||||||
|
- FastAPI (Python)
|
||||||
|
- SQLite for data persistence
|
||||||
|
- RPi.GPIO for hardware control
|
||||||
|
- Async operations for improved performance
|
||||||
|
|
||||||
|
## API Documentation
|
||||||
|
|
||||||
|
### Endpoints
|
||||||
|
|
||||||
|
#### Gate Control
|
||||||
|
- `POST /api/trigger`
|
||||||
|
- Toggles the gate state (open/close)
|
||||||
|
- Response: `{ "success": boolean, "currentStatus": boolean }`
|
||||||
|
|
||||||
|
#### 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
|
```bash
|
||||||
cd backend
|
cd backend
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Run the development server:
|
3. Install frontend dependencies:
|
||||||
```bash
|
|
||||||
uvicorn main:app --reload --host 0.0.0.0 --port 3000
|
|
||||||
```
|
|
||||||
|
|
||||||
### Frontend (React)
|
|
||||||
|
|
||||||
1. Install Node.js dependencies:
|
|
||||||
```bash
|
```bash
|
||||||
cd frontend
|
cd frontend
|
||||||
npm install
|
npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Start the development server:
|
## Development
|
||||||
|
|
||||||
|
1. Start the backend:
|
||||||
```bash
|
```bash
|
||||||
|
cd backend
|
||||||
|
python main.py
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Start the frontend development server:
|
||||||
|
```bash
|
||||||
|
cd frontend
|
||||||
npm run dev
|
npm run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
## Deployment
|
## Deployment
|
||||||
|
|
||||||
1. Deploy to Raspberry Pi:
|
Use the deployment script:
|
||||||
```bash
|
```bash
|
||||||
./deploy.sh
|
./deploy.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
This will:
|
This will:
|
||||||
- Build the frontend
|
1. Build the frontend
|
||||||
- Package the Python backend
|
2. Package all files
|
||||||
- Copy files to the Raspberry Pi
|
3. Deploy to the Raspberry Pi
|
||||||
- Install Python dependencies
|
4. Restart the service
|
||||||
- Set up and start the systemd 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:
|
### Timing Settings
|
||||||
```bash
|
- `maxOpenTimeSeconds`: Maximum time the gate stays open (default: 300 seconds)
|
||||||
sudo usermod -a -G gpio gatekeeper
|
- `triggerDuration`: Duration of the trigger pulse in milliseconds (default: 500ms)
|
||||||
```
|
|
||||||
|
|
||||||
## API Endpoints
|
## Status Indicators
|
||||||
|
|
||||||
- `POST /api/trigger/{direction}` - Trigger gate (direction: "open" or "close")
|
- Gate Open: Status LED shows HIGH (3.3V)
|
||||||
- `GET /api/events` - Get recent gate events
|
- Gate Closed: Status LED shows LOW (0V)
|
||||||
- `GET /api/settings` - Get current settings
|
|
||||||
- `POST /api/settings` - Update settings
|
## 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
|
## License
|
||||||
|
|
||||||
MIT
|
Copyright 2025 DLB. All rights reserved.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue