This guide provides a comprehensive step-by-step process for setting up the DeerSafe project, including configuring the Raspberry Pi, setting up the database, integrating sensors, running the application, testing with Postman, and using Expo Go for mobile testing.
- Download the Raspberry Pi Imager:
- Flash the OS to an SD card:
- Choose Raspberry Pi OS (Lite or Desktop) and configure Wi-Fi and SSH under
Advanced Options
.
- Choose Raspberry Pi OS (Lite or Desktop) and configure Wi-Fi and SSH under
- Insert the SD card into your Raspberry Pi and boot it up.
- Update the system:
sudo apt update && sudo apt upgrade -y
- Install required tools:
sudo apt install python3 python3-pip gpsd gpsd-clients python3-gps git -y
- Clone the repository to the Raspberry Pi:
git clone https://github.com/kxs1119/Detection-System.git cd Detection-System
- Install PostgreSQL:
sudo apt install postgresql postgresql-contrib -y
- Start the PostgreSQL service:
sudo systemctl start postgresql sudo systemctl enable postgresql
-
Switch to the PostgreSQL user:
sudo -i -u postgres
-
Create the DeerSafe database:
psql CREATE DATABASE deersafe; CREATE USER deersafe_user WITH ENCRYPTED PASSWORD 'your_password'; GRANT ALL PRIVILEGES ON DATABASE deersafe TO deersafe_user; \q exit
-
Apply database schema:
psql -U deersafe_user -d deersafe -f Detection-System/backend/schema.sql
- Navigate to the backend directory:
cd Detection-System/backend
- Run virtual environment:
source env/bin/activate pip install -r requirements.txt
- Navigate to the frontend directory:
cd Detection-System/DeerSafeApp
- Install dependencies:
npm install
-
Wire the GPS module to the Raspberry Pi using a breadboard:
- GPS TX → Raspberry Pi GPIO RX (Pin 10).
- GPS RX → Raspberry Pi GPIO TX (Pin 8).
- GPS VCC → Raspberry Pi 5V (Pin 2).
- GPS GND → Raspberry Pi GND (Pin 6).
-
Verify connections:
- Use a multimeter to check continuity for proper wiring.
- Navigate to the
sensor_script
directory:cd Detection-System/sensor_script
- Install Python dependencies:
pip install -r requirements.txt
- Start the GPS handler script:
python3 gps_handler.py
- Navigate to the backend directory:
cd Detection-System/backend source env/bin/activate
- Start the Flask server:
flask run --host=0.0.0.0 --port=8080
- Navigate to the frontend directory:
cd Detection-System/DeerSafeApp
- Start the React Native application:
npm start
- Download Expo Go from your mobile device’s app store:
- Ensure your mobile device and Raspberry Pi are on the same Wi-Fi network.
- Start the React Native application on your Raspberry Pi:
npm start
- Once the React Native application starts, a QR code will be displayed in your terminal or browser.
- Open the Expo Go app on your mobile device.
- Scan the QR code to load the application on your mobile.
- Test GPS and alerts directly from the mobile app.
- Interact with the application and ensure the following:
- User location updates on the map.
- Alerts display correctly based on proximity.
- Open Postman and create a new POST request.
- Use the following URLs:
-
To test location data:
POST http://127.0.0.1:8080/api/location
Body (JSON):
{ "latitude": 41.301943, "longitude": -79.890538 }
-
To test proximity alerts:
POST http://127.0.0.1:8080/api/proximity
Body (JSON):
{ "latitude": 41.301943, "longitude": -79.890538 }
-
To test alert processing:
POST http://127.0.0.1:8080/api/alerts
Body (JSON):
{ "id": 1, "device": "ESP32-CAM-01", "time_stamp": "2024-10-31T15:45:00Z", "latitude": 41.301943, "longitude": -79.890538, "location": "Route 27", "animal_type": "Deer", "alert_count": 1, "description": "Single deer detected crossing the road" }
-
- Check that the backend returns appropriate success responses.
- Ensure that the database updates reflect the sent data.
-
Backend not reachable:
- Ensure the Flask server is running and accessible via the specified port.
- Verify the Raspberry Pi's IP address.
-
No GPS data:
- Check the GPS sensor connections.
- Run the test script:
python3 gps_handler.py
-
Frontend not working:
- Ensure all dependencies are installed.
- Restart the React Native application:
npm start
-
Mobile app not loading:
- Verify that the mobile device and Raspberry Pi are on the same Wi-Fi network.
- Restart the Expo Go app and re-scan the QR code.
You are now ready to deploy and test the DeerSafe system! Follow these steps to ensure seamless integration between the Raspberry Pi, GPS sensor, backend, frontend, and mobile application.