What is the main purpose of setting email alerts on sensor thresholds?
To notify users immediately when a sensor value goes above or below a set limit, helping to take quick action.
Click to reveal answer
beginner
Which Python library is commonly used on Raspberry Pi to send emails?
The smtplib library is commonly used to send emails from Python scripts on Raspberry Pi.
Click to reveal answer
beginner
Why do we check sensor values against thresholds in code?
To decide if the sensor reading is normal or if it needs attention, triggering alerts only when necessary.
Click to reveal answer
intermediate
What information do you need to send an email alert from Raspberry Pi?
You need the SMTP server address, sender email, receiver email, and login credentials if required.
Click to reveal answer
intermediate
How can you avoid sending too many email alerts when sensor values fluctuate around the threshold?
By adding a delay or checking if the alert was already sent recently to prevent repeated emails.
Click to reveal answer
Which Python module helps send emails from Raspberry Pi?
Atime
Bos
Csmtplib
Drandom
✗ Incorrect
The smtplib module is used to send emails using SMTP protocol.
What should you compare sensor data against to trigger an email alert?
ARandom numbers
BThreshold values
CCurrent time
DSensor ID
✗ Incorrect
Threshold values define limits that, when crossed, trigger alerts.
Which of these is NOT needed to send an email alert?
AReceiver email address
BSender email address
CSMTP server address
DSensor calibration data
✗ Incorrect
Sensor calibration data is unrelated to sending emails.
How can you prevent sending too many emails when sensor values hover near the threshold?
AAdd a delay or cooldown between alerts
BSend emails every second
CIgnore sensor data
DChange the sensor
✗ Incorrect
Adding a cooldown prevents repeated alerts for small fluctuations.
What is a good reason to use email alerts on Raspberry Pi sensors?
ATo get notified remotely about important sensor changes
BTo increase sensor power
CTo slow down the sensor
DTo decorate the Raspberry Pi
✗ Incorrect
Email alerts help users get notified remotely about sensor conditions.
Explain how you would set up an email alert system on a Raspberry Pi to notify when a temperature sensor exceeds a threshold.
Think about the steps from reading the sensor to sending the email.
You got /5 concepts.
Describe why it is important to manage how often email alerts are sent when monitoring sensor thresholds.
Consider what happens if alerts are sent too frequently.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of sending email alerts when a sensor value crosses a threshold on a Raspberry Pi?
easy
A. To store sensor data permanently in a database
B. To notify the user immediately about important sensor events
C. To increase the sensor's measurement accuracy
D. To reset the sensor automatically
Solution
Step 1: Understand the role of email alerts
Email alerts are used to inform users instantly when something important happens, like a sensor crossing a limit.
Step 2: Compare options with this purpose
Only To notify the user immediately about important sensor events matches this purpose. Options B, C, and D describe unrelated tasks.
Final Answer:
To notify the user immediately about important sensor events -> Option B
Quick Check:
Email alerts = notify user instantly [OK]
Hint: Email alerts are for instant notifications, not data storage [OK]
Common Mistakes:
Confusing alerts with data logging
Thinking alerts improve sensor accuracy
Assuming alerts reset hardware automatically
2. Which of the following Python code snippets correctly sends an email alert when a sensor value exceeds 50?
easy
A. if sensor_value > 50:
send_email_alert()
B. if sensor_value < 50
send_email_alert()
C. if sensor_value > 50
send_email_alert()
D. if sensor_value > 50:
send_email_alert
Solution
Step 1: Check Python if-statement syntax
Python requires a colon after the if condition and indentation for the block.
Step 2: Validate each option
if sensor_value > 50:
send_email_alert() has correct syntax and logic. if sensor_value < 50
send_email_alert() misses colon and wrong condition. if sensor_value > 50
send_email_alert() misses colon and indentation. if sensor_value > 50:
send_email_alert misses parentheses for function call.
Final Answer:
if sensor_value > 50:
send_email_alert() -> Option A
Quick Check:
Correct if syntax + function call = if sensor_value > 50:
send_email_alert() [OK]
Hint: Remember colon and indentation after if, and parentheses for function calls [OK]
Common Mistakes:
Missing colon after if condition
Forgetting parentheses when calling functions
Incorrect indentation causing syntax errors
3. Given the code below, what will be printed if sensor_value = 75?
def check_sensor(value):
if value > 70:
print("Alert: High sensor value!")
else:
print("Sensor value normal.")
check_sensor(sensor_value)
medium
A. Alert: High sensor value!
B. No output
C. Sensor value normal.
D. SyntaxError
Solution
Step 1: Analyze the condition with sensor_value = 75
Since 75 > 70, the if condition is true.
Step 2: Determine which print statement runs
The code prints "Alert: High sensor value!" because the if condition is met.
Final Answer:
Alert: High sensor value! -> Option A
Quick Check:
75 > 70 triggers alert print [OK]
Hint: Check if condition true or false to find printed message [OK]
Common Mistakes:
Confusing else output with if output
Assuming no output if condition true
Thinking code has syntax errors
4. The following code is intended to send an email alert if the sensor value is above 60, but it does not work. What is the error?
sensor_value = 65
if sensor_value > 60
send_email_alert()
medium
A. send_email_alert() is not defined
B. Indentation is incorrect
C. sensor_value should be a string
D. Missing colon after the if condition
Solution
Step 1: Check syntax of the if statement
The if statement is missing a colon at the end of the condition line.
Step 2: Identify the cause of failure
Without the colon, Python raises a syntax error and the code won't run.
Final Answer:
Missing colon after the if condition -> Option D
Quick Check:
if statement requires colon [:] [OK]
Hint: Always put a colon after if conditions in Python [OK]
Common Mistakes:
Forgetting colon after if condition
Assuming function is undefined without checking syntax first
Thinking sensor_value must be string
5. You want to send an email alert only once when the sensor value crosses above 80, not repeatedly while it stays above 80. Which approach is best to implement this on a Raspberry Pi?
hard
A. Restart the Raspberry Pi after each alert to reset the sensor
B. Send an email every time the sensor value is checked and above 80
C. Use a flag variable to track if alert was already sent and reset it when value goes below 80
D. Ignore sensor values below 80 and send emails continuously
Solution
Step 1: Understand the problem of repeated alerts
Sending emails repeatedly while the value stays high can spam the user.
Step 2: Use a flag to send alert only once
A flag variable remembers if alert was sent; reset it when value drops below threshold to allow future alerts.
Final Answer:
Use a flag variable to track if alert was already sent and reset it when value goes below 80 -> Option C
Quick Check:
Flag variable prevents repeated alerts [OK]
Hint: Track alert state with a flag to avoid repeated emails [OK]