We had been away on holiday. We returned to discover the magic mirror stuck in a reboot cycle. I hadn't backed anything up. Crisis!
Troubleshooting consisted of swapping out different components with my test unit to work out what had failed. After a few hours of exhaustive testing, it turns out that the Pi power brick had failed, and was not providing enough power to boot properly. The constant reboots and power failures also seem to have irreparably damaged the boot partition on the SD card, because that wouldn't boot in my test unit. Luckily though, I was still able to access the SD card with a freeware Windows program called '
DiskInternals Linux Reader', which could open and read the root partition, which is where all the custom scripts, magic mirror module configuration and timebonger code were stored. All relevant files were immediately copied off and backed up safely! I just had to reflash the SD card, order a new replacement power brick, and then reinstall everything.
I chose to use the latest Google AIY Projects image, meaning that I shouldn't have to worry about trying to reconfigure any audio settings because it should all work out of the box. All I would need to do would be configure the networking, retrieve the previously created AIY credentials from my Google account, reinstall the Magic Mirror software and modules, and copy back the timebonger script. I also decided to keep some notes on what I was doing, just in case I'd have to do it all again! Here they are:
1. Flash AIY Projects image to flash card with
Etcher
2. Boot Pi with new image
3. Connect to home wifi using menu icon
4. Using 'Preferences'->'Raspberry Pi Configuration'
System tab: Set hostname to 'magicmirror'
Interfaces tab: Enable VNC server (then set admin password in VNC server config)
Localisation: check settings for UK
5. Set fixed IP Address
run:
sudo leafpad /etc/network/interfaces
comment out:
iface wlan0 inet manual
add:
iface wlan0 inet static
address 192.168.0.98
subnet 255.255.255.0
gateway 192.168.0.1
6. Update everything
sudo apt-get update && sudo apt-get -y upgrade && sudo reboot
sudo rpi-update
7. Configure AIY Projects
Follow instructions in AIY project installation to create the 'client_secrets.json' and 'credentials.json' files and put them in /home/pi/
8. Install 'xscreensaver' to stop the default screensaver kicking in
run:
sudo apt-get install xscreensaver
configure by going to 'Preferences'->'Screensaver' and setting the blank screensaver
9. Install 'unclutter' to hide the mouse after a few moments of inactivity
run:
sudo apt-get install unclutter
10. Install my 'timebonger' script
copy timebonger.py and cuckoo_clock1_x.wav to ~/timebonger
create ~/timebonger/tb.sh with leafpad to contain:
python /home/pi/timebonger/timebonger.py
make executable:
chmod +rwx tb.sh
11. Install MagicMirror core -
https://magicmirror.builders/
run:
bash -c "$(curl -sL https://raw.githubusercontent.com/MichMich/MagicMirror/master/installers/raspberry.sh)"
12. Configure some default MagicMirror modules
Add a personal Google Calendar using the ical link
Add local weather and weather forecast using details from http://www.openweathermap.org
Configure a couple of BBC News rss feeds
13. Install some additional MagicMirror modules.
random_quotes:
cd ~/MagicMirror/modules
git clone https://github.com/KirAsh4/random_quotes
add to MagicMirror config.js:
{
module: 'random_quotes',
position: 'middle_center',
config: {
updateInterval: 300
// The config property is optional
// Without a config, a random quote is shown,
// selected from all of the categories available.
}
},
mmm-systemtemperature:
cd ~/MagicMirror/modules
git clone https://github.com/MichMich/mmm-systemtemperature.git
add to MagicMirror config.js:
{
module: 'mmm-systemtemperature',
position: 'bottom_right', // This can be any of the regions.
classes: 'small dimmed', // Add your own styling. Optional.
config: {
// See 'Configuration options' for more information.
}
},
MMM-ping:
add ip addresses and hostnames of the devices I want to monitor inside my network to /etc/hosts so we can see names and not a list of ip addresses.
leafpad /etc/hosts
192.168.0.1 sky_router
192.168.0.99 deepthought
192.168.0.150 chromecast
192.168.0.151 firestick
192.168.0.200 tplink_ext
192.168.0.209 hipsy00005
192.168.0.210 retropie
cd ~/MagicMirror/modules
git clone https://github.com/fewieden/MMM-ping.git
cd ~/MagicMirror/modules/MMM-ping
npm install --productive
sudo chmod u+s /bin/ping
add to MagicMirror config.js:
{
module: 'MMM-ping',
position: 'bottom_left',
header: 'Ping',
config: {
colored: true,
font: 'xsmall',
updateInterval: 1,
hosts: [
'sky_router',
'deepthought',
'chromecast',
'firestick',
'tplink_ext',
'retropie',
'hipsy00005'
]
}
},
MMM-Trello:
useful online collaboration post it notes for teams (we use it at work)
cd ~/MagicMirror/modules
git clone https://github.com/Jopyth/MMM-Trello.git
cd MMM-Trello
npm install
add to MagicMirror config.js:
{
module: 'MMM-Trello',
position: 'bottom_right', // This can be any of the regions, best results in center regions.
header: 'Trello',
config: {
// See 'Configuration options' for more information.
showTitle: "true",
api_key: "<my api key>",
token: "<my token>",
list: "<my card id>"
}
},
14. Adjust MagicMirror CSS to reduce the large border and maximise screen area
Edit custom.css:
leafpad ~/MagicMirror/css/custom.css
Insert this css into body to override those defaults in main.css
body {
margin: 10px;
position: absolute;
height: calc(100% - 20px);
width: calc(100% - 20px);
}
15. Set pm2 to autostart everything
I initially followed these instructions
Auto Starting MagicMirror and then adapted them to start the other features.
start timebonger
pm2 start /home/pi/timebonger/tb.sh --name "TimeBonger"
start Google Assistant - assistant_library_demo.py
create gassist.sh (which is mostly a copy of ~/bin/AIY-voice-kit-shell.sh):
leafpad ~/bin/gassist.sh
#!/bin/bash --rcfile
source /etc/bash.bashrc
source ~/.bashrc
cat /etc/aiyprojects.info
cd ~/AIY-voice-kit-python
source env/bin/activate
/home/pi/AIY-voice-kit-python/src/assistant_library_demo.py
make it executable
chmod +rwx ~/bin/gassist.sh
add it to pm2 startup:
pm2 start /home/pi/bin/gassist.sh
start MagicMirror
pm2 start /home/pi/MagicMirror/installers/mm.sh --name "MagicMirror"
save pm2 process list
pm2 save
add pm2 startup to /etc/rc.local
run:
pm2 startup systemd
which should add a startup command (like the one below) to /etc/rc.local
# pm2 startup
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi
16. Reboot, and cross fingers!
So that's about it for my Magic Mirror!
It's especially useful in the mornings to have a clock and calendar available, and to quickly check the day's forecast for good or bad local weather. Having the random quotes is fun, but the rss news feed is less useful because it only shows one thing at a time. Having the Google VoiceHat installed is also cool, and when I find the time, I'll have a go at swapping out the simple Assistant with the more powerful Cloud Speech API to implement some of my own commands, and bring me a bit closer to the Star Trek Next Generation LCARS interface! Yes, I am a nerd.
All in all, the timebonger is the icing on the cake as far as I'm concerned, it amuses me all the time, and no-one's complained about it so far!