End goal:
I have a partial solution - I will put that in my 2nd post on this topic!
My end goal is to get an audio alert zone played by my systems speaker (NOT THROUGH THE WEB PAGE) whenever a specific Zone is triggered on 1 of my monitors. For now, Im just testing with a general filter before I add in a specific zone to the filter.
The Issue/Problem
The filter I created seems to execute the command HOWEVER, all that happens is mpg123 starts up with a slightly strange command line (indicated on the included image) and it then goes to 100% of a CPU core and nothing happens.
Strange command line example, something such as "/media/camera/cameravideos/7/2023-07-09/705037" gets added to the command line (please see the below image on the right side)
I have followed both:
https://bkjaya.wordpress.com/2020/11/08 ... -a-motion/
viewtopic.php?p=122000&hilit=mp3#p122000
Steps I have performed
- Installed mpg123 "sudo apt install mpg123"
- Created the "sounds" folder and moved my mp3 file into it "sudo mkdir /usr/share/zoneminder/www/sounds"
- Performed "sudo chmodd 777 frontdoor.mp3" on the mp3 file (and other mp3 file).
- Edited my "sudoers.d" file and added bypass of permissions there on the mp3 files.
- Created the filter as a very simple filter and confirmed its settings as per instructions.
- Rebooted my system after ALL these changes.
- tested "mpg123 /usr/share/zoneminder/www/sounds/frontdoor.mp3" when logged in at the command line and it works fine.
- tested "mpg123 /usr/share/zoneminder/www/sounds/frontdoor.mp3 /media/camera/cameravideos/7/2023-07-09/705037" when logged in and that appears to work fine too!
Additional note
I have also noted this post viewtopic.php?t=31677 about the WEB_SOUND_ON_ALARM setting being reworked recently, however I believe that is unrelated to what I am doing here.
Does anyone have any thoughts?
Many thanks!
Zoneminder Audio Alerts using mpg123
Re: Zoneminder Audio Alerts using mpg123
The reason it doesnt play, is because when using the system account to play a sound, the audio card is not started/running in that user session (the system account).
As such, you have to re-direct the audio output to an actual user session, assumedly a user that is logged in. There may be other solutions to this, that Im missing, however, this is how I have gotten it to work! (Ubuntu).
- Follow the previous posts instructions to move the mp3 files to the folder you want AND set those file permissions.
- Install the expect utility "sudo apt-get install expect"
- Create a bash file pointing to the file you want to play the sound of. In this file you will add the username AND password (yes not very secure) of the user account and therefore user session you want to play the sound from. As I said, a currently logged in user. The bash file should look something like the following:
Change the MYUSERACCOUNT and MYPASSWORD to the user account and password you want to use.
Save your bash file to the location you want to run it from and then chmod its permissions so that it can be executed e.g. chmod 777 myfile.sh (or whatever security permissions you wish to set.... 777 isnt great security wise). I called my file "playfront.sh"
Back in your filter screen, run the command with "expect" NOT bash.
create the rest of the filter settings as you wish and ensure you have it set to "run in background".
It works..... though Im now working on how to make my actual filter settings correct, but I now have sound playing when things trigger.
As I say, there probably are MUCH better solutions out there and anyone is welcome to chip in with a better answer/solution or thoughts!
As such, you have to re-direct the audio output to an actual user session, assumedly a user that is logged in. There may be other solutions to this, that Im missing, however, this is how I have gotten it to work! (Ubuntu).
- Follow the previous posts instructions to move the mp3 files to the folder you want AND set those file permissions.
- Install the expect utility "sudo apt-get install expect"
- Create a bash file pointing to the file you want to play the sound of. In this file you will add the username AND password (yes not very secure) of the user account and therefore user session you want to play the sound from. As I said, a currently logged in user. The bash file should look something like the following:
Code: Select all
#!/usr/bin/expect -f
set target_user "MYUSERACCOUNT"
set password "MYPASSWORD"
set command_to_run "mpg123 /usr/share/zoneminder/www/sounds/frontdoor.mp3"
spawn su - "$target_user" -c "$command_to_run"
expect "Password:"
send "$password\r"
expect eof
Save your bash file to the location you want to run it from and then chmod its permissions so that it can be executed e.g. chmod 777 myfile.sh (or whatever security permissions you wish to set.... 777 isnt great security wise). I called my file "playfront.sh"
Back in your filter screen, run the command with "expect" NOT bash.
create the rest of the filter settings as you wish and ensure you have it set to "run in background".
It works..... though Im now working on how to make my actual filter settings correct, but I now have sound playing when things trigger.
As I say, there probably are MUCH better solutions out there and anyone is welcome to chip in with a better answer/solution or thoughts!