This project is a lightweight Python-based alarm system that plays a sound whenever your device loses Internet connectivity. The project is not tested, only coded! It continuously checks your connection and alerts you instantly if the network goes down.
Itβs ideal for monitoring unstable WiβFi, servers, routers, or any setup where connection uptime is important.
requests librarypygame library
import time
import requests
import pygame
# Initialize pygame mixer
pygame.mixer.init()
# Path to your sound file
SOUND_FILE = "soundfile.mp3"
def is_connected():
try:
requests.get('https://www.google.com', timeout=5)
return True
except requests.ConnectionError:
return False
def play_sound():
try:
pygame.mixer.music.load(SOUND_FILE)
pygame.mixer.music.play()
while pygame.mixer.music.get_busy():
time.sleep(0.1)
except Exception as e:
print(f"Error playing sound: {e}")
def monitor_connection(check_interval=5):
while True:
if not is_connected():
print("Internet connection dropped. Playing sound...")
play_sound()
else:
print("Internet connection is up.")
time.sleep(check_interval)
if __name__ == "__main__":
monitor_connection()
You can replace the sound file with any alert tone you prefer.