Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update project files.
  • Loading branch information
yousafs12 committed Aug 1, 2024
0 parents commit 3f3e057
Show file tree
Hide file tree
Showing 16 changed files with 402 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Smart Environment using MQTT/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Smart Environment using MQTT/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Smart Environment using MQTT/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Smart Environment using MQTT/.idea/pythonProject2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Smart Environment using MQTT/docs/METHODOLOGY.md
@@ -0,0 +1,13 @@
# Development Methodology

## Agile Methodology
We used Agile methodology to manage our project. The development process was divided into sprints, with each sprint lasting two weeks. During each sprint, we held daily stand-up meetings to discuss progress and any roadblocks.

## Tools Used
- **Version Control**: Git
- **Project Management**: Trello
- **Communication**: Slack
## Sprint Planning
- Defined user stories and tasks
- Prioritized the backlog
- Assigned tasks to team members
16 changes: 16 additions & 0 deletions Smart Environment using MQTT/docs/PROGRAMMING APPROACHES.md
@@ -0,0 +1,16 @@
# Programming Approaches and Different Technologies

## Technologies Used
- **Flask**: For creating the web server and API endpoints.
- **Plotly**: For creating interactive graphs and visualizations.
- **Paho MQTT**: For MQTT communication between sensors and the server.

## Why These Technologies?
- **Flask**: Lightweight and easy to set up for creating web applications.
- **Plotly**: Provides powerful graphing capabilities with interactive features.
- **Paho MQTT**: Reliable and efficient protocol for IoT communication.

## Programming Approaches
- **Modular Design**: Each component of the system (sensor integration, MQTT communication, web interface) is designed as a separate module.
- **Code Quality**: Ensured through code reviews, linters, and adhering to PEP 8 guidelines.
- **Testing**: Unit tests were written to verify the functionality of each module.
17 changes: 17 additions & 0 deletions Smart Environment using MQTT/docs/PROJECT_MANAGEMENT.md
@@ -0,0 +1,17 @@
# Project Management

## Roles and Responsibilities
- **Team Leader**: Het pate
- **Developer**: Kartik Sharma
- **UI/UX Designer**: Sami Yousaf

## Meeting Schedule
- **Weekly Meetings**: Every Monday at 10 AM

## Meeting Minutes
### Meeting on 2023-07-01
- **Attendees**: Het pate, Kartik Sharma, Sami Yousaf
- **Discussion Points**:
- Reviewed project progress
- Discussed next steps
- Assigned tasks for the coming week
15 changes: 15 additions & 0 deletions Smart Environment using MQTT/docs/Prototypes.md
@@ -0,0 +1,15 @@
# Project Prototype Ideas and Prototypes

## Ideation Process
- Brainstormed various ideas for environmental monitoring systems.
- Discussed the feasibility, cost, and impact of each idea.
- Selected the idea of a smart environmental monitoring system using MQTT.

## Prototypes
1. **Initial Prototype**: Basic system with data collection and MQTT communication.
2. **Second Prototype**: Added web interface with real-time graphs.
3. **Final Prototype**: Improved UI, optimized data handling, and added additional features.

## Iterations
- **Feedback**: Collected feedback from peers and advisors.
- **Improvements**: Made improvements based on feedback, such as enhancing the UI and optimizing data processing.
42 changes: 42 additions & 0 deletions Smart Environment using MQTT/docs/README.md
@@ -0,0 +1,42 @@
# Environmental Monitoring System

## Overview
This project implements a smart environmental monitoring and control system using MQTT, Flask, and Plotly. It displays real-time data from various sensors on a web interface.

## Features
- Real-time data monitoring
- Interactive web-based UI with graphs
- MQTT integration for data communication

## Setup Instructions
1. Install dependencies:
```bash
pip install -r requirements.txt
```

2. Run the Flask application:
```bash
python app.py
```
3. Access the web interface at `http://127.0.0.1:5000`.


## Usage
- The system continuously monitors environmental data and updates the web interface in real-time.
- Graphs for temperature, humidity, and CO2 levels are displayed on the web interface.

## System Explanation
- **Sensor Integration**: Collects data from various sensors (temperature, humidity, CO2).
- **MQTT Communication**: Sends sensor data to the server using the MQTT protocol.
- **Web Interface**: Displays real-time data using Flask and Plotly.

## Acknowledgements
We would like to thank ...

## Methodology
We followed the Agile methodology ...

