Skip to content
Snippets Groups Projects
Commit 5e68cdf6 authored by Kendra Tyler's avatar Kendra Tyler
Browse files

Project IOT

parent e78ee8ed
No related branches found
No related tags found
No related merge requests found
import pandas as pd
import serial
from flask import Flask, render_template
import csv
# Establish serial connection with Arduino
ser = serial.Serial('COM11', 9600)
while True:
# read data created by the Arduino
data = ser.readline().decode().strip() # assuming the data is in string format and each line contains one data point
# create a DataFrame with the data
df = pd.DataFrame({'Time of incident ': [data]})
# append the DataFrame to the CSV file
with open('data.csv', 'a', newline='') as f:
writer = csv.writer(f)
writer.writerow(df['Time of incident '])
print(df)
\ No newline at end of file
File added
File added
from flask import Flask, render_template
import csv
app = Flask(__name__)
@app.route('/', methods = ["GET", "POST"])
def index():
table_data = []
with open('data.csv', 'r') as csvfile:
csvreader = csv.reader(csvfile)
for row in csvreader:
table_data.append(row)
return render_template('index.html', table_data=table_data)
@app.route('/login', methods = ["GET", "POST"])
def login():
return render_template('login.html')
if __name__ == '__main__':
app.run(debug=True)
0:4:20
0:4:40
#include <Wire.h>
#include <rgb_lcd.h>
#include <TimeLib.h>
#include <time.h>
rgb_lcd lcd;
int soundSensorPin = 4;
int motionSensorPin = 3;
int buttonPin = 2;
bool messageSent = false;
bool sensorsEnabled = true;
unsigned long lastMessageTime = 0;
String Dt = ""; // Store time and date of message sending
time_t getTime() {
return time(nullptr);
}
void setup() {
pinMode(soundSensorPin, INPUT);
pinMode(motionSensorPin, INPUT);
pinMode(buttonPin, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.setRGB(0, 255, 0);
lcd.setCursor(0, 0);
lcd.print("OK");
setSyncProvider(getTime);
if (timeStatus() != timeSet) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("NO TIME SET");
lcd.setRGB(255, 0, 0);
}
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int soundLevel = analogRead(soundSensorPin) / 4; // Divide by 4 to make sensor less sensitive
int motionState = digitalRead(motionSensorPin);
int buttonState = digitalRead(buttonPin);
if (sensorsEnabled && (soundLevel > 100 || motionState == HIGH) && (millis() - lastMessageTime > 20000)) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("MESSAGE SENT");
lcd.setRGB(255, 0, 0);
messageSent = true;
lastMessageTime = millis();
Dt = String(hour()) + ":" + String(minute()) + ":" + String(second()); // Store time and date
Serial.print(Dt); // print the date to the serial port
Serial.println(); // print a new line character to end the message
delay(10000); // Delay for 10 seconds before going back to "OK"
}
else if (messageSent && (millis() - lastMessageTime > 10000)) {
messageSent = false;
lcd.setRGB(0, 255, 0);
lcd.setCursor(0, 0);
lcd.print("OK "); // Add extra spaces to clear "SSAGE"
Dt = ""; // Reset data
}
else {
lcd.setRGB(0, 255, 0);
lcd.setCursor(0, 0);
lcd.print("OK "); // Add extra spaces to clear "SSAGE"
}
if (buttonState == LOW) {
sensorsEnabled = !sensorsEnabled; // Toggle sensors enabled/disabled
delay(1000); // Delay to debounce button
}
if (!sensorsEnabled) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SENSORS DISABLED");
lcd.setRGB(255, 255, 0);
}
delay(100); // Add a small delay to reduce sensor noise
}
\ No newline at end of file
/* Global styles */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
/* Header styles */
header {
background-color: #333;
color: #fff;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
}
.header-controls {
display: flex;
justify-content: flex-end;
align-items: center;
}
button {
background-color: #fff;
border: none;
color: #333;
cursor: pointer;
font-size: 16px;
margin-left: 10px;
padding: 8px 16px;
}
#home_button:hover, #login_button:hover {
background-color: #ddd;
}
/* Latest Feed styles */
h1 {
font-size: 24px;
font-weight: bold;
margin: 20px;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: calc(100vh - 88px); /* subtract header height (50px) */
}
.picture {
border: 1px solid #ccc;
height: 200px;
margin-top: 20px;
width: 300px;
}
.picture img {
display: block;
max-width: 100%;
height: auto;
}
<!DOCTYPE html>
<html>
<head>
<title>Watch Out</title>
<link rel="stylesheet" type="text/css" href="/static/styles.css">
</head>
<body>
<header>
<h2>Watch Out!</h2>
<div class="header-controls">
<form action="{{ url_for('index') }}" method="POST">
<button type="submit" id="home_button" name="home_button" value="home_button">Home</button>
</form>
<form action="{{ url_for('login') }}" method="POST">
<button type="submit" id="long_button" name="login_button" value="login_button">Login</button>
</form>
</div>
</header>
<div class="container">
<h1>Latest Feed</h1>
<table>
{% for row in table_data %}
<tr>
{% for item in row %}
<td>{{ item }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" type="text/css" href="static/styles.css">
</head>
<body>
<h1>Login Page</h1>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment