A full-stack web application built with Flask (backend) and React (frontend) that monitors plant sensor data and uses machine learning to predict optimal watering times based on weather conditions.
- User Authentication: Secure login and registration with session-based authentication
- Plant Management: Add, select, and manage multiple plants with unique sensor IDs
- Real-time Sensor Monitoring: Displays Light, Soil Moisture, and Temperature data
- National Weather Service Integration: Fetches current weather data from the NWS API
- ML-Powered Predictions: Uses a trained model to predict when to water your plant based on:
- Current soil moisture
- Environmental conditions (temperature, light)
- Weather forecast (humidity, precipitation, wind speed)
- Evapotranspiration calculations
- Plant Health Score: Calculated health score based on sensor data with detailed breakdown
- AI Chatbot: OpenAI-powered chatbot for plant care advice (requires API key)
- Data Visualization: Interactive charts showing sensor data trends and watering predictions
- Location Settings: Set your location for accurate weather data
- Modern UI: Beautiful, responsive React interface with white theme
SmartPlantAssistant/
├── backend/ # Flask API server
│ ├── app.py # Main Flask application
│ └── requirements.txt
├── frontend/ # React frontend
│ ├── src/
│ │ ├── components/ # React components
│ │ ├── services/ # API service layer
│ │ ├── App.js
│ │ └── index.js
│ └── package.json
└── README.md
- Python 3.8+ (backend)
- Node.js 14+ and npm (frontend)
- Neon Postgres database (free tier available at neon.tech)
- OpenAI API key (optional, for chatbot functionality)
Create a .env file in the project root with the following:
# Neon Postgres Database URL (required)
DATABASE_URL=postgresql://username:password@ep-xxxxx.us-east-2.aws.neon.tech/neondb?sslmode=require
# Flask Secret Key (required for sessions)
SECRET_KEY=your-secret-key-here
# NWS (National Weather Service) API User-Agent (required for weather)
# Format: AppName-your.email@domain.com
NWS_USER_AGENT=SmartPlantAssistant-your.email@example.com
# OpenAI API Key (optional, for chatbot functionality)
OPENAI_API_KEY=your_openai_api_key_hereImportant: Never commit your .env file to version control. It's already in .gitignore.
-
Navigate to the backend directory:
cd backend -
Create a virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Initialize the database (first time only):
python3 -c "from app import app, db; app.app_context().push(); db.create_all(); print('✅ Database tables created')" -
Run the Flask server:
python app.py
The backend will run on
http://localhost:5001(port 5000 is often used by macOS AirPlay Receiver)
-
Navigate to the frontend directory:
cd frontend -
Install dependencies:
npm install
-
Start the React development server:
npm start
The frontend will run on
http://localhost:3001and automatically proxy API requests to the backend.
Use the provided start script:
./start.shThis will start both the backend and frontend servers. To stop them:
./stop.shPOST /api/register- Register a new userPOST /api/login- Login userPOST /api/logout- Logout userGET /api/user- Get current user information
GET /api/sensor-data- Get current sensor readings for selected plantPOST /api/sensor-data- Update sensor data (for actual sensor integration)
GET /api/weather- Get weather data from NWS API (uses user's saved location)PUT /api/user/location- Update user's location
GET /api/plants- Get all user's plantsPOST /api/plants- Create a new plantPUT /api/plants/<id>- Update a plantDELETE /api/plants/<id>- Delete a plant
POST /api/predict- Get watering prediction based on sensor and weather dataGET /api/plant-health/<plant_id>- Get plant health score
POST /api/chat- Send message to AI chatbot (requires OpenAI API key)
This project includes scripts for connecting Raspberry Pi sensors (AHT20, BH1750, Arduino I2C soil moisture) directly to the Neon database.
-
SSH into your Raspberry Pi and navigate to the project directory
-
Install sensor dependencies:
pip3 install --user --break-system-packages psycopg2-binary python-dotenv adafruit-blinka adafruit-circuitpython-ahtx0 adafruit-circuitpython-bh1750 RPi.GPIO
-
Set up environment variables (create
~/.envor use systemd service):DATABASE_URL=postgresql://username:password@ep-xxxxx.us-east-2.aws.neon.tech/neondb?sslmode=require PLANT_ID=1 -
Set up automatic readings (every 10 seconds):
cd raspberry_pi chmod +x setup_10_second_readings.sh sudo ./setup_10_second_readings.sh -
Check service status:
sudo systemctl status smart-plant-sensor.service
See raspberry_pi/README.md for detailed setup instructions and troubleshooting.
- Backend: Flask, Python, NumPy, SQLAlchemy, Flask-Login
- Frontend: React, Chart.js, Axios
- ML: Custom neural network model for predictions
- APIs: National Weather Service API, OpenAI API (optional)
- Database: Neon Postgres (cloud-hosted, accessible from Raspberry Pi and backend)
- Authentication: Session-based with Flask-Login
Works in all modern browsers that support:
- ES6 JavaScript
- Fetch API
- Geolocation API
- Canvas API (for charts)
- The backend uses CORS to allow React frontend to communicate
- Sensor data comes from Raspberry Pi sensors connected to Neon Postgres database
- Weather data is fetched from NWS API based on user's saved location (must be set in Location Settings)
- Predictions update every 5 seconds along with sensor data
- All data displayed is real-time from physical sensors (no simulated data)
- Never commit your
.envfile to version control - The
.env.examplefile shows the required environment variables without sensitive data - Database files (
.db) are excluded from version control - Generate a strong SECRET_KEY for production deployments
[Add your license here]
[Add contributing guidelines if applicable]