This directory contains the Django backend server for the Blackbox. It serves as the central hub for the embedded "Blackbox" system, managing recording sessions ("Runs"), synchronizing configurations with the ESP32 via Firebase, and providing a real-time web dashboard for tracking telemetry.
The system consists of three main components:
- ESP32 Edge Device: Logs sensor data and pushes to Firebase.
- Firebase Realtime Database: Acts as the message broker between the ESP32 and Django.
- Django Backend: Listens to Firebase, stores data in an SQLite database, and serves the UI.
- Run Management: Create and manage "Runs" representing single tracking journeys.
- Dynamic Configuration: Setting up a new run pushes thresholds (Temperature, Humidity, Light) directly to Firebase (
/run_config), which the ESP32 reads. - Firebase Synchronization:
- Toggling an active run syncs an
Active_Runboolean flag in Firebase to start/stop the ESP32 recording. - A persistent background listener syncs telemetry packets from
/shipment_logsinto local Django SQL.
- Toggling an active run syncs an
- Real-time Dashboard: Displays live sensor readings (Temperature, Humidity, Light Level, GPS Coordinates), along with charts, and aggregated violations.
-
Create a virtual environment and install dependencies:
python3 -m venv venv source venv/bin/activate pip install -r requirements.txt -
Add your Firebase credentials: Place your
firebasekey.jsoninside themain/blackbox/directory. -
Run migrations to set up the SQLite database:
cd main python manage.py migrate
To run the application, you need to start two separate processes:
Process 1: Django Web Server Provides the HTTP server for the web interface and API endpoints.
cd main
python manage.py runserverProcess 2: Firebase Background Listener
Maintains a persistent WebSocket connection to Firebase, listening to the /shipment_logs node. This automatically saves every telemetry packet the ESP32 pushes into the local SQLite database.
cd main
python manage.py firebase_listenermodels.py: Defines theRunandSensorReadingschema.views.py: Web endpoints for listing runs, displaying run details (graphs & metrics), and toggling runs.firebase_utils.py: Helper functions to push configuration and active state to Firebase.management/commands/firebase_listener.py: The background script for real-time telemetry polling.