Friday, October 13, 2017

Making an embedded Audio PA System with a web based UI

In my post how to make digital signage and PA system using a google chrome box it worked well for a while but then we had issues with the audio announcements double playing, skipping or not playing at all.  It was very odd, so to rectify this issue I built a new PA system using an old Foxconn AMD E-350 AT-3350 with 4GB of RAM and loaded with Windows 7 Embedded.

The PA System run WAV files at a specified time using task scheduler.  This just opens the default player (windows media player in this case) and runs the file.  This means that the user must be logged into the system to run so if you setup RDP you will have to just disconnect (do not logout).  I also created a Web Based UI using XAMPP for Windows as the base Apache 2 install with minimal settings.  I've also used a 3rd party plugin called nircmd.  This allowed me to make a php file to run a mute/unmute command.  This machine has no access to the internet and is only accessible from the intranet due to security concerns.


Task Scheduler with the wave file schedule
I changed the root directory to a folder we will call PA.  In there I have a file called sound status which tracks if the sound is enabled or disabled.  This is loaded into the index.php file on load which uses a if else statement for displaying the status and the button.


Web Directory
The code for the php files that are executed using nircmd are setup like so


nircmd.exe mutesysvolume 0 - Sound is Enabled


nircmd.exe mutesysvolume 1 - Sound is Muted

The PHP files for enabling and disabling the sound are seperated out from the index.php file because it would run the mute/unmute commands when loading the page.  Lets go over the index file first.  We have the index file loading a txt file with a true or false value.  The sound is either on or off.  The we use a simple if statement to display if we are displaying the sound is on or off.
Code for the index.php file
The buttons for enabling and disabling the sound are php files which run the bat script for muting and unmuting the sound writes the new value to the soundstatus.txt file and then sends you back to the index.php page.


PHP Files for enabling and disabling sound
The PHP code is fairly simple.

system('cmd /c $YOURPATHTONIRCMD.EXE mutesysvolume 1');

as I described above this is the command for muting the sound, using the NIRCMD utility.

Then I built used a responsive web based UI for enabling and disabling the sound.


PA System Desktop Showing Sound Enabled


PA System Desktop Showing Sound Disabled


PA System on Mobile
UPDATE!

To reset the PA System Audio to enabled I setup a task scheduler event to run a bat file that runs nircmd.exe mutesysvolume 0 at 6:00 am.  With this in mind you also need to update the soundstatus.txt file so when the GUI load it registers that the sound has been re-enabled.  To do that I decided to use powershell, specifically the Out-File utility.
"on" | Out-File $PATHTO\TEXTFILE.txt

Now by doing this if I want to run it as a .ps1 file I need to allow powershell scripts to run the powershell scripts you run powershell as an administrator and 

Set-ExecutionPolicy Unrestricted

Now this IS a security risk and I will be looking to make something that is more secure in the future, in the mean time it is a stopgap measure that his acceptable since the access to the device is intranet on port 80 and RDP only.  The script above leaves some forward character garbage so I also changed the lookup logic of the PHP file to look and see if the sound is off.  This way be default it assumes the sound is on, and only checks to see if the sound has been disabled.

Hyper-V Cluster Node Keeps Randomly Going Down

Over the last few weeks I had an issue with a Hyper-V Cluster node randomly going down causing issues with my Hyper-V cluster. Looking at th...