Pi 5 watchdog on Chrome when stop play audio and send e-mail

Hi,
I have a raspberry pi 5 and I would like this:
1- Open a Full Screen web page with Chrome.
once the page is opened on my site the audio will start automatically. I managed this part with tutorials on the internet. It’s functional
But,

2- In Chrome, I want to check that the audio is playing and if it has stopped, send an email and restart the pi5.

:slight_smile:
Thank’s

Hi @daniel282384, welcome to the forums!

Glad to hear you’ve got step one working already! How exactly did you do this? It may narrow or broaden our options depending on the libraries and methods used, so more information on this would be super helpful.

My initial thoughts are that you may be able to use a watchdog application paired with some sort of resource monitor, that depends on exact configuration though.

1 Like

Thank you very much.
I have finaly make this on pyton but I am not able to place this script always on. i have test and I receved E-mail, that’s very cool but no work. Can you help me please? :slight_smile:

import os
import smtplib
from email.mime.text import MIMEText
import time

# Configuration
EMAIL_FROM = 'log@imagein.ca'
EMAIL_TO = 'danielduplain@me.com'
EMAIL_SUBJECT = 'Audio Marcel Pelchat dans Chrome est arrêté'
SMTP_SERVER = 'box22.domaineinternet.ca'
SMTP_PORT = 587
SMTP_USER = 'lALLO@imagein.ca'
SMTP_PASSWORD = '000000'

def send_email():
    msg = MIMEText("L'audio dans Chrome s'est arrêté.")
    msg['Subject'] = EMAIL_SUBJECT
    msg['From'] = EMAIL_FROM
    msg['To'] = EMAIL_TO

    with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as server:
        server.starttls()
        server.login(SMTP_USER, SMTP_PASSWORD)
        server.sendmail(EMAIL_FROM, EMAIL_TO, msg.as_string())

def check_audio():
    while True:
        # Vérifie si l'audio est actif
        audio_active = os.system("pactl list sink-inputs | grep -q 'RUNNING'") == 0
        
        if not audio_active:
            send_email()
            break
        
        time.sleep(10)  # Vérifie toutes les 10 secondes

if __name__ == "__main__":
    check_audio()

Hi Daniel,

There are a couple ways you can set your script to be always on. The easiest is to have a script that won’t end and to run it when you boot your Pi. In your script set a loop that will check for audio and if it can’t detect it send an email, some delay for it to send, and then reboot your Pi.

Here are some methods that you can use to run a script when your Pi boots.

Merci est-ce possible de me montrer car je suis très très debutant.
Thank’s it is possible to make for me please?
:slight_smile:

Hi @daniel282384,

It’s not quite possible for us to be able to setup for you as it requires it to be setup on the device and user that you want it to run on.

The link Jack sent through has fairly simple steps to follow to be able to get it up and working.
If you’re getting stuck you can ask for help.