update
This commit is contained in:
parent
660ae4a448
commit
1d27aa26e9
@ -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")
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -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()
|
||||
|
||||
@ -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.")
|
||||
|
||||
|
||||
@ -112,7 +112,7 @@
|
||||
<br><br>
|
||||
<button type="submit">Rename Sensor</button>
|
||||
</form>
|
||||
<h1>Email Settings</h1>
|
||||
<h1>Alert Settings</h1>
|
||||
<form method="post" action="/updateMail">
|
||||
<label for="smtp_id">Sender Email:</label>
|
||||
<input type="email" id="smtp_id" name="smtp_id" value="{{ email_settings[0] }}">
|
||||
@ -130,10 +130,10 @@
|
||||
<input type="email" id="recipient_email" name="recipient_email" value="{{ email_settings[4] }}">
|
||||
<br><br>
|
||||
<label for="MAX_TEMP">Temperature max threshold:</label>
|
||||
<input type="number" id="MAX_TEMP" name="MAX_TEMP" value="{{ threshold_settings[0] }}">
|
||||
<input type="number" id="MAX_TEMP" name="MAX_TEMP" value="{{ threshold_settings[1] }}">
|
||||
<br><br>
|
||||
<label for="MAX_HR">HR max threshold:</label>
|
||||
<input type="number" id="MAX_HR" name="MAX_HR" value="{{ threshold_settings[1] }}">
|
||||
<input type="number" id="MAX_HR" name="MAX_HR" value="{{ threshold_settings[0] }}">
|
||||
<br><br>
|
||||
<button type="submit">Save Settings</button>
|
||||
</form>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user