Thursday, November 09, 2017

Wedding Begging Poem

I got married to my wonderful wife nearly five years ago. We went to loads of wedding fairs, saw lots of wonderful things, and picked each other up off the floor when we found out how expensive everything was. So, we looked at little ways to cut costs, and one of them involved printing our own invites (very tasteful, laser printed, curly fonts, expensive paper, coloured ribbons, wax seal... very sophisticated). We included a fun little poem indicating our preference for cold hard cash instead of gifts, which is an idea we'd nicked from somewhere. I'm sure 75% of the below is repurposed from other sources, but I can't quite remember where those bits end and my bits start, so here is our version incase someone else wants to do the same.


We do not have a gift list,
we’ve got our pots and pans.
Our life is pretty sorted.
We’ve inked out all our plans!

We thank you for your presence,
to celebrate our day.
Your love is all we really need,
to send us on our way.

But if the mood should take you,
and you feel a little flash,
put on a cheque "C. Thomas"
we'd love a gift of cash!

The honeymoon's expensive.
The three kids bleed us dry!
Please don't be too offended, that
we gave this verse a try!

Tuesday, November 07, 2017

Chimney Clock Server

My 'wine box' fileserver was getting a bit creaky... there were no more XP updates, and IIS wasn't the most secure, so it was time to upgrade... and build stuff! By this time the 'maker' scene had really taken off and given me delusions of grandeur, so I thought I'd do things a bit differently this time around. I bought a newer, more powerful mini-itx board, more memory, and bigger hard disks. I also took advantage of the free upgrade from Windows 7 to Windows 10. I was on the bleeding edge!

Even though this was a more powerful board, it was still passively cooled, but to aid the cooling I decided to build it in a 'chimney' configuration, so that warm air escaping out of the top would draw in cooler air at the bottom. My first idea was to paint it in black gloss to make it look like the alien monolith from 2001 A Space Odyssey...


 ...but it was proving difficult to obtain wood in the right dimensions (1x3x9) and I also I don't have any woodworking equipment to make perfectly straight cuts, or to join pieces of wood together with any accuracy. Those problems, and the fact that it would probably need to be pretty big for anything to fit comfortably inside, kind of put the breaks on that idea.

I wondered if I could build the server into a wall clock. Not only would it look nice, but you'd be able to tell the time! However, all the lovely wall hanging ones on eBay were way too expensive to buy second hand, and I didn't relish the idea of destroying a beautiful clock by accident. I did however, discover some ready made A4 sized wooden box files, which are hinged, made specifically for you to decorate yourself, and were almost the same dimension as my original wine box server. I bought two of them and figured they'd stack up on top of each other. They looked a bit like this...


I wood-glued them together, end to end so the lids could open together, and cut a hole to allow air to flow between both boxes. I cut out two sections from the 'base' of each box with a craft knife, to allow for inflow and outflow of air. It worked a treat, but it wasn't very stable stood on the one end, so I got two cheap B&Q pine corner shelves, drilled holes in the edges for dowels, and stuck them together to create a wide semicircular base for the tower, which was glued in place.


More strips of wood were glued in place to provide airflow and support for the mini-itx board, hard disks, and I figured out a mounting scheme for the obligatory big red comedy sized power button. I temporarily used my old mini-itx board as a build template...


A cheap quartz crystal clock mechanism was built into the top lid. To protect the hands from accidental damage, a small square picture frame with a perspex window was glued to the outside. A little bit like this one...


Finally, a couple more moulded wooden strips were glued to the top and bottom of the outside of the boxes and it all had a couple of coats of wood stain, to give it a bit more of an authentic 'clock' look. I also drilled a small hole to thread the power LED light to subtly light the clock face. The hard disk light pokes out the back and illuminates the wall most effectively.


Specs:
Motherboard: Gigabyte J1900N-D2H quad-core 2Ghz Intel Celeron
Memory: 4Gb
Boot HD: 120Gb
Data HD: 3Tb WD Red (2.7Tb formatted)
OS: Windows 10 Pro 64bit (free upgrade from Windows 7 Pro)

Idle temperature: 37°C
Awesomeness: Very

Sunday, November 05, 2017

My First Wine Box Server

I wanted to build a cheap backup file server. Nothing too fancy, it didn't need a high spec, and I wanted it to be quiet and relatively low power, because it would be on 24/7. I purchased a cheap fanless mini-itx board, hard disk, memory, PSU, and set to building it into an old wooden wine box.


First to go in was the mini-itx motherboard. Holes were cut for network cable and for airflow. The thread on the 12V DC power socket was just about wide enough to let me screw it tightly to fix it through the backing board.


Two strips of wood were glued to the back to allow air to circulate more easily from the back side of the motherboard, and also to stop the screws holding it in from popping out through to the outside.


Two further strips were glued inside of the 'top' and 'bottom' of the box (left and right in the above picture), which allowed me to place two snugly fitting wooden props on top of them. The boot and data hard disks rested on the props, which kept them away from the heat sink to prevent any contact or electrical shorting, and permitted airflow.


More airflow holes were drilled (and later enlarged) into the top of the box allowed for a small chimney effect to draw cool air in and hot air out.

There was always a noticable 'warm wood' smell emanating from the box whenever it was switched on. I was of course concerned that it would catch fire, but the box was never under any great load, and the fragrance was actually quite nice. I ran some software called 'motherboard monitor' was was able to graph the cpu and system temperatures thoughout the day. After a couple of days, the temperature remained stable and acceptably low, so I didn't really worry about it.

A big red comedy power switch replaced the cheap little grey square one that came with the motherboard, and a four way USB hub in the shape of a robot was blu-tacked to the top to allow for easy file transfer by USB stick. The robot also has big blue glowing eyes which were useful to show that the server was powered on. The actual power and hard disk activity lights aren't even fixed permanently, and are just unceremoniously poking through one of the airflow holes.


One spare install of Windows XP later, and it worked great! I also included a webcam, some software to take pictures and turn the webcam into a security camera, and installed IIS to let me view the latest picture. Port 80 was forwarded from my home router, and hey presto, remote webcam monitoring!

With no fans, and barely audible hard disk activity, this was an ideal server to have in the living room, connected via ethernet cable to my home router. Thankfully it never did catch fire, and in the five or so years it was running, it was powered on 24/7. A great first 'maker' project!

Wednesday, November 01, 2017

Magic Mirror - build part 4

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!