Prototype Minster Music Software

This Forum is for discussion about the development of the software to control the playing of the music in the Minster Nave and the bells in the Tower.

There will be two programs; both based on the original software but now running on two Pis.
Post Reply
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Prototype Minster Music Software

Post by TerryJC »

I have created an early prototype of the software to control the playing of music in the Nave. This code is based on the program created for the original system but includes only features for the playing of music. The program will run on a Raspberry Pi 3 and will perform the following functions using apscheduler for the timings and mpg123 for playing the music:
  1. Set the music volume using amixer by reference to a variable (nave_vol) containing the required level in percent.
  2. Check the time and start the music playing during opening hours. For this the variables hour and opening_hours will be set and referenced.
  3. Stop the music playing outside opening hours.
  4. Start the Wedding Sequence at 11 am and 2 pm.
The above functions have been implemented and partially checked. The following control functions are present in the code but there is no means to invoke them yet:
  1. Enable Late Hours. This will respond to the variable enable_late being set and will extend the Opening Hours to 10 pm.
  2. Change volume.
  3. Change track.
  4. Stop the music playing.
  5. Start the music playing.
  6. Stop the Wedding Sequence.
  7. Start the Wedding Sequence.
In addition there is a Monitor Performance Function written but not fully debugged. This is based on the code used in the River System.

I'll be adding one or two queries to this thread to ascertain the best way to establish communication for the control functions and the reading of the performance parameter,
Terry
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: Prototype Minster Music Software

Post by TerryJC »

Apart from the software functionality detailed in my first post there will be a method of communicating with the running code using a smartphone or computer. To achieve this I will be installing a Web Server on the Pi 3 to host the code for the devices to log into. The aim is to have the web page(s) provide access to the running Minster Music program to read and / or modify the variables used in the program. So for example the user might want to change the volume in the Nave, so the web software would modify nave_vol to set a new percentage.

What I need to know is what the best approach to communicating these variable values is. Following on from the River System evolution, should I perhaps install MySQL on the Pi 3 and have both the running software and the Web Server access this? Is there another way that makes more sense?

Apart from the communication between the running software and the Web Server there will also be a need for the Pi 3 to access the Pi Zero which will be controlling the chimes. I'm assuming that the database could also do that, but direct communications using the River System sockets code could also be used presumably.

Any thoughts?
Terry
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Prototype Minster Music Software

Post by hamishmb »

I think using a database would be quite an inefficient and complex way of doing this. It works for the river system because timing isn't critical, but it'd be best to use the Sockets code for this, I think.

I'll provide more thoughts a bit later.
Hamish
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: Prototype Minster Music Software

Post by TerryJC »

Hamish,

I was wondering about this myself and last night I realised that if we write a value to a database then it won't be acted on until something gets round to reading it. Not very useful if the Operator has just pressed the 'Next Track' button. :oops:

Thanks.
Terry
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Prototype Minster Music Software

Post by hamishmb »

Ah don't worry about it.

Hopefully I'll find some time to do this, but I think I might just need to rest over Christmas. We'll see - I'm a workaholic so chances are I'll end up doing stuff anyway :lol:
Hamish
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: Prototype Minster Music Software

Post by TerryJC »

Hamish,

I was going to have a go at this myself, but that might result in code that isn't very efficient or elegant. However, perhaps you could give me an outline of the approach you would take sometime?
Terry
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Prototype Minster Music Software

Post by hamishmb »

Yeah, definitely. Let me know when you'd like me to do that.

I'll probably need to do some calls with you and Penri about the mobile visitor GUI anyway, so makes sense to reciprocate for taking up some of your time for that.
Hamish
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: Prototype Minster Music Software

Post by TerryJC »

hamishmb wrote: 04/12/2020, 19:16Yeah, definitely. Let me know when you'd like me to do that.
My time is quite flexible, so perhaps we work around yours and Penri's availability.
Terry
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: Prototype Minster Music Software

Post by TerryJC »

