Evening classes and my new Hi-Fi stand

There will be an exhibition of my work in the York Explore Library this weekend ( 20-21 June 2015 ). Well technically it's not about my work but the York Adult Learning exhibition but hey, I have to start somewhere and I have one thing on show!

/images/2015/hi-fi_stand/completed_stand.thumbnail.jpg

It started when I signed up of an evening class with York Council ( I think this is the website https://www.yortime.org.uk/ but I can't make it's search work ) it was called Furniture Design, Make or Restore. With Julian Marston.

Basically every Monday night I would cycle over to the school where it was held and get some woodwork done.

/images/2015/hi-fi_stand/workbench.thumbnail.jpg

First day was a bit daunting as you would exact, everything new. I was late of course ( I may have stopped for some chips ). But did not miss much of the introduction. There seemed to be a few people who where regulars and had just started to get on with things and a few like myself who had no idea what it was all about. Julian gave us a quick tour round all the tools that we might want to use and then let us have a go on them. Band saw, pillar drill and belt sander. Then just left us to it. I was later to realise that was generally his style. If you needed help he would be there with advice and help but other than a chat now and again you where free to get on with things.

/images/2015/hi-fi_stand/slacker_tea.thumbnail.jpg

That first day I chatted with some of the people there wandered around a bit, and had some tea. Then went away with the puzzling question about what to make. It's not like I don't have enough things I want to do but this had to fit in ten weeks and be able to go back and forth on my bike each week. I pondered for a bit then chose to make a stand for my Hi-Fi. I have recently sold all my large Hi-Fi. Gone is the large surround amp, separate DAB radio and CD player and now I just have a small amp and a squeezebox. So I wanted a simpler stand that reflected that. My speakers have also shrunk but have matching stands that look rather neat so decided to mimic that in wood.

The design phase consisted of a couple of sheets of paper and a very rough sketch. Mostly I was going to wing it as I don't really know what I am doing. Measuring things up I headed out to the local timber merchant. I came back with a couple of planks of oak. This was going to be a fancy stand after all. For reference a couple of 2m oak planks is no problem on the bike.

A little bit of planning now had to happen as I wanted to glue the planks to make a sheet. So I did that at home. This process, as with most of mine at the moment, started with an hour watching YouTube. After realising that I needed an electric jointer, planer and table saw I managed to find some good videos showing what I was supposed to be doing. Paul Sellers and The English Woodworker where a great help as always.

So I took my newly created sheets of wood to school and tried to plane them flat. I had not realised how good it was not to have to chase the workbench around the room as you plane. Even if these benches where a little on the low side. Planing went well and I am still surprised how smooth and neat it all looks with just a plane much better than an electric sander. The second sheet seemed a lot harder, no matter how I tried it just seem to either dig in or skim over. It was at that point that Julian popped over and causally mentioned that he had a sharpening stone if I needed it. How right he was! Just a couple of seconds on the stone and I was back in business. I let Julian show me how so I could pick up some more sharpening tips. I have some diamond stones at home and at the time was struggling to get things right with them so I guessed I would be no better with the oil stone.

/images/2015/hi-fi_stand/scratchblock.thumbnail.jpg

A scratch block is a really old style tool consisting of something metal jammed into a bit of wood. You then drag this down the side of your work piece and it scores a line in it. I made one from a screw with the edge filed off. It worked really well and was a lot less scary to used than a router. With this I scored the three lines down the front to reflect the same pattern in my speaker stands.

/images/2015/hi-fi_stand/glass_legs.thumbnail.jpg

Next up was the glass. York Glass Supplies where really great. I took in my paper template, drawn up in FreeCAD, and they just cut it out and drilled the holes. Even smoothed over the edges nicely. There was a slight delay while they waited for the right sized drill bit to be delivered from Germany but other than that a really great service.

( Funny story about the York glass supplies website. Their ssl certificate shows as bad because it is only valid for manloveforensics.co.uk. I decided not to look any further into that )

/images/2015/hi-fi_stand/glass_legs_in_place.thumbnail.jpg

Next up I had a go on the lathe. What fun. Sawdust everywhere! I had a practice making a square block round then went ahead an made up the little feed to go on the end of the glass and the front.

Then there was the rounding of the edges. Marked up with pencil I went at it with the plane. First at 45 degrees then gradually smoothing that out. Then a little tidy up with a rhasp and things where starting to look tidy.

/images/2015/hi-fi_stand/glue_up.thumbnail.jpg

I had to do all my gluing up at home so that it would have time to dry before going on the bike. It worked out quite well as I had just treated myself to a load of clamps. We will see if it all holds together in the long run but I don't think there where many gaps which is the important thing.

Once I had the mortice and tenon cut for the top it was time for the finish to go on. This was however after the end of the course so none of my workmates got to see the final showing. I used some Osmo oil partly because I like the mat finish and partly because it's really easy to apply with just a scouring cloth.

All done and in place. I am really please with how it turned out. I am sure I would do things a little differently next time round but I think it looks pretty neat.

/images/2015/hi-fi_stand/full_stand.thumbnail.jpg

Starting nfc-eventd from systemd on the beaglebone

Attaching an nfc reader to the beaglebone. In my case a cheap one called COOQROBOT which I think is pn532 variant.

I installed both libnfc and nfc-eventd from source. The ususal ./configure; make ; sudo make install. ( You might need to follow this with a ldconfig -v to get the library picked up )

Now you can start a service that monitors your nfc reader for new tags. Just drop the following into /etc/systemd/system/nfceventd.service and run sudo systemd daemon-reload.

[Unit]
Description=nfc-eventd

[Service]
ExecStart=/usr/local/bin/nfc-eventd

[Install]
WantedBy=multi-user.target

Now you can start the service with systemctl start nfceventd.service. And look at errors and output with systemctl status nfceventd.service.

By default the config for nfc-eventd just saves the events to /tmp/nfc-eventd. If you edit /usr/local/etc/nfc-eventd.conf you can change what this now does. So it could for instance send those events to your node-red server via mqtt.

action = "mosquitto_pub -h mosquitto.example.com -t /nfc/tag/ -m $TAG_UID "

Bash Linting. Checking your scripts are nice and lint free

Continiuing on from my previous post on testing shell scripts with bats I have been looking for a linting solution for shell scripts. And I think I have found a nice one in shellcheck. Which is aviailble as both a website and a packge on debian.

It's really simple to run just give it your shell script as an argument and you get a nice set of comments on the style of your code. Here is the result of testing their test script.

#!/usr/bin/env bash
## Example of a broken script. Hit the Down Arrow button to ShellCheck it!
for f in $(ls *.m3u)
do
  grep -qi hq.*mp3 $f \
    && echo 'Playlist $f contains a HQ file in mp3 format'
done

Then run shellcheck foo.sh

In foo.sh line 3:
for f in $(ls *.m3u)
         ^-- SC2045: Iterating over ls output is fragile. Use globs.
              ^-- SC2035: Use ./*.m3u so names with dashes won't become options.


In foo.sh line 5:
  grep -qi hq.*mp3 $f \
           ^-- SC2062: Quote the grep pattern so the shell won't interpret it.
                   ^-- SC2086: Double quote to prevent globbing and word splitting.


In foo.sh line 6:
    && echo 'Playlist $f contains a HQ file in mp3 format'
            ^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.

I have a simple makefile now that's just there mostly as a reminder of the testing that is aviailble for that script.

bats: *.bats
    bats *.bats

lint: your_script your_nextscript
    shellcheck your_script
    shellcheck your_nextscript

Next up is intergration with vim. I use the really nice syntastic vim plugin. Syntastic does automatic style checking on files as you save them and shows a set of errors. Installing it is simple. Install shellcheck, I use apt-get install shellcheck on Debian but you can use your favorite way on your OS. Then install the vim syntastic, again I use Vundle so adding Bundle scrooloose/syntastic to my .vimrc and then running BundleInstall in vim did the trick for me. Now when I write a shell script to disk vim will comment on my style.

Setting Soundcard names in Gnome

I have a couple of sound cards attached to my laptop at work and it gets confusing to know which one is which when they have names like "Analogue line out". So I set about changing them and struggled a bit in the process so I thought I would note it here for reference.

Gnome takes the name of the soundcards from pulseaudio. There does not seem to be a way to rename them directly in gnome but you can do it from the command line. The command pacmd list-sinks will give you a list of the devices that you have. Looking through that list at the 'name:' field are the identifiers that you can use. ( You can also use the ID but I am not sure how stable they are ) The man page for pulse-cli-syntax is the rather confusing location for the commands that you can give the pacmd command.

Now we know which card we want we can change the description property that Gnome uses with the following command. Note the extra quotes are required if your description has spaces in it.

update-sink-proplist alsa_output.usb-Burr-Brown_from_TI_USB_Audio_DAC-00-DAC.analog-stereo 'device.description="External Blue headphones"'

Then you can run the pacmd list-sinks command to check that works. At the gnome level nothing will have changed. So now you need to add this to your config file ~/.config/pulse/default.pa which is just a list of pacmd commands to run on startup. You can now drop the extra single quotes as it does not need to be escaped for the shell prompt.

Update: You need to add the line below to your default.pa so that it knows about the default config. Pulseaudio only loads one config file by default so this just makes sure you get the default settings first.

.include /etc/pulse/default.pa

Now it just remains to get pulseaudio to re-read it's config in the usual unix way by giving it a HUP.

pkill -HUP pulseaudio

Listening to SSL with socat

I wanted to dump the headers for a http request over ssl today. Pulled out socat and this command and it seemed to work quite nicely.

socat OPENSSL-LISTEN:4433,cert=server.crt,key=server.key,verify=0 -

You will need to create server.crt and server.key and if you don't want the other end to complain then they should be a valid keypair.

Socat is a really nice tool that exposes the power of Unix sockets and allows you to connect anything together. In this case a tcp socket with ssl support and the standard out. But it could be a UDP port and a serial cable for all all socat cares. A really nice tool.

Testing Bash with Bats

Spectacled Fruit Bat by Shek Graham

Spectacled Fruit Bat by Shek Graham

I quite like unit tests. They give you that quick feedback that things are going to be okay. I can write a test watch it fail. Write some code and watch it fail also. Then learn very quickly what I have done wrong.

At some point last year I read the Clean Code book by Rober C Martin and it opened up to me a lot of the ideas about testing and code that I had not really got to grips with at the time. Martin takes you through the reasoning and process for producing code that, in a years time, you might want to actually look at and feel comfortable editing.

What has this go to do with bash and bats? Well we have been adding more tests to our puppet code and it came time to write a bit of bash for moving some files around. I thought there must be a simple way to check some of this and sure enought that is where bats comes in.

bats is a testing framework for bash scripts. I know it sounds crazy but it really does work. If you start applying some of the lessons from clean code and spliting your work into functions with local varaiables it soon becomes easier to test. You can, as ever, take things too far but this does at least allow you to test a lot of your logic before you roll it out. With the added benifit of makeing the code a little more readable.

I found this blog post by Spike cleared up some of the questions I had about testing functions as well. http://blog.spike.cx/post/60548255435/testing-bash-scripts-with-bats

Some other useful things are the google shell style guide and shUnit2 which I have yet to look at. The Defensive Shell Guide by Kfir Lavi and Better Bash Scripting in 15 Minutes by Robert Muth are also good.

Using the ACS ACR122 NFC card reader under linux

If you are seeing some errors in the logs like the ones below:

pcscd[4489]: 58837251 ccid_usb.c:645:OpenUSBByName() Can't claim interface 001/110: Device or resource busy
pcscd[4489]: 00040743 ifdhandler.c:118:IFDHCreateChannelByName() failed
pcscd[4489]: 00000030 readerfactory.c:1043:RFInitializeReader() Open Port 0x200000 Failed (usb:072f/2200:libudev:0:/dev/bus/usb/001/110)
pcscd[4489]: 00000008 readerfactory.c:335:RFAddReader() ACS ACR122U init failed.

You need to prevent the kenel nfc drivers loading so add the following lines to /etc/modprobe.d/rfid-blacklist.conf

blacklist pn533
blacklist nfc

as suggested here: http://maciaszek.net/26522/rfid-reader-mit-debian/

Then remove those modules with modprobe -r pn533 nfc

Then install some packages

apt-get install libpcsclite1 pcsc-tools pcscd

Then run:

pcsc_scan

You should get some output similar to the stuff below.

PC/SC device scanner
V 1.4.23 (c) 2001-2011, Ludovic Rousseau <ludovic.rousseau@free.fr>
Compiled with PC/SC lite version: 1.8.11
Using reader plug'n play mechanism
Scanning present readers...
0: ACS ACR122U 00 00

Thu Jan 22 23:00:58 2015
Reader 0: ACS ACR122U 00 00
  Card state: Card removed,

Thu Jan 22 23:01:06 2015
Reader 0: ACS ACR122U 00 00
  Card state: Card inserted,
  ATR: 3B 8F 81 01 80 4F 0C A0 00 00 04 06 03 00 01 00 00 00 00 6A

ATR: 3B 8F 81 01 80 4F 0C A0 00 00 04 06 03 00 01 00 00 00 00 6A
+ TS = 3B --> Direct Convention
+ T0 = 8F, Y(1): 1000, K: 15 (historical bytes)
  TD(1) = 80 --> Y(i+1) = 1000, Protocol T = 0
-----
  TD(2) = 01 --> Y(i+1) = 0000, Protocol T = 1
-----
+ Historical bytes: 80 4F 0C A0 00 00 04 06 03 00 01 00 00 00 00
  Category indicator byte: 80 (compact TLV data object)
    Tag: 4, len: F (initial access data)
      Initial access data: 0C A0 00 00 04 06 03 00 01 00 00 00 00
+ TCK = 6A (correct checksum)

Possibly identified card (using /usr/share/pcsc/smartcard_list.txt):
3B 8F 81 01 80 4F 0C A0 00 00 03 06 04 00 01 00 00 00 00 6A
3B 8F 81 01 80 4F 0C A0 00 00 03 06 .. 00 01 00 00 00 00 ..
    Mifare Standard 1K (as per PCSC std part3)
3B 8F 81 01 80 4F 0C A0 00 00 03 06 04 00 01 00 00 00 00 6A
3B 8F 81 01 80 4F 0C A0 00 00 03 06 04 .. .. 00 00 00 00 ..
    RFID - ISO 14443 Type A Part 3 (as per PCSC std part3)
3B 8F 81 01 80 4F 0C A0 00 00 03 06 04 00 01 00 00 00 00 6A
    Philips MIFARE Standard (1 Kbytes EEPROM)
    http://www.nxp.com/#/pip/pip=[pfp=41863]|pp=[t=pfp,i=41863]
    RFID - ISO 14443 Type A - Transport for London Oyster
    ACOS5/1k Mirfare
    RFID - ISO 14443 Type A - NXP Mifare card with 1k EEPROM
    vivotech ViVOcard Contactless Test Card
    Bangkok BTS Sky SmartPass

More next time.

Scrolling text on a rainboduino

Spent a little time last night at Hackspace writing some basic code to scroll some text across a rainbowduino.

I use arduino-mk ( pacakge available on debian ) so here is the basic makefile to build it.

BOARD_TAG    = atmega328
ARDUINO_LIBS = Rainbowduino
ARDUINO_DIR   = /usr/share/arduino
ARDMK_DIR     = /usr/share/arduino
AVR_TOOLS_DIR = /usr

include /usr/share/arduino/Arduino.mk
/*
 Rainbowduino v3.0

 Scrolling text

*/

#include <Rainbowduino.h>

String message = "John is ace!";

void setup()
{
  Rb.init();
}

unsigned char x,y,z;

void scroll_text(String msg)
{
    int len = msg.length();
    const int kern = 6;
    byte msg_b[len+1];
    msg.getBytes(msg_b, len+1);

    for (int i = 0; i <= len * kern ; i++) {
        for (int b = 0 ; b < len ; b++) {
            if ((b * kern) > ( i - kern) && (b * kern) < (i + kern) ) {
                Rb.drawChar(msg_b[b],- i + (b * kern),1,random(0xFFFFFF));
            }
        }
        delay(200);
        Rb.blankDisplay();
    }
}

void loop()
{

    scroll_text(message);

}

Internet Notes from about week 02

A new year and a new blog post....

Tech news

All things python: http://pycoders.com/2014/ - This is a list of the best of the pycoders weekly from last year. Some really great posts in there.

Testing our puppet code has become a big thing for us now. More and more of our code has spec tests using rspec-puppet and puppetlabs-rspec-helper. We are also starting to experiment with beaker that server-spec that allow us to boot up a Virtual Machine(VM) and run tests against an applied manifests. Which then leads me on to a interesting project called test-kitchen which was created to do a similar thing for Chef recipies. http://pocket.co/s_5Sx is an interesting post about how to use test-kitchen and docker to do the same for puppet.

Clearing out

Keeping up with my clearing up and with a bit of a new year burst of enthusiasm I have binned my old CD player that I brought at University and no longer works feels such a shame to take it to the tip. Also selling DVD player, AV Amp, Huge speakers on Gumtree. Now I just have a nice stereo amp and small speakers hooked up to a squeezebox for music and radio. Then an Kodi ( was XBMC ) box for watching Youtube and movies etc. All neat and tidy. Next up is sorting the Minidisc collection and getting rid of that too. Everything must go.

I got given a vice for Christmas, no not that sort, a woodworking vice. So now I just need to build a bench to attach it too. So look out for some more woodworking stuff.

Do no evil

I am going to try going back to this blog for some online stuff. I am starting to worry about my dependence on Google. I have been looking at owncloud and I kickstarted ( is that a word now? ) the http://sandstorm.io/ project and the Mozilla Matchstick last year as well.

Stuff from the internet

Bikes and that

http://www.thediscerningcyclist.co.uk/2014/09/quoc-pham-the-derby-review/ - Some really nice cycling shoes. I don't have clipless pedals but if I did these would be the shoes for me. Oh and their boots in the winter.

Coding

https://medium.com/@lucperkins/web-development-in-c-crazy-or-crazy-like-a-fox-ff723209f8f5 - It may seem mad but why not write your next web application in C? Some good tips if you do and a couple of interesting libraries even if you don't.

https://vimeo.com/71278954 - The future of programming circa 1974, given in a talk in 2014. TL;DW we are still programming like it's 1974.

Sysadmin

http://blog.petersobot.com/pipes-and-filters - A really simple introduction to what is going on in a unix pipe. Good to remind yourself of the basics sometimes.

http://youtu.be/mgcJPREl3CU?list=PLDGkOdUX1Ujo3wHw9-z5Vo12YLqXRjzg2 - Some good videos showing you how to driver Grafana which is turning out to be a really smart front end to graphite.

Making

http://www.rayjardine.com/papers/why-sew/index.htm - I brougt a broken sewing machine of ebay based on this post. ( Why do I insist on shaving the yak first every time?)

https://woodworkingmasterclasses.com/ - I have been watching hours or Paul Sellers videos. He has such a great presenting style. Just watching him work is a pleasure. It's all hand tools as well so it a much more relaxed pace. I am seriously concierding treating myself to one of his courses.