## Contributors
- Het patel: Sensor integration and data collection
- Kartik Sharma: MQTT communication and device control
- Sami Yousaf : User interface development and data analysis
21 changes: 21 additions & 0 deletions Smart Environment using MQTT/docs/requirements.txt
@@ -0,0 +1,21 @@
blinker == 1.8.2
click == 8.1.7
colorama == 0.4.6
contourpy == 1.2.1
cycler == 0.12.1
Flask == 3.0.3
fonttools == 4.53.1
itsdangerous == 2.2.0
Jinja2 == 3.1.4
kiwisolver == 1.4.5
MarkupSafe == 2.1.5
matplotlib == 3.9.1
numpy == 2.0.1
packaging == 24.1
paho-mqtt == 2.1.0
pillow == 10.4.0
pip == 23.2.1
pyparsing == 3.1.2
python-dateutil == 2.9.0.post0
six == 1.16.0
Werkzeug == 3.0.3
53 changes: 53 additions & 0 deletions Smart Environment using MQTT/mqtt_communication.py
@@ -0,0 +1,53 @@
# mqtt_communication.py
import random

import paho.mqtt.client as mqtt
import json
import time

# MQTT settings
BROKER = "broker.hivemq.com"
PORT = 1883
TOPIC = "home/environment"

# Callback when a message is received
def on_message(client, userdata, message):
data = json.loads(message.payload.decode())
print(f"Received message: {data}")

# Example: Control devices based on received data
if data["temperature"] > 25:
print("Temperature is high, turning on the fan...")

elif data["temperature"] < 18: # Adjust the threshold value as needed
print("Temperature is low, turning on the heater...")
else:
print("Temperature is normal, turning off the fan and heater...")



def on_connect(client, userdata, flags, rc):
print("Connected to MQTT broker")
client.subscribe(TOPIC)

def publish_sensor_data(client, sensor_data):
client.publish(TOPIC, json.dumps(sensor_data))
print(f"Published sensor data: {sensor_data}")

if __name__ == "__main__":
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message

client.connect(BROKER, PORT, 60)
client.loop_start()

while True:
# Simulating data collection and publishing (this should come from Member 1)
sensor_data = {
"temperature": random.uniform(20.0, 30.0),
"humidity": random.uniform(30.0, 70.0),
"co2": random.uniform(400, 1000)
}
publish_sensor_data(client, sensor_data)
time.sleep(5)
40 changes: 40 additions & 0 deletions Smart Environment using MQTT/sensor_integration.py
@@ -0,0 +1,40 @@
# sensor_integration.py
import random
import time


# Simulating sensor data collection
def read_temperature():
# Code to read temperature from sensor
return random.uniform(20.0, 30.0)


def read_humidity():
# Code to read humidity from sensor
return random.uniform(30.0, 70.0)


def read_co2():
# Code to read CO2 levels from sensor
return random.uniform(400, 1000)


def collect_sensor_data():
while True:
temperature = read_temperature()
humidity = read_humidity()
co2 = read_co2()

sensor_data = {
"temperature": temperature,
"humidity": humidity,
"co2": co2
}

print(f"Collected sensor data: {sensor_data}")
# Simulate a delay between readings
time.sleep(5)


if __name__ == "__main__":
collect_sensor_data()
74 changes: 74 additions & 0 deletions Smart Environment using MQTT/templates/index.html
@@ -0,0 +1,74 @@
<!-- templates/index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Environmental Monitoring System</title>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<h1>Environmental Monitoring System</h1>

<div id="temperature-container" style="width:600px;">
<div id="temperature-graph" style="height:250px;"></div>
<p style="text-align: center;">Temperature (°C)</p>
</div>

<div id="humidity-container" style="width:600px;">
<div id="humidity-graph" style="height:250px;"></div>
<p style="text-align: center;">Humidity (%)</p>
</div>

<div id="co2-container" style="width:600px;">
<div id="co2-graph" style="height:250px;"></div>
<p style="text-align: center;">CO2 (ppm)</p>
</div>

<script>
function fetchData() {
fetch('/data')
.then(response => response.json())
.then(data => {
var time = data.time;
var temperature = data.temperature;
var humidity = data.humidity;
var co2 = data.co2;

var temp_trace = {
x: time,
y: temperature,
type: 'scatter',
mode: 'lines+markers',
name: 'Temperature',
line: {color: 'red'}
};

var humidity_trace = {
x: time,
y: humidity,
type: 'scatter',
mode: 'lines+markers',
name: 'Humidity',
line: {color: 'blue'}
};

var co2_trace = {
x: time,
y: co2,
type: 'scatter',
mode: 'lines+markers',
name: 'CO2',
line: {color: 'green'}
};

Plotly.newPlot('temperature-graph', [temp_trace]);
Plotly.newPlot('humidity-graph', [humidity_trace]);
Plotly.newPlot('co2-graph', [co2_trace]);
});
}

setInterval(fetchData, 5000); // Fetch data every 5 seconds
</script>
</body>
</html>

0 comments on commit 3f3e057

Please sign in to comment.