Sitrep 1:

I have the basic MP3 Player working as required at the moment. There was a hiccup with this initially because the mpg321 player was throwing up an error that I did not understand and no-one could explain. I tried using mpg123 but that refused to loop round the Playlist (it was designed that way). I then returned to using mpg321 and found that it doesn't occur anymore :!: I can only assume that there was an error when I invoked it originally which is no longer there in the current code.

At present it isn't possible to change tracks, stop or restart the player because I need to develop the web-based control panel. Otherwise it is working. As part of the program, CPU Usage, Memory Usage and CPU Temperature are measured and this is available for the web-based control panel when i get there. It isn't possible to check fan speed because there is no pick-off to read. The two fans are on all the time.

I am now looking at the Bells code.
Terry
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: Prototype Minster Music Software

Post by TerryJC »

Sitrep 2:

I now have the Bells code working correctly (without any external control yet) and basic communication is set up between the two Pis. A full installation Specification will be produced in due course, but the following defines what needs to be done after a clean SD Card has been imaged and booted.

NOTES:
  1. Each Pi must be configured individually. I initially created a 'Base' SD Card Image in a similar way to the River System images. Unfortunately, this will result in the Volume Control (alsamixer / amixer) failing because the Adafruit Tutorial for the Stereo Bonnet (https://learn.adafruit.com/adafruit-spe ... y-pi-usage) requires that the Pi is rebooted twice after the setup script has been run. Using a pre-configured image seems to fall foul of this.
  2. Currently the hardware configuration is as defined at viewtopic.php?p=4514#p4514. This uses a USB / Ethernet Adaptor, but it has been pointed out to me by someone on the Raspberry Pi Forums that a fully functional network can be configured on a Pi using only a male to male USB cable between the Type A connector on the Pi 3 and the microUSB connector on the Zero. This will need a cable which I currently do not have, but they are cheap so I will probably do this in due course because that would release a £15 Adaptor for other Projects.
  3. It is not necessary to install RPi.GPIO on the Music Pi, but it will do no harm.
The following is a highly cut-down set of commands to run:

Code: Select all

pi@minster-bells:~ $ curl -sS https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/i2samp.sh | bash

REBOOT TWICE!

pi@minster-bells:~ $ sudo apt install python3-pip        

pi@minster-bells:~ $ pip3 install RPI.GPIO

pi@minster-bells:~ $ pip3 install apscheduler

pi@minster-bells:~ $ pip3 install datetime

pi@minster-bells:~ $ pip3 install psutil

pi@minster-bells:~ $ sudo apt install mpg321
After these commands have completed, set up networking by editing /etc/dhcdcd.conf and setting up a static IP address of 192.168.10.1 for the Music Pi and 192.168.10.2 for the Bells Pi. On the Bells Pi add a static router line pointing to the Music Pi at 192.168.10.1.

Finally create a route through the Music Pi to the WMT Network:

Code: Select all

sudo nano /etc/sysctl.d/routed-ap.conf
This will open a new file. Add:

Code: Select all

# Enable IPv4 routing
net.ipv4.ip_forward=1
In the console issue:

Code: Select all

pi@minster-music:~ $ sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE  
pi@minster-music:~ $ sudo iptables -t nat -L -v -n
This should return:

Code: Select all

Chain PREROUTING (policy ACCEPT 12 packets, 3312 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain INPUT (policy ACCEPT 11 packets, 2984 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain POSTROUTING (policy ACCEPT 2 packets, 282 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    8   729 MASQUERADE  all  --  *      wlan0   0.0.0.0/0            0.0.0.0/0           

Chain OUTPUT (policy ACCEPT 10 packets, 1011 bytes)
 pkts bytes target     prot opt in     out     source               destination
If all is well, send:

Code: Select all

sudo netfilter-persistent save
to make the new route persistent. Reboot both Pis.

It should now be possible to ping Google's DNS Server (8.8.8.8).
Terry
Post Reply