diff --git a/Program/Webserver.py b/Program/Webserver.py index ac40cf4..b5bac0e 100644 --- a/Program/Webserver.py +++ b/Program/Webserver.py @@ -92,9 +92,14 @@ def update_mail(): smtp_server = request.form['smtp_server'] smtp_port = request.form['smtp_port'] recipient_email = request.form['recipient_email'] + max_hr = request.form['MAX_HR'] + max_temp = request.form['MAX_TEMP'] - # Update email settings in the database or perform any other actions + # Update email settings in the database update_email_settings(smtp_id, smtp_pwd, smtp_server, smtp_port, recipient_email) + # Update threshold settings in the database + update_threshold_settings(max_hr, max_temp) + # Redirect to a success page or render a template return redirect("/adm") diff --git a/Program/__pycache__/database.cpython-311.pyc b/Program/__pycache__/database.cpython-311.pyc index d1a0e1e..93015eb 100644 Binary files a/Program/__pycache__/database.cpython-311.pyc and b/Program/__pycache__/database.cpython-311.pyc differ diff --git a/Program/__pycache__/mail.cpython-311.pyc b/Program/__pycache__/mail.cpython-311.pyc index de6672d..97ee7b9 100644 Binary files a/Program/__pycache__/mail.cpython-311.pyc and b/Program/__pycache__/mail.cpython-311.pyc differ diff --git a/Program/database.py b/Program/database.py index 8388611..75a5d70 100644 --- a/Program/database.py +++ b/Program/database.py @@ -37,8 +37,8 @@ def create_database(db_name): smtp_server TEXT, smtp_port INTEGER, recipient_email TEXT, - MAX_HR INT - MAX_TEMP);''') + MAX_HR INT, + MAX_TEMP INT);''') c.execute("INSERT OR IGNORE INTO alert_settings (smtp_id, smtp_pwd, smtp_server, smtp_port, recipient_email, MAX_HR, MAX_TEMP) VALUES (?, ?, ?, ?, ?, ?, ?)", (SMTP_ID, SMTP_PWD, SMTP, SMTP_PORT, RECIPIENT, MAX_HR, MAX_TEMP)) @@ -135,10 +135,10 @@ def update_email_settings(smtp_id, smtp_pwd, smtp_server, smtp_port, recipient_e def update_threshold_settings(max_hr, max_temp): conn = sqlite3.connect(DBFILE) c = conn.cursor() - c.execute("UPDATE alert_settings SET smtp_id = ?, smtp_pwd = ? ", (smtp_id, smtp_pwd, smtp_server, smtp_port, recipient_email)) + c.execute("UPDATE alert_settings SET MAX_HR = ?, MAX_TEMP = ? ", (max_hr, max_temp)) conn.commit() - print(f"[{datetime.now()}] Web - Mail settings updated :") - print_email_settings() + print(f"[{datetime.now()}] Web - threshold settings updated :") + print_threshold_settings() conn.close() def print_email_settings(): @@ -164,6 +164,26 @@ def print_email_settings(): # Close the connection conn.close() +def print_threshold_settings(): + # Connect to the database + conn = sqlite3.connect(DBFILE) + c = conn.cursor() + + # Fetch threshold settings + c.execute("SELECT MAX_HR, MAX_TEMP FROM alert_settings") + settings = c.fetchone() + + # Print settings + if settings: + print("threshold Settings:") + print(f"MAX_HR: {settings[0]}") + print(f"MAX_TEMP:{settings[1]}") + else: + print("No threshold settings found in the database.") + + # Close the connection + conn.close + def history_graph_temp(): # Fetch sensor data sensorList = fetch_all_sensor() diff --git a/Program/mail.py b/Program/mail.py index 78cbb2a..cf3c028 100644 --- a/Program/mail.py +++ b/Program/mail.py @@ -72,17 +72,21 @@ def check_and_send_email(): # Retrieve the last record from SensorData table c.execute("SELECT * FROM SensorData ORDER BY Id DESC LIMIT 1") last_record = c.fetchone() + # Retrieve the threshold settings from Alert_settings table + c.execute("SELECT MAX_HR, MAX_TEMP FROM alert_settings") + threshold = c.fetchone() + print(threshold) if last_record: # Extract HR and Temp values from the last record _, sensor, time, temp, hr, _ = last_record # Check if HR or Temp exceed set values - if temp > MAX_HR: + if temp > threshold[1]: email(RECIPIENT, MESSAGE_TEMP, temp, sensor, time) - elif hr > MAX_TEMP: + if hr > threshold[0]: email(RECIPIENT, MESSAGE_HR, hr, sensor, time) - + else: print(f"[{datetime.now()}] Mail - No data found in the database.") diff --git a/Program/templates/admin.html b/Program/templates/admin.html index a54fb19..5124c45 100644 --- a/Program/templates/admin.html +++ b/Program/templates/admin.html @@ -112,7 +112,7 @@

-

Email Settings

+

Alert Settings

@@ -130,10 +130,10 @@

- +

- +