Skip to content

cosmologist10/irrigation-system

Repository files navigation

Automated Irrigation System

CI

A full-stack IoT application for automated plant irrigation with real-time moisture monitoring. Built with Rust backend and React frontend.

Features

  • Real-time Monitoring - Track soil moisture levels with interactive charts
  • Automated Irrigation - Configurable thresholds trigger watering automatically
  • Manual Override - One-click manual irrigation control
  • Multi-timeframe Views - View data by hour, day, week, or month
  • Configurable Parameters - Adjust irrigation duration, intervals, and thresholds
  • Time-series Storage - Efficient multi-granularity data aggregation

Tech Stack

Layer Technology
Backend Rust, Rocket 0.5, MongoDB
Frontend React 18, TypeScript, Tailwind CSS, Visx
Database MongoDB 6
Infrastructure Docker, Docker Compose, GitHub Actions

Architecture

┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│   ESP8266/RPi   │────▶│   Rust Backend  │◀────│  React Frontend │
│  (Sensor Data)  │     │   (Rocket API)  │     │   (Dashboard)   │
└─────────────────┘     └────────┬────────┘     └─────────────────┘
                                 │
                        ┌────────▼────────┐
                        │    MongoDB      │
                        │  (Time-series)  │
                        └─────────────────┘

Quick Start (Docker)

The easiest way to run the project:

# Clone the repository
git clone https://github.com/cosmologist10/irrigation-system.git
cd irrigation-system

# Start all services
docker-compose up -d

# Open the dashboard
open http://localhost:3000

This starts:

Demo Mode

To see the system in action without real sensors:

# Seed historical data (past 7 days)
python scripts/demo_simulator.py --seed

# Run continuous simulation (live data)
python scripts/demo_simulator.py --continuous

Development Setup

Prerequisites

  • Rust 1.70+ (rustup)
  • Node.js 18+ (nvm)
  • MongoDB 6+

Backend

# Copy environment file
cp .env.example .env

# Start MongoDB (if not using Docker)
mongod --dbpath /path/to/data

# Run the backend
cargo run

The API will be available at http://localhost:8000.

Frontend

cd frontend

# Install dependencies
npm install

# Start development server
npm start

The dashboard will be available at http://localhost:3000.

API Endpoints

Method Endpoint Description
POST /app/measurement Submit new sensor reading
GET /app/get_last_day_measurements/:sensor Get last 24 hours data
GET /app/get_last_week_measurements/:sensor Get last 7 days data
GET /app/get_last_hour_measurements/:sensor Get last 60 minutes data
GET /app/get_last_month_measurements/:sensor Get last 30 days data
GET /app/sensors List all configured sensors
GET /app/sensors/irrigation/:sensor Trigger manual irrigation
GET /app/irrigations/:sensor Get irrigation history
GET /app/preferences/:sensor Get sensor preferences
POST /app/preferences/:sensor Update sensor preferences

Example: Submit Measurement

curl -X POST http://localhost:8000/app/measurement \
  -H "Content-Type: application/json" \
  -d '{"sensor_name": "plant_1", "capacity": 650}'

Configuration

Environment Variables

Variable Description Default
MONGODB_URI MongoDB connection string mongodb://localhost:27017
ROCKET_ADDRESS Server bind address 0.0.0.0
ROCKET_PORT Server port 8000
REACT_APP_API_URL Backend URL for frontend http://localhost:8000

Sensor Preferences

Each sensor can be configured with:

  • Irrigation Time - How long to water (seconds)
  • Minimum Interval - Cooldown between irrigations (minutes)
  • Capacity Buffer - Moisture threshold to trigger irrigation
  • Signal Pin - GPIO pin for relay control (Raspberry Pi)

Project Structure

irrigation-system/
├── src/                    # Rust backend
│   ├── main.rs            # Entry point
│   ├── lib.rs             # App initialization & CORS
│   ├── models/            # Data models
│   ├── repository/        # Database layer
│   └── routes/            # HTTP endpoints
├── frontend/              # React frontend
│   ├── src/
│   │   ├── components/    # React components
│   │   │   ├── Graph/     # Data visualization
│   │   │   └── ControlPanel/  # Settings UI
│   │   └── constants/     # Configuration
│   └── package.json
├── scripts/               # Utility scripts
│   └── demo_simulator.py  # Demo data generator
├── docker-compose.yml     # Container orchestration
├── Dockerfile             # Backend container
└── .github/workflows/     # CI/CD pipeline

Hardware Setup (Optional)

For actual deployment with sensors:

Components

  • Raspberry Pi Zero W
  • Capacitive Soil Moisture Sensor
  • 5V Relay Module
  • 12V Water Pump

Wiring

Raspberry Pi GPIO 18 ──▶ Relay IN
Relay COM ──▶ 12V Power Supply
Relay NO ──▶ Water Pump (+)

Testing

# Run backend tests
cargo test

# Run with verbose output
cargo test --verbose

# Run frontend type checking
cd frontend && npx tsc --noEmit

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under MIT - see the LICENSE file for details.

Acknowledgments

Inspired by PatrickHallek/automated-irrigation-system, reimplemented with a Rust backend for better performance and type safety.

About

Automated irrigation system written in Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •