The Power Alert System is a Python script designed to monitor your network for power outages. It checks if your modem and router are online. If they are, it proceeds to monitor other specified devices. The script sends email notifications when devices go offline or come back online, keeping you updated on your network status.
Recommendation: This script is particularly useful for systems where the network infrastructure (modem, router, and server) is separate from the monitored devices. It ensures that monitoring only begins once the core network is fully operational. For improved reliability, it is recommended to use at least two devices for monitoring: one connected via Ethernet and another via Wi-Fi. This setup helps ensure that network issues affecting one connection type do not prevent the detection of network problems. Tested on Raspberry Pi 4.
smtplib, email, locale (included with Python)Email Configuration:
The script supports sending emails using various SMTP servers. You can configure the script to use your preferred email service by adjusting the SMTP settings. Here are some examples:
Make sure to replace the placeholder values with your actual email settings:
sender_email = "SENDER_EMAIL"
sender_password = "SENDER_EMAIL_PASSWORD"
receiver_emails = ["RECEIVER_EMAIL_1", "RECEIVER_EMAIL_2"]
smtp_server = "SMTP_SERVER" # e.g., smtp.office365.com for Outlook
smtp_port = 587Device IPs:
Set the IP addresses of the devices you want to monitor:
device_ips = ['192.168.0.23', '192.168.0.9']Configure the IP addresses for your modem and router:
modem_ip = '192.168.1.254'
router_ip = '192.168.0.1'Locale Setting: The script is configured to use a default locale for date and time formatting, specifically 'C', to ensure consistent behavior across different systems. If you need a different locale, you can adjust the following line:
locale.setlocale(locale.LC_TIME, 'C') # Default localeRun the Script:
Execute the script using Python:
python power_alert.pyScript Behavior:
Robustness for Service Use: This script is designed to be reliable for use as a service. It ensures that the monitoring and notification processes are resilient to network infrastructure changes. Specifically:
Ensure you have network access to the devices and email server specified.
Adjust the time.sleep(10) interval as needed for your monitoring frequency.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.