Système de gestion de parking aéroportuaire intelligent avec intégration IoT ESP32, mises à jour en temps réel via WebSocket, et authentification Firebase.
- Monitoring en Temps RΓ©el: 6 capteurs IR ESP32 dΓ©tectent la prΓ©sence des vΓ©hicules
- RΓ©servations Intelligentes: Les utilisateurs rΓ©servent des places avec expiration automatique
- Mises Γ Jour Live: WebSocket diffuse les changements d'Γ©tat instantanΓ©ment
- Barrière Automatique: Servo-moteur contrôlé par l'ESP32
- Affichage LCD: Γcran I2C affichant l'Γ©tat du parking
- Authentification SΓ©curisΓ©e: Firebase Auth pour les utilisateurs, clΓ© API pour les capteurs
aeropack/
βββ backend/ # Backend FastAPI
β βββ main.py # Point d'entrΓ©e
β βββ config.py # Configuration
β βββ requirements.txt # DΓ©pendances Python
β βββ .env # Variables d'environnement
β βββ routers/ # Routes API
β β βββ auth.py # Authentification utilisateurs
β β βββ parking.py # OpΓ©rations parking
β β βββ admin.py # Administration
β β βββ sensor.py # Routes capteurs ESP32
β β βββ websocket.py # Gestionnaire WebSocket
β βββ services/ # Logique mΓ©tier
β β βββ parking_service.py
β β βββ reservation_service.py
β β βββ websocket_service.py
β βββ models/ # ModΓ¨les Pydantic
β β βββ parking.py # place_id, etat, force_signal
β β βββ user.py
β βββ security/ # SΓ©curitΓ©
β β βββ firebase_auth.py
β β βββ api_key.py # Validation clΓ© API
β βββ database/ # Couche base de donnΓ©es
β β βββ firebase_db.py # OpΓ©rations Firestore
β βββ utils/
β βββ scheduler.py
β βββ helpers.py
βββ esp32/ # Client ESP32
β βββ aeropark_sensor/
β βββ aeropark_sensor.ino # Code Arduino
βββ README.md
- ESP32 DevKit - MicrocontrΓ΄leur principal
- 6 Capteurs IR - DΓ©tection places (a1-a6)
- 2 Capteurs IR - EntrΓ©e/Sortie
- 1 Servo SG90 - Barrière
- 1 LCD I2C 16x2 - Affichage
| Composant | GPIO ESP32 |
|---|---|
| IR Place a1 | GPIO 13 |
| IR Place a2 | GPIO 14 |
| IR Place a3 | GPIO 25 |
| IR Place a4 | GPIO 26 |
| IR Place a5 | GPIO 27 |
| IR Place a6 | GPIO 34 |
| IR EntrΓ©e | GPIO 32 |
| IR Sortie | GPIO 33 |
| Servo | GPIO 4 |
| LCD SDA | GPIO 21 |
| LCD SCL | GPIO 22 |
cd aeropack/backend
# CrΓ©er environnement virtuel
python -m venv venv
# Activer (Windows)
venv\Scripts\activate
# Installer dΓ©pendances
pip install -r requirements.txtVotre .env est dΓ©jΓ configurΓ©. VΓ©rifiez que les valeurs sont correctes:
FIREBASE_PROJECT_ID="aeropark-a191e"
FIREBASE_PRIVATE_KEY="..."
FIREBASE_CLIENT_EMAIL="..."
# ClΓ© API ESP32 (IDENTIQUE dans le code Arduino)
SENSOR_API_KEY=aeropark-sensor-key-2024
# Paramètres
TOTAL_PARKING_SLOTS=6# Depuis le dossier backend
uvicorn main:app --host 0.0.0.0 --port 8000 --reloadLe serveur dΓ©marre sur http://localhost:8000
- Documentation Swagger: http://localhost:8000/docs
- Health check: http://localhost:8000/health
| Endpoint | MΓ©thode | Description |
|---|---|---|
/api/v1/sensor/update |
POST | Mise Γ jour Γ©tat place |
/api/v1/sensor/health |
GET | VΓ©rification connexion |
/ws/parking |
WebSocket | Notifications rΓ©servations |
{
"place_id": "a1",
"etat": "occupied",
"force_signal": -55
}Content-Type: application/json
X-API-Key: aeropark-sensor-key-2024
Notification de rΓ©servation:
{
"type": "reservation",
"donnees": {
"place_id": 1,
"action": "create"
}
}Dans esp32/aeropark_sensor/aeropark_sensor.ino, modifiez:
// WiFi
const char* ssid = "VOTRE_SSID";
const char* password = "VOTRE_MOT_DE_PASSE";
// Serveur (IP de votre PC sur le mΓͺme rΓ©seau)
const char* serverHost = "192.168.1.100";
const int serverPort = 8000;
// ClΓ© API (doit correspondre au backend)
const char* apiKey = "aeropark-sensor-key-2024";Dans Arduino IDE, installer via Library Manager:
ArduinoJson(by Benoit Blanchon)WebSockets(by Markus Sattler)ESP32ServoLiquidCrystal I2C
GET /parking/status
POST /parking/reserve
Authorization: Bearer <firebase_id_token>
{
"place_id": "a1",
"duration_minutes": 60
}
POST /parking/release/a1
Authorization: Bearer <firebase_id_token>
- Capteurs ESP32: ClΓ© API dans header
X-API-Key - Utilisateurs: Token Firebase dans header
Authorization: Bearer <token> - CORS: ConfigurΓ© pour accepter toutes les origines (
*)
-
DΓ©marrer le backend:
cd backend && uvicorn main:app --host 0.0.0.0 --port 8000 --reload
-
Tester l'endpoint sensor avec curl:
curl -X POST http://localhost:8000/api/v1/sensor/update \ -H "Content-Type: application/json" \ -H "X-API-Key: aeropark-sensor-key-2024" \ -d '{"place_id": "a1", "etat": "occupied", "force_signal": -50}'
-
VΓ©rifier la rΓ©ponse:
{ "success": true, "place_id": "a1", "new_etat": "occupied", "message": "Place a1 mise Γ jour", "timestamp": "2024-..." }
Le backend crΓ©e automatiquement la collection parking_places avec les documents:
parking_places/
βββ a1: { place_id: "a1", etat: "free", ... }
βββ a2: { place_id: "a2", etat: "free", ... }
βββ a3: { place_id: "a3", etat: "free", ... }
βββ a4: { place_id: "a4", etat: "free", ... }
βββ a5: { place_id: "a5", etat: "free", ... }
βββ a6: { place_id: "a6", etat: "free", ... }
cd backend
docker build -t aeropark-backend .
docker run -p 8000:8000 --env-file .env aeropark-backend- VΓ©rifier SSID et mot de passe
- ESP32 supporte uniquement WiFi 2.4GHz
- VΓ©rifier que
X-API-Keyest exactementaeropark-sensor-key-2024 - VΓ©rifier que
SENSOR_API_KEYdans.envcorrespond
- VΓ©rifier que le port 8000 est ouvert
- Utiliser l'IP locale du serveur (pas localhost)
- VΓ©rifier les credentials Firebase dans
.env - S'assurer que Firestore est activΓ© dans la console Firebase
AeroPark Smart System - Projet de fin d'Γ©tudes
cp .env.example .env
# Edit .env with your Firebase credentials and API keys-
Run the server:
# Development uvicorn main:app --reload --host 0.0.0.0 --port 8000 # Production uvicorn main:app --host 0.0.0.0 --port 8000 --workers 4
-
Access the API:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- WebSocket: ws://localhost:8000/ws/parking
-
Install Arduino IDE (or PlatformIO)
-
Install ESP32 board support:
- File β Preferences β Additional Board Manager URLs
- Add:
https://dl.espressif.com/dl/package_esp32_index.json - Tools β Board β Boards Manager β Search "esp32" β Install
-
Install required libraries:
- ArduinoJson (by Benoit Blanchon)
-
Configure the sketch: Open
esp32/parking_sensor/parking_sensor.inoand update:const char* WIFI_SSID = "YOUR_WIFI_SSID"; const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD"; const char* SERVER_HOST = "YOUR_SERVER_IP"; const char* API_KEY = "YOUR_SENSOR_API_KEY"; const char* SPOT_ID = "YOUR_SPOT_ID";
-
Hardware wiring (HC-SR04):
HC-SR04 Pin ESP32 Pin VCC 5V GND GND TRIG GPIO 5 ECHO GPIO 18 -
Upload and monitor:
- Select board: Tools β Board β ESP32 Dev Module
- Select port: Tools β Port β (your COM port)
- Upload sketch
- Open Serial Monitor (115200 baud)
| Method | Endpoint | Description |
|---|---|---|
| GET | /users/me |
Get current user profile |
| GET | /users/me/reservation |
Get user's active reservation |
| Method | Endpoint | Description |
|---|---|---|
| GET | /parking/status |
Get all spots status |
| GET | /parking/available |
Get available spots only |
| GET | /parking/spot/{id} |
Get specific spot details |
| POST | /parking/reserve |
Reserve a parking spot |
| POST | /parking/release |
Release reserved spot |
| POST | /parking/extend |
Extend reservation time |
| Method | Endpoint | Description |
|---|---|---|
| GET | /admin/parking/all |
Get all spots (admin) |
| GET | /admin/parking/stats |
Get parking statistics |
| POST | /admin/parking/add |
Add new parking spot |
| PUT | /admin/parking/{id} |
Update spot configuration |
| DELETE | /admin/parking/{id} |
Delete parking spot |
| POST | /admin/parking/force-release/{id} |
Force release any spot |
| POST | /admin/parking/initialize |
Initialize default spots |
| Method | Endpoint | Description |
|---|---|---|
| POST | /sensor/update |
Report spot occupancy |
| POST | /sensor/heartbeat |
Sensor keep-alive |
| GET | /sensor/config/{id} |
Get sensor configuration |
| POST | /sensor/batch-update |
Batch sensor updates |
| Endpoint | Description |
|---|---|
/ws/parking |
Real-time parking updates |
GET /ws/status |
WebSocket connection stats |
Users authenticate via Firebase ID tokens:
Authorization: Bearer <firebase-id-token>ESP32 sensors authenticate via API key:
X-API-Key: <sensor-api-key>
X-Sensor-ID: <sensor-identifier>Admins need both Firebase auth (with admin role) and may use admin API key for additional security.
AVAILABLE ββ(user reserves)ββ> RESERVED
β β
β β
(vehicle leaves (vehicle arrives
or expiry) - sensor detects)
β β
β β
AVAILABLE <ββ(vehicle leaves)ββ OCCUPIED
Connect to ws://localhost:8000/ws/parking to receive real-time updates:
const ws = new WebSocket('ws://localhost:8000/ws/parking');
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
switch(data.type) {
case 'connected':
console.log('Connected to parking updates');
break;
case 'initial_status':
console.log('Current parking status:', data.data);
break;
case 'spot_update':
console.log('Spot changed:', data.event, data.data);
break;
case 'reservation_created':
console.log('New reservation:', data.data);
break;
case 'sensor_update':
console.log('Sensor update:', data.data);
break;
}
};
// Request current status
ws.send(JSON.stringify({ type: 'get_status' }));
// Keep-alive ping
ws.send(JSON.stringify({ type: 'ping', timestamp: Date.now() }));curl -X POST "http://localhost:8000/parking/reserve" \
-H "Authorization: Bearer YOUR_FIREBASE_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"spot_id": "SPOT_ID_HERE",
"duration_minutes": 60
}'curl -X POST "http://localhost:8000/sensor/update" \
-H "X-API-Key: YOUR_SENSOR_API_KEY" \
-H "X-Sensor-ID: ESP32-SENSOR-001" \
-H "Content-Type: application/json" \
-d '{
"spot_id": "SPOT_ID_HERE",
"status": "occupied",
"distance_cm": 25.5
}'curl -X POST "http://localhost:8000/admin/parking/add" \
-H "Authorization: Bearer ADMIN_FIREBASE_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"spot_number": "B1",
"zone": "Terminal 2",
"floor": 1,
"sensor_id": "ESP32-SENSOR-006"
}'| Variable | Description | Required |
|---|---|---|
FIREBASE_PROJECT_ID |
Firebase project ID | Yes |
FIREBASE_PRIVATE_KEY |
Service account private key | Yes |
FIREBASE_CLIENT_EMAIL |
Service account email | Yes |
FIREBASE_DATABASE_URL |
Firestore database URL | Yes |
SENSOR_API_KEY |
API key for ESP32 sensors | Yes |
ADMIN_API_KEY |
API key for admin operations | Yes |
CORS_ORIGINS |
Allowed CORS origins (comma-separated) | No |
DEBUG |
Enable debug mode | No |
DEFAULT_RESERVATION_DURATION_MINUTES |
Default reservation time | No |
MAX_RESERVATION_DURATION_MINUTES |
Maximum reservation time | No |
After starting the server, initialize default parking spots:
curl -X POST "http://localhost:8000/admin/parking/initialize" \
-H "Authorization: Bearer ADMIN_TOKEN"Use the mock ESP32 behavior:
# Report spot as occupied
curl -X POST "http://localhost:8000/sensor/update" \
-H "X-API-Key: your-sensor-api-key" \
-d '{"spot_id": "SPOT_ID", "status": "occupied"}'
# Report spot as free
curl -X POST "http://localhost:8000/sensor/update" \
-H "X-API-Key: your-sensor-api-key" \
-d '{"spot_id": "SPOT_ID", "status": "free"}'FROM python:3.11-slim
WORKDIR /app
COPY backend/ .
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]The application is ready for deployment to Google Cloud Run or similar platforms. Ensure environment variables are configured in your cloud provider.
- Payment integration (Stripe/PayPal)
- Mobile app (React Native)
- License plate recognition (OpenCV/ML)
- Multi-floor parking visualization
- Parking guidance system
- Analytics dashboard
- Rate limiting and quotas
- Email/SMS notifications
This project is proprietary software for AeroPark Smart System.
For support and inquiries, contact the AeroPark development team.