Intelligentes IoT-Pflanzenbewässerungssystem für Raspberry Pi 5
PlanetPlant ist ein vollständiges IoT-System zur automatischen Überwachung und Bewässerung von Pflanzen. Das System kombiniert ESP32-Sensoren, eine Raspberry Pi 5-Zentrale und eine moderne React-PWA für die Benutzeroberfläche.
┌─────────────────┐ MQTT ┌─────────────────┐ HTTP/WS ┌─────────────────┐
│ ESP32 │◄────────────┤ Raspberry Pi 5 │◄──────────────┤ React PWA │
│ Sensoren & │ │ │ │ Dashboard │
│ Wasserpumpe │ │ InfluxDB │ │ │
└─────────────────┘ │ Mosquitto MQTT │ └─────────────────┘
│ Redis Cache │
│ Node.js API │
│ Grafana │
└─────────────────┘
Datenfluss: ESP32 → MQTT → Backend → InfluxDB → Grafana & Web-Dashboard
- Raspberry Pi 5 (oder Pi 4) mit min. 4GB RAM
- Docker & Docker Compose installiert
- 10GB freier Speicherplatz
- Internetverbindung für Initial-Setup
# 1. Repository klonen
git clone https://github.com/PhilKsr/planetplant.git
cd planetplant
# 2. Environment konfigurieren
cp .env.example .env
nano .env # WiFi & MQTT Einstellungen anpassen
# 3. Raspberry Pi 5 setup (einmalig)
make setup-pi
# 4. Services starten
make up
# 5. System testen
make testFertig! 🎉 Zugriff auf:
- Frontend: http://
<PI-IP> - Grafana: http://
<PI-IP>:3001 (admin/plantplant123) - InfluxDB: http://
<PI-IP>:8086
| Service | Port | Beschreibung | Credentials | Speicher |
|---|---|---|---|---|
| Frontend | 80 | React PWA Dashboard | - | 512MB |
| Backend API | 3001 | Node.js REST API | - | 2GB |
| Grafana | 3001 | Datenvisualisierung | admin/plantplant123 | 1GB |
| InfluxDB | 8086 | Zeitserien-Datenbank | admin/plantplant123 | 2GB |
| MQTT Broker | 1883 | Message Broker | - | 512MB |
| Redis | 6379 | Cache & Sessions | plantplant123 | 1GB |
| Nginx | 80 | Reverse Proxy | - | 256MB |
- ARM64 native Container-Images
- Ressourcen-Limits angepasst für 8GB RAM
- Restart-Policies für hohe Verfügbarkeit
- Health-Checks für alle Services
- Persistent Volumes unter
/opt/planetplant/
- ESP32 DevKit v1
- Kapazitive Bodenfeuchte-Sensoren
- DHT22 (Temperatur/Luftfeuchtigkeit)
- 5V Wasserpumpe mit Relais
- Optional: LDR Lichtsensor
ESP32 DevKit v1 Komponente
================ =============
GPIO 4 ──── DHT22 Data
A0 (GPIO 36) ──── Moisture Sensor Analog
GPIO 5 ──── Pump Relay IN
A3 (GPIO 39) ──── Light Sensor (Optional)
GPIO 2 ──── Status LED (Built-in)
GPIO 0 ──── Manual Button (Built-in)
3.3V ──── Sensor VCC
GND ──── Sensor & Relay GND
5V ──── Pump & Relay VCC
# Mit PlatformIO
cd esp32
pio run --target upload
# Mit Arduino IDE
# Öffne esp32/src/main.cpp und upload direkt- Erste Verbindung: ESP32 erstellt WiFi "PlanetPlant-Setup"
- Verbinden: Passwort "plantplant123"
- Konfigurieren: Web-Portal öffnet sich automatisch
- MQTT Setup: Raspberry Pi IP-Adresse eingeben
# ESP32 → Server (Published)
sensors/{device_id}/data # Sensor-Daten alle 60s
sensors/{device_id}/status # Device-Status Updates
sensors/{device_id}/pump # Pump-Activity
devices/{device_id}/heartbeat # Keep-Alive alle 5min
# Server → ESP32 (Subscribed)
commands/{device_id}/water # Bewässerungs-Befehle
commands/{device_id}/config # Konfigurations-Updates# Development Environment starten
make dev
# Frontend Development Server
make frontend-dev # http://localhost:5173
# Backend Development
make backend-dev # http://localhost:3001
# Logs verfolgen
make logs
# Services testen
make test# Linting
make lint
# Dependencies prüfen
make check-deps
# Security Scan
make security-scan- Branch erstellen:
git checkout -b feature/new-feature - Code ändern in
raspberry-pi/oderwebapp/ - Tests laufen lassen:
make test - Linting prüfen:
make lint - Pull Request erstellen
- Live Status: http://localhost:3005/status (Public Status Page)
- Uptime Kuma: http://localhost:3005 (Health Monitoring)
- Grafana: http://localhost:3006 (Metrics Dashboards)
- Prometheus: http://localhost:9091 (Raw Metrics)
- Service Down > 2 Minuten → Critical Alert
- Response Time > 2 Sekunden → Warning
- Error Rate > 5% → Warning
- Disk Space < 20% → Warning
- No Sensor Data > 15 Minuten → Warning
- Memory Usage > 80% → Warning
# Setup monitoring with notifications
./scripts/setup-monitoring.sh
# Configure SMTP for alerts
SMTP_USER=your-email@gmail.com ./scripts/configure-alerting.sh- Health Overview: System status and alerts
- Plant Monitoring: Sensor data and automation
- Performance Metrics: CPU, memory, disk usage
- Container Health: Docker container monitoring
make down && make up # Alles neu starten
make rebuild # Force rebuild
make clean # Aufräumen + neu startenmake logs # Alle Services
make logs-backend # Nur Backend
make logs-influxdb # Nur InfluxDBmake status # Detaillierter Status
make health # Schneller Health-Check
docker-compose ps # Container-Status| Problem | Ursache | Lösung |
|---|---|---|
| ❌ InfluxDB startet nicht | Falsche Permissions | sudo chown -R $USER /opt/planetplant |
| ❌ MQTT Verbindung fehlschlägt | Firewall blockiert | sudo ufw allow 1883 |
| ❌ Frontend nicht erreichbar | Nginx-Config Fehler | make logs-frontend |
| ❌ Frontend Build-Fehler | Lucide-React Import | Icons in PlantDetail.jsx prüfen |
| ❌ Hohe RAM-Nutzung | Resource Limits | docker stats → Limits anpassen |
| ❌ ESP32 verbindet nicht | WiFi-Probleme | Reset-Button halten beim Start |
# System-Ressourcen prüfen
free -h # RAM-Verbrauch
df -h # Disk-Space
docker stats --no-stream # Container-Ressourcen
# Logs rotieren
sudo logrotate -f /etc/logrotate.d/planetplant
# Alte Backups löschen
find /opt/planetplant/backups -name "*.tar.gz" -mtime +30 -delete-
Passwörter ändern in
.env:JWT_SECRET=your-secure-secret-min-32-chars INFLUXDB_PASSWORD=secure-password REDIS_PASSWORD=secure-password GRAFANA_ADMIN_PASSWORD=secure-password
-
Firewall konfigurieren:
sudo ufw enable sudo ufw allow ssh sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw allow 1883/tcp # MQTT
-
Tailscale für Remote-Zugriff:
curl -fsSL https://tailscale.com/install.sh | sh sudo tailscale up
# Automatisches Backup (täglich um 2:00 Uhr)
echo "0 2 * * * cd /home/pi/planetplant && make backup" | crontab -
# Manuelles Backup
make backup
# Backup wiederherstellen
make restore file=/opt/planetplant/backups/planetplant_backup_20240101_120000.tar.gz# Abhängigkeiten installieren
make install
# Development starten
make dev
# Tests laufen lassen
make test
# Code-Qualität prüfen
make lintPlanetPlant verfügt über eine vollständige Staging-Umgebung für Tests vor Production:
# Staging starten (separate Ports)
make staging
# Staging Status prüfen
make staging-status
# Staging Logs
make staging-logs
# Staging Health Check
make staging-health
# Staging bereinigen
make staging-cleanStaging URLs:
- Frontend: http://localhost:8080
- Backend API: http://localhost:3002/api
- InfluxDB: http://localhost:8087
- Grafana: http://localhost:3003
- develop branch → Automatisches Staging Deployment
- main branch → Automatisches Production Deployment
- Pull Requests → Staging Tests
# Staging zu Production promoten
make promote-to-prod- ESLint für JavaScript/React
- Prettier für Code-Formatierung
- Conventional Commits für Commit-Messages
- Tests für neue Features
PlanetPlant verfügt über eine vollständige CI/CD Pipeline für automatisierte Builds und Deployments.
- Trigger: Push auf main branch oder manuell
- Platforms: linux/amd64 (Mac/x86), linux/arm64 (Raspberry Pi)
- Registry: GitHub Container Registry (ghcr.io)
- Images: backend, frontend, nginx-proxy
- Trigger: Push auf main branch oder manuell
- Stages: Build → Test → Deploy → Notify
- Features: Rolling updates, health checks, automatic rollback
- Target: Raspberry Pi via SSH
Für die CI/CD Pipeline müssen folgende Secrets in den Repository-Einstellungen konfiguriert werden:
# Deployment Target
PI_HOST=your-raspberry-pi-hostname-or-ip
PI_SSH_KEY=your-private-ssh-key-content
# Container Registry (automatisch verfügbar)
GITHUB_TOKEN=automatic-github-token
# Notifications (optional)
DISCORD_WEBHOOK=https://discord.com/api/webhooks/your-webhook
SLACK_WEBHOOK=https://hooks.slack.com/your-webhookFür lokale Multi-Arch Builds:
# Setup
export GITHUB_TOKEN=ghp_your_token_here
# Build und Push aller Images
./scripts/push-images.sh
# Spezifische Version
IMAGE_TAG=v1.2.3 ./scripts/push-images.sh- Code Push auf main branch
- Images builden für AMD64 + ARM64
- Integration Tests mit neuen Images
- Deploy auf Pi via SSH mit Rolling Update
- Health Checks nach Deployment
- Notifications über Discord/Slack
- Automatic Rollback bei Fehlern
Raspberry Pi vorbereiten für automatisierte Deployments:
# 1. SSH Key Setup
ssh-copy-id pi@your-pi-host
# 2. Docker Login Token erstellen
echo "ghp_your_token" | docker login ghcr.io -u your-username --password-stdin
# 3. Deployment Directory
sudo mkdir -p /opt/planetplant
sudo chown pi:pi /opt/planetplant
# 4. Environment konfigurieren
cp .env.example /opt/planetplant/.env
# .env entsprechend anpassen- Node.js 20 mit Express.js
- InfluxDB 2.7 für Zeitserien-Daten
- Redis 7.2 für Caching
- Mosquitto MQTT 2.0 für IoT-Kommunikation
- PM2 für Process Management
- React 18.3 mit Vite 5.4
- Tailwind CSS 3.4 für Styling
- Recharts für Datenvisualisierung
- PWA mit Service Worker
- i18next für Mehrsprachigkeit
- Docker Compose für Service-Orchestrierung
- Nginx als Reverse Proxy
- Grafana 10.2 für Advanced Monitoring
- ARM64 optimierte Container
- 8GB RAM: Optimal für alle Services
- 64GB+ SD-Karte: Class 10 oder besser
- Netzwerk: Ethernet oder WiFi 6
- Kühlung: Aktiver Lüfter empfohlen
- 4GB RAM: Funktional, Grafana optional
- 32GB+ SD-Karte: Class 10
- Resource Limits müssen angepasst werden
# Wichtigste Einstellungen
NODE_ENV=production
INFLUXDB_PASSWORD=secure-password-here
GRAFANA_ADMIN_PASSWORD=secure-password-here
JWT_SECRET=your-secure-jwt-secret-32-chars
MQTT_BROKER_URL=mqtt://localhost:1883
# Automatisierung
MOISTURE_THRESHOLD=30 # Bewässerung bei < 30%
WATERING_DURATION=5000 # 5 Sekunden pumpen
MAX_WATERING_PER_DAY=3 # Max 3x täglichmake down && make up # Alles neu starten
make rebuild # Force rebuild
make clean # Aufräumen + neu startenmake logs # Alle Services
make logs-backend # Nur Backend
make logs-influxdb # Nur InfluxDB| Problem | Ursache | Lösung |
|---|---|---|
| ❌ InfluxDB startet nicht | Falsche Permissions | sudo chown -R $USER /opt/planetplant |
| ❌ MQTT Verbindung fehlschlägt | Firewall blockiert | sudo ufw allow 1883 |
| ❌ Frontend nicht erreichbar | Nginx-Config Fehler | make logs-frontend |
| ❌ Hohe RAM-Nutzung | Resource Limits | docker stats → Limits anpassen |
| ❌ ESP32 verbindet nicht | WiFi-Probleme | Reset-Button halten beim Start |
GET /api/plants # Alle Pflanzen
GET /api/plants/:id # Spezifische Pflanze
GET /api/plants/:id/current # Aktuelle Sensor-Daten
POST /api/plants/:id/water # Manuelle Bewässerung
PUT /api/plants/:id/config # Pflanze konfigurierenGET /api/system/status # System-Status
GET /api/system/stats # Performance-Metriken
GET /api/alerts/active # Aktive Alerts# Abhängigkeiten installieren
make install
# Development starten
make dev
# Tests laufen lassen
make test
# Code-Qualität prüfen
make lint- Node.js 20 mit Express.js
- InfluxDB 2.7 für Zeitserien-Daten
- Redis 7.2 für Caching
- Mosquitto MQTT 2.0 für IoT-Kommunikation
- React 18.3 mit Vite 5.4
- Tailwind CSS 3.4 für Styling
- Recharts für Datenvisualisierung
- PWA mit Service Worker
- Docker Compose für Service-Orchestrierung
- Nginx als Reverse Proxy
- Grafana 10.2 für Advanced Monitoring
- ARM64 optimierte Container
MIT License
Made with 💚 for plants and IoT enthusiasts
PlanetPlant - Because every plant deserves smart care! 🌱