Weather Monitoring System tracks weather in major Indian metros using OpenWeatherMap API. It features live data collection, alerts for threshold breaches, and daily analytics. Built with React, Node.js, and MongoDB, it displays current conditions and trends via an interactive dashboard. Includes email alerts and supports both Celsius/Fahrenheit.
This project is a Real-Time Data Processing System for Weather Monitoring designed to collect weather data, perform real-time analysis, and provide insights using rollups and aggregates. The application leverages data from the OpenWeatherMap API to monitor weather conditions across key Indian metropolitan cities and generate summarized insights.
-
Real-Time Data Collection:
- Continuous retrieval of weather data for Indian metros: Delhi, Mumbai, Chennai, Bangalore, Kolkata, and Hyderabad.
- Fetches current temperature, perceived temperature, humidity, wind speed, and main weather conditions at configurable intervals (default: 5 minutes).
-
Data Processing & Aggregation:
- Converts temperature values from Kelvin to Celsius (or Fahrenheit based on user preference).
- Performs daily rollups to calculate:
- Average Temperature
- Maximum Temperature
- Minimum Temperature
- Dominant Weather Condition (determined by frequency of occurrence).
- Data is stored in a MongoDB database for further analysis.
-
Alerting System:
- User-configurable thresholds for alerts based on temperature and other weather conditions.
- Automatic alert generation when conditions exceed thresholds (e.g., temperature above 35°C for two consecutive updates).
- Alerts can be acknowledged through the interface.
-
Visualizations:
- Real-time dashboard displaying current weather data.
- Historical temperature trends and daily summaries.
- Active alerts and threshold management.
- Frontend: React.js with Recharts for visualization, CSS for styling.
- Backend: Node.js, Express.js for REST API.
- Database: MongoDB for storing weather data and summaries.
- Data Source: OpenWeatherMap API.
- Alert Notifications: Nodemailer for email notifications.
- Environment Management: dotenv for managing environment variables.
├── client
│ ├── components
│ │ ├── WeatherDashboard.jsx # Main weather dashboard component
│ │ ├── droplet.jsx # Animated component for visualizing humidity
│ └── services
│ └── api.js # Frontend API service for communicating with the backend
├── server
│ ├── controllers
│ │ ├── weatherController.js # Controller for weather data operations
│ │ └── alertController.js # Controller for alert management
│ ├── services
│ │ ├── dataRetrievalService.js # Service for fetching data from OpenWeatherMap API
│ │ ├── dataProcessingService.js # Service for calculating daily weather summaries
│ │ └── alertService.js # Service for managing alert thresholds and notifications
│ ├── models # MongoDB schemas for data
│ ├── routes
│ │ └── api.js # API routes for weather data and alerts
│ ├── app.js # Main server file
│ └── config # Configuration files for server setup
- Node.js (>=14.x)
- MongoDB instance
- Docker: Required to set up and run MongoDB container.
- OpenWeatherMap API Key (sign up here to get a free API key)
- Git
-
Clone the repository:
git clone <repository_url> cd <repository_name>
-
Pull Docker Image
docker pull hit4man47/weather-mongo-image:latest
-
Run the Docker Container
docker run -d -p 27017:27017 --name weather-mongo-db hit4man47/weather-mongo-image:latest
-
Install server dependencies:
cd server npm install -
Set up environment variables:
Create a
.envfile in theserverdirectory with the following values:PORT=3000 MONGODB_URI=mongodb://localhost:27017/weather-monitoring OPENWEATHER_API_KEY=<your_openweather_api_key> EMAIL_USER=<your_email> EMAIL_PASS=<your_email_password> ALERT_EMAIL_RECIPIENT=<alert_recipient_email>
-
Start the server:
npm start
-
Install client dependencies:
cd ../client npm install -
Run the client:
npm run dev
-
Access the application:
Open your browser and navigate to
http://localhost:5173.
GET /api/weather/:city: Fetch current weather for a city.GET /api/weather/daily-summary/:city: Fetch daily weather summary for a city.GET /api/weather/history/:city: Fetch weather history (24-hour) for a city.
GET /api/alerts/:city: Retrieve active alerts for a city.POST /api/alerts/threshold: Create a new alert threshold.PUT /api/alerts/threshold/:id: Update an existing threshold.DELETE /api/alerts/threshold/:id: Delete an alert threshold.PUT /api/alerts/acknowledge/:id: Acknowledge an alert.
- Pull Image:
docker pull hit4man47/weather-mongo-image:latest
- Run Container:
docker run -d -p 27017:27017 --name weather-mongo-db hit4man47/weather-mongo-image:latest
- Stop Container:
docker stop weather-mongo-db
- Remove container:
docker rm weather-mongo-db
-
Real-time Data Collection:
- Chose Axios for reliable API calls to OpenWeatherMap.
- Data is stored in a raw format in MongoDB for historical analysis.
-
Data Aggregation:
- Daily summaries are processed using scheduled intervals.
- Aggregates are calculated for each day to identify key patterns (e.g., average temperature, dominant weather).
-
Alerting System:
- Alerts are generated based on user-defined thresholds.
- Email notifications are implemented using Nodemailer, which is easy to configure for SMTP.
-
Frontend Visualization:
- Recharts library is used for intuitive data visualization (e.g., line charts, area charts).
- The dashboard supports switching between Celsius and Fahrenheit based on user preference.
-
System Setup:
- Test if the server starts successfully and connects to the MongoDB instance.
- Validate successful API connection to OpenWeatherMap using a valid API key.
-
Data Retrieval:
- Simulate weather data fetching at configurable intervals.
- Ensure correct parsing of weather data, especially temperature conversion from Kelvin to Celsius.
-
Data Processing:
- Validate daily weather summary calculations (average, max, min temperatures).
- Test handling of edge cases (e.g., no data for a specific day).
-
Alert System:
- Configure and verify user thresholds for temperature.
- Simulate data that triggers alerts and ensure notifications are handled correctly.
- Add support for additional weather parameters (e.g., wind speed, humidity).
- Implement forecast retrieval using OpenWeatherMap’s prediction API.
- Improve visualization for long-term trends (e.g., monthly summaries).
- Extend alert system to support SMS notifications.
- Dockerize the application for easy deployment.
This project is licensed under the MIT License.
- OpenWeatherMap for providing the API service.
- Nodemailer for email alert functionality.
- Recharts for visualization components.