Smart beehive monitoring system with AI-powered Asian hornet detection
Real-time monitoring of beehives wellbeing, temperature, humidity, and automatic detection of Asian hornets to protect bee colonies.
| Name | Role |
|---|---|
| Yasser BOUHAI | Project Lead |
| Ghozlene HANAFI | Developer |
| Yanelle BEKKAR | Developer |
| Hadriel RATIARISON | Developer |
| Amine NAIT SI-AHMED | Developer |
Sorbonne Université - 2025/2026
┌─────────────────────────────────────────────────────────────┐
│ ESP32 Device │
│ Edge Impulse AI Model (on-device) │
│ Temperature, Humidity, Camera, Microphone │
└─────────────────────────┬───────────────────────────────────┘
│ LoRaWAN
▼
┌─────────────────────────────────────────────────────────────┐
│ The Things Network (TTN) │
│ Payload Formatter │
└─────────────────────────┬───────────────────────────────────┘
│ Webhook (POST /api/iot/data)
▼
┌─────────────────────────────────────────────────────────────┐
│ Backend │
│ FastAPI + Python │
│ (Port 8000) │
└──────────┬──────────────┼──────────────────┬────────────────┘
│ │ │
▼ ▼ ▼
┌──────────────────┐ ┌──────────────┐ ┌─────────────────────┐
│ MySQL │ │ InfluxDB │ │ Frontend │
│ (Relational DB) │ │ (Time-series)│ │ React + Nginx │
│ Port 3306 │ │ Port 8086 │ │ Port 80 │
│ │ │ │ │ │
│ - Users │ │ - Sensor data│ │ - Dashboard │
│ - Organizations │ │ - Temperature│ │ - Charts │
│ - Beehives │ │ - Humidity │ │ - Settings │
│ - Apiaries │ │ - Bee counts │ │ - Alerts history │
│ - Settings │ │ - Hornets │ │ │
└──────────────────┘ └──────────────┘ └─────────────────────┘
| Component | Technology |
|---|---|
| Frontend | React 18, Vite, CSS Modules |
| Backend | FastAPI, Python 3.11 |
| Database | MySQL 8.0 |
| Time-series DB | InfluxDB 2.7 |
| Containerization | Docker, Docker Compose |
| Reverse Proxy | Nginx |
| Hardware | ESP32 (Seeed XIAO) |
| AI Inference | Edge Impulse |
| Communication | LoRaWAN via TTN |
| SMTP (Gmail compatible) |
- Docker Desktop installed and running
- Git
# Clone the repo
git clone https://github.com/your-username/BeeGuardAI.git
cd BeeGuardAI
# Create environment file from template
cp .env.example .env
# Edit .env with your own credentials (SMTP, database passwords, etc.)
# Start all services
docker-compose up -d
# Check logs
docker-compose logs -fAccess the app at: http://localhost
- Email:
admin@sorbonne.fr - Password:
admin123
BeeGuardAI/
├── backend-python/ # FastAPI backend
│ ├── app/
│ │ ├── main.py # App entry point
│ │ ├── config.py # Environment config
│ │ ├── models.py # Pydantic models
│ │ ├── db/
│ │ │ ├── mysql.py # MySQL operations
│ │ │ └── influxdb.py # InfluxDB operations
│ │ ├── routes/
│ │ │ ├── auth.py # Authentication
│ │ │ ├── ruchers.py # Apiaries management
│ │ │ ├── ruches.py # Beehives management
│ │ │ ├── data.py # Sensor data & IoT
│ │ │ └── settings.py # User settings
│ │ └── services/
│ │ ├── email_service.py # SMTP emails
│ │ ├── alert_service.py # Hornet alerts
│ │ └── report_service.py # PDF reports
│ ├── Dockerfile
│ └── requirements.txt
│
├── frontend-react/ # React frontend
│ ├── src/
│ │ ├── pages/ # Page components
│ │ ├── components/ # Reusable components
│ │ ├── services/ # API client
│ │ └── context/ # Auth context
│ ├── nginx.conf # Nginx config
│ ├── Dockerfile
│ └── package.json
│
├── esp32/ # ESP32 firmware
│ ├── arduino.ino # Main Arduino code
│ └── beeguardai_inferencing/ # Edge Impulse model library
│
├── tests/
│ ├── simulate_device.py # Device simulator
│ └── test_report.py # Email test script
│
├── docker-compose.yml # Docker services
├── .env.example # Environment template
└── README.md
The ESP32 device runs on-device AI inference using Edge Impulse.
- Microcontroller: Seeed XIAO ESP32S3
- Sensors: Temperature, humidity,Luminosity, camera, microphone
- Communication: LoRaWAN module
arduino.ino- Main code that reads sensors, runs inference, and sends data via LoRaWANbeeguardai_inferencing/- Edge Impulse exported library containing the trained AI model
- ESP32 reads sensors and runs AI inference locally
- Results sent via LoRaWAN to The Things Network (TTN)
- TTN payload formatter decodes the raw bytes to JSON
- TTN webhook sends POST request directly to backend
/api/iot/data - Backend stores in InfluxDB and triggers email alerts if hornets detected
// Device sends: "DATA T:25.4 H:40.2"
// Formatter outputs:
{
"device_id": "xiao-beeguard",
"temperature": 25.4,
"humidite": 40.2,
"nombre_frelons": 0,
"nombre_abeilles": 0,
"luminosite": 1,
"etat_acoustique": "bees"
}We manually labeled over 1,000 images to train our object detection model with three classes:
| Class | Description |
|---|---|
bees |
Group of bees gathered in front of the hive |
bee |
Single bee |
hornet |
Asian hornet roaming around the hive |
We used an iterative training approach on Edge Impulse:
- Initial labeling - Manual bounding box annotation of images
- Incremental training - After each batch of labeled images, we retrained the model to monitor accuracy evolution
- Final model - Achieved 85% accuracy using YOLO Pro architecture
Training Evolution:
┌────────────────┬──────────────┐
│ Training Round │ Accuracy │
├────────────────┼──────────────┤
│ Round 1 │ ~45% │
│ Round 2 │ ~60% │
│ Round 3 │ ~72% │
│ Final (YOLO) │ ~85% │
└────────────────┴──────────────┘
The YOLO Pro model could not run on the ESP32 due to severe RAM limitations. Even the YOLO Nano variant (the smallest YOLO format available) exceeded the memory capacity of the Seeed XIAO ESP32S3. We therefore switched to the FOMO architecture and applied several optimization techniques to achieve a good compromise between memory usage and accuracy:
| Optimization Technique | Description |
|---|---|
| Image size reduction | Reduced input resolution to fit memory constraints |
| Quantization | Converted model weights from float32 to int8 |
| Grayscale conversion | Changed from RGB to grayscale images (3x less memory) |
| Architecture tuning | Modified convolution layers and classifier parameters |
| Parameter | Value |
|---|---|
| Architecture | FOMO (Faster Objects, More Objects) |
| Accuracy | 70-75% |
| Target device | Seeed XIAO ESP32S3 |
| Input format | RGB (camera native) |
- The optimized FOMO model has some false positives and false negatives
- Overall detection is reliable enough to trigger hornet alerts effectively
- The trade-off between accuracy and memory footprint was necessary for embedded deployment
- Real-world testing shows satisfactory hornet detection for alerting purposes
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register new user |
| POST | /api/auth/login |
Login |
| POST | /api/auth/logout |
Logout |
| GET | /api/auth/me |
Get current user |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/ruchers |
List apiaries |
| POST | /api/ruchers |
Create apiary |
| GET | /api/ruches |
List beehives |
| POST | /api/ruches |
Create beehive |
| PUT | /api/ruches/{id} |
Update beehive |
| DELETE | /api/ruches/{id} |
Delete beehive |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/donnees/latest |
Get latest sensor data |
| GET | /api/ruches/{id}/donnees |
Get beehive history |
| POST | /api/iot/data |
Receive IoT sensor data |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/settings |
Get user settings |
| PUT | /api/settings |
Update settings |
- User authentication (register, login, logout)
- Multi-organization support
- Beehive management (CRUD)
- Apiary management (CRUD)
- Real-time dashboard with sensor data
- Historical data charts with time range filtering
- Acoustic state monitoring (bees, no_bees, queen)
- Auto-generated device IDs
- IoT data ingestion (direct HTTP + TTN webhook)
- Device simulator for testing
- Dark/Light theme toggle
- Email alerts for hornet detection
- PDF reports (daily/weekly)
- User settings page
Create .env from .env.example and configure with your credentials:
# MySQL
MYSQL_ROOT_PASSWORD=your-root-password
MYSQL_DATABASE=beeguardai
MYSQL_USER=beeguard
MYSQL_PASSWORD=your-password
# InfluxDB
INFLUX_TOKEN=your-influx-token
INFLUX_ORG=beeguardai
INFLUX_BUCKET=sensor_data
# SMTP Email (for alerts and reports)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your-email@gmail.com
SMTP_PASSWORD=your-app-password
SMTP_FROM_EMAIL=your-email@gmail.com
SMTP_FROM_NAME=BeeGuardAIcurl -X POST http://your-server/api/iot/data \
-H "Content-Type: application/json" \
-d '{
"device_id": "beehive-12345",
"temperature": 35.2,
"humidite": 65.0,
"nombre_abeilles": 150,
"nombre_frelons": 0,
"luminosite": 1,
"etat_acoustique": "bees"
}'Configure a webhook in TTN console pointing to:
https://your-server/api/iot/data
cd tests
python simulate_device.pycd tests
python test_report.py report # Test PDF report
python test_report.py alert # Test alert check- Install Docker Desktop
- Clone repo and create
.envwith your credentials - Run
docker-compose up -d - Access at http://localhost
- Get a VPS (OVH, Hetzner, DigitalOcean, etc.)
- Install Docker & Docker Compose
- Clone repo and configure
.env - Run
docker-compose up -d - Point your domain to the VPS IP
- (Optional) Set up SSL with Let's Encrypt
MIT