Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
initialized alarm
  • Loading branch information
Mubaraq Olayinka committed Jul 21, 2024
1 parent 93ea0a6 commit 4e04d68
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Binary file added alarm.mp3
Binary file not shown.
10 changes: 8 additions & 2 deletions camera.py
Expand Up @@ -5,6 +5,7 @@
from datetime import datetime
import firebase_admin
from firebase_admin import credentials, storage
from playsound import playsound

# MQTT settings
MQTT_BROKER = "broker.hivemq.com"
Expand All @@ -15,6 +16,9 @@
FIREBASE_CREDENTIALS_PATH = "ServiceAccountKey.json"
FIREBASE_STORAGE_BUCKET = "only-motion-detector.appspot.com"

# Alarm sound file path
ALARM_SOUND_PATH = "alarm.mp3"

# Initialize Firebase Admin SDK
cred = credentials.Certificate(FIREBASE_CREDENTIALS_PATH)
firebase_admin.initialize_app(cred, {'storageBucket': FIREBASE_STORAGE_BUCKET})
Expand Down Expand Up @@ -88,10 +92,11 @@
cv2.rectangle(frame1_macbook, (x, y), (x + w, y + h), (0, 255, 0), 2)
motion_detected_macbook = True

# If motion is detected, publish to MQTT and print message
# If motion is detected, publish to MQTT, print message, and sound alarm
if motion_detected_macbook:
client.publish(MQTT_TOPIC, "Motion Detected (MacBook)")
print("Motion Detected (MacBook)")
playsound(ALARM_SOUND_PATH)

# Write the frame to the output file for MacBook camera
out_macbook.write(frame1_macbook)
Expand Down Expand Up @@ -121,10 +126,11 @@
cv2.rectangle(frame1_iphone, (x, y), (x + w, y + h), (0, 255, 0), 2)
motion_detected_iphone = True

# If motion is detected, publish to MQTT and print message
# If motion is detected, publish to MQTT, print message, and sound alarm
if motion_detected_iphone:
client.publish(MQTT_TOPIC, "Motion Detected (iPhone)")
print("Motion Detected (iPhone)")
playsound(ALARM_SOUND_PATH)

# Write the frame to the output file for iPhone camera (if available)
if iphone_camera.isOpened():
Expand Down

0 comments on commit 4e04d68

Please sign in to comment.