Thursday, January 22, 2015

Lessons Learnt

How many industries do this?

Imagine the conclusion of a big project, or an event... Everyone's had a week or so to recover, and it's now time to break it down and figure it out.

What is it?

Well... I guess you could call it a "debrief", only, it's a lot bigger than that. You get EVERYONE into a room together. You take as long as you need. You make sure that EVERYONE talks about:
  • Anything that went particularly well.
  • Anything that went wrong.
  • Possible solutions for avoiding or mitigating the things that went wrong.
  • How to maximize the things that went well.
  • Where improvements can be made.
Why is this important?

Well... instead of leaving a project only to repeat past mistakes, it's helpful to turn it into a learning exercise. You get to learn how other people felt about it in comparison to how you were feeling about things. You figure out how to make the next iteration even better. I see it as professional development.

Is this common practise though? There's this whole thing against any sort of negativity and, by extension, critical thinking. But people who poke holes in things are making informed choices - they're trying to figure out what's wrong with a decision. The decision they come to is going to be THE most scrutinized of all the choices. But it also looks like they're trying to cast down the idea.
It takes a thick skin. In the case of a project, something's probably gone wrong that you feel responsible for. Perhaps it was a break down in communication between your team and another.

If you only look at the rainbows, and not the rain, chances are you're missing out on a whole lot of learning. It's that learning that you should be taking away with you. That's the positive that you miss out on by ONLY looking at the positive... and to me, that's a far worse negative than anything that might come out of looking over the negatives....

Tuesday, January 20, 2015

Photocopier - Proof of Concept

I was asked to photocopy something for someone and so I decided, given the state of my MFC (Multi-Function Center - photocopier, fax, printer) device, I'd do it using a scanner and printer. The reasoning for this is that I can, eventually, use a Raspberry Pi and it's GPIO to give me a modular, extensible photocopier.

Extensible? you ask... well... It occurred to me that I only have a flatbed scanner, but at some stage, I might want to add a multipage scanner. Or I might want to switch to a colour printer (though my black and white, very fast, laser printer does me quite well for the time being). Or I might want to add a display of some description and have a scan to email facility. And if there's a display anyway, then the ability to print off multiple copies would be brilliant.


So, on my desktop computer, I put together this script. All I need to do is to set up a Raspberry Pi with Raspian, hook up a button to the GPIO, and have it run this script whenever the button is pushed. Oh, and probably have a blinky LED to tell the user when the scanner is still scanning...

 #!/bin/bash  
 SCAN_COMMAND="scanimage"  
 SCAN_DESTINATION="plustek"  
 WIDTH_MM="210"
 HEIGHT_MM="297"
 RESOLUTION="150"
 WIDTH_INCHES="$( echo "scale=3;$WIDTH_MM/25.4" | bc )"
 HEIGHT_INCHES="$( echo "scale=3;$HEIGHT_MM/25.4" | bc )"
 SCAN_PARAMETERS="--mode Gray -l 0 -t 0 -x $WIDTH_MM -y $HEIGHT_MM --resolution $RESOLUTION"  
 PRINTER="FS-1030D"
 photocopy_cmd="$SCAN_COMMAND -d $SCAN_DESTINATION $SCAN_PARAMETERS | pnmtops -width $WIDTH_INCHES -height $HEIGHT_INCHES -imagewidth $WIDTH_INCHES -imageheight $HEIGHT_INCHES | lp -d $PRINTER"
 eval $photocopy_cmd  

If this script is going to be used by anyone else:
  • You need to have sane and cups installed.
  • To get the printer name run:
    • scanimage -L
  • To get the printer name run:
    • lpstat -p -d
  • The dimensions (WIDTH_MM and HEIGHT_MM) are obviously in millimeters (the dimensions there are for A4). It does a conversion to inches (damn Americans and their imperial system).
  • If you want colour copies, in SCAN_PARAMETERS change:
    • --mode Gray
    • to
    • --mode Color
  • If you're finding it slow, trying turning down the resolution (though 150 seems to be a pretty good setting).
I'm planning on running this on a Raspberry Pi which I'll have set up with my tv server (I suspect I've found my problem with that though need to do some testing - for which I've had to order a couple of parts).

Raspberry Pi TV Server

I spent about 12 hours trying to get a tv server for Raspberry Pi working... I haven't managed to get it working yet, but I figured I'd document it anyway.

Here's what I'm aiming for.

In my house, our outdoor aerial came down a few years ago and was never replaced. We have around 4 TVs in the house and each of them have these ugly indoor aerials that on occasion seem to need adjusting (I think it's related to humidity). Out of those 4 TVs, 2 have pi's connected, 1 is used as a second monitor for a computer, and the 3rd one is someone else's. So a TV server makes sense.

Basically, you use a tv tuner on a computer to transmit TV via wifi. That's it. I'm not really that interested in PVR functionality. In this age of streaming (which isn't nearly as good as it should be. I'm of the opinion that this is a prime area where patents completely screw with progress), it shouldn't be necessary to record anything off the TV. Timeshift might be interesting... but first and foremost, I'd like to be able to use the Pi for EVERYTHING on the TVs (in which case, I'm buying DVD drives).

First things first. The server software. Under Linux, the options are:
  • VDR
  • MythTV
  • DVBLink
  • Tvheadend
VDR
Don't do it to yourself... VDR requires a plugin - VNSI server - which is a moving target. They're up to version 6. I could only find a server for 5 which rejects clients using version 6. The compile instructions had no instructions for compile and instead had a somewhat ambiguous note about link a folder.

MythTV
This was FAR more complicated than I was anticipating. It's definitely not a user centric program. It's beest avoided.

DVB LINK
I kind of wanted to scream when I tried this. Out of the box, it's a free download! Yay! Except that it then tells you that you have to install a "product" to able to use TV with it. It's a bit like buying a bottle of coke, only to find you have to buy the coke separately. The "product" is a time limited trial and then you have to pay for it.

Tvheadend
This was my chosen solution (even though I haven't a clue what's going wrong at the moment).

So the only new piece of information I can offer... I saw lots and lots of tutorials that talked about multiplexers and how the presets are probably wrong and sources to go to for that information.

Forget it. ALL of that information just isn't quite as good as having a look at what's working for you! So when it comes to adding multiplexers, don't "Add DVB Network by Location". You don't know if it's even got the right information. Instead, do a scan. The command in Linux is w_scan.

w_scan > channels.conf

Problem solved. Once you have a list of multiplexers, you can add them manually.

The Issue
Okay, so EVERYTHING would work. Even EPG which was a bit of a surprise as lots of online sources talk about scrappers and the like. In NZ it'd probably be better to use a scrapper as our EPG only tends to cover the current show and 1 or 2 after it. So recording is difficult.

The only thing not working... the actual streaming of TV content. That's it. The core functionality. I can't get it working with the VLC plugin, on the xbmc machines (pi). Nothing...

[Update]
I managed to get it working properly. It seems it was an issue with the hardware...

Friday, January 16, 2015

#humblebrag

ARRRRGGGGGHHHHHH!!!!!

I've got a problem... My hand has been cramping up. I'm on the computer all day every day and I have really big hands. It's kind of an advantage for touch typing (though I could do with an ergonomic keyboard). BUT my big problem is trying to find a damn computer mouse at a reasonable price.

It's annoying! I've been going through forums to find what other people have found ... and they're all still too damn small! Going based on length, most of the recommendations are for 12cm mice. I've got one right there... and it's still too small...



Basically, I need something that:
  • Supports my little finger - having it hang out the side sucks. So around 10cm wide.
  • Is at least 14cm long (preferably 15cm) as to avoid my palm being on the desk.
  • Must cost less than $100.
  • Be wireless (cables suck!)
  • Be right handed.
I have found something that meets the specifications except that it looks like a terrible caricature of those kinds of mice NO BODY likes to use and isn't wireless. Do a google search for "Jumbo Mouse".

Contour designs do mice based on size and handedness but are wired and horrendously expensive. (£100 or so which translates to around $200NZD).


Anyway.... before some smart arse comments with "#humblebrag" I thought I'd save you the trouble. Does anyone know where to get a scary big computer mouse from?

Wednesday, January 14, 2015

Some Nerd Notes - Multiple kodi/xbmc Raspberry Pi's

I've finally been trying to set up a second Raspberry Pi running Raspbmc (Kodi) ... and it's been a mission!

So I thought I'd document what I've found (and the pitfalls that don't seem to be documented).

Firstly, ssh into the Raspberry Pi you intend to use as your server. The defaults are:
Username: pi
Password: Raspberry

Firstly, sharing the files:

Uh-oh....

Okay, here's the problem. For some strange reason, the pi doesn't always mount the USB drives on boot. I used uuid's as I didn't want the uncertainty of the two drives that I've got having different designators when udev finds them. So here's what that part of /etc/fstab looks:

 /dev/disk/by-uuid/73321d6f-daeb-4201-b300-c37d3d3c91a8   /srv/nfs/movies ext4     defaults,noatime 0 2  
 /dev/disk/by-uuid/f2e5e6bd-9b11-4d1c-b399-a75d69931a5b   /srv/nfs/tv   ext4     defaults,noatime 0 2  


You'll need to find out which drive is which by running this command:






ls -l /dev/disk/by-uuid/

and:

mount

You should be able to figure it out from there....

Given that Raspbmc is a Debian based distribution, it makes sense to use NFS shares - Kodi supports it and it has less overhead than CIFS/SMB.

Setting up the server:

This should be easy right? Really really simple... But... unfortunately...
So loads and loads of tutorials will tell you that all you have to do is install nfs-kernel-server and set up your exports. This just won't work. There's a couple of problems to solve first.

rpcbind

I'm not sure this is necessary (I'd love it if someone could give this a go without this step).

This isn't enabled by default and is needed by nfs-common. Furthermore, update-rc.d just isn't set up correctly. So... you can't just tell it to load up on default runlevels. Instead you have to issue this command:

sudo update-rc.d rpcbind enable S 2 3 4 5

Get a blank slate

It seems even though rpcbind AND nfs-common are both installed by default, they just won't play nice. So issue the following command:

sudo apt-get install --reinstall rpcbind nfs-common nfs-kernel-server

If everything has gone right, you should get a warning about there being no exports.

Set up the directory structure for exports

This bit may seem a little unnecessarily fiddly, but bear with me.

To keep things a little cleaner, I'm going to create a directory: /srv/nfs and from there, create the directories I want to share. For me that's:

/srv/nfs/tv
/srv/nfs/movies

Set up the exports file

In /etc/exports add the following lines:

/srv/nfs        192.168.3.0/24(ro,no_subtree_check,insecure)
/srv/nfs/tv     192.168.3.0/24(ro,no_subtree_check,insecure)
/srv/nfs/movies 192.168.3.0/24(ro,no_subtree_check,insecure)

They're read-only (this could be fixed later - change the ro to rw) at this stage. Make sure the directories match up to your own. Change the allowed IP range and subnet to match your own.

Finishing Up

The boring bit... testing. Okay, so now the settings are all there. We need to get those settings refreshed. Use the following command:

sudo service nfs-kernel-server restart

And finally, test it:

showmount -e localhost

It should now show all of your exports.

Setting up shares on the clients

Your server also needs to be a client. This is so that we can generate the database so that all of your Raspberry Pi's can use the same information. So start with the server. For this bit, you need to be sitting in front of the TV that the server is installed on.

Go to: Videos ▶ Files ▶ Add Movies ▶ Browse ▶ Network Filesystem (NFS)

Do this on all of your clients (and try to set them all up in the same way).

Sharing the Library

Setting up the server

By default, kodi (xbmc) uses sqllite which seems great for a single machine! But not so good when you need to share that database. So we need to use mysql. SSH into the server again.

Firstly, we need to install mysql. Issue the following command:

sudo apt-get install mysql-server

Set up a kodi user for the database:

mysql -u root -p

Use the password you entered during the mysql-server installation.

CREATE USER 'kodi' IDENTIFIED BY 'kodi';
GRANT ALL ON *.* TO 'kodi';
/q

Setting up Clients

Remember, your server is a client. So do this on your client first. This requires being in ssh.

cd ~/.kodi/userdata

Create a file called "advancedsettings.xml" (Using nano... it's just easier). In it, put in the following:
<advancedsettings>
  <videodatabase>
    <type>mysql</type>
    <host>192.168.3.70</host>
    <port>3306</port>
    <user>kodi</user>
    <pass>kodi</pass>
  </videodatabase>
  <musicdatabase>
    <type>mysql</type>
    <host>192.168.3.70</host>
    <port>3306</port>
    <user>kodi</user>
    <pass>kodi</pass>
  </musicdatabase>
  <videolibrary>
    <importwatchedstate>true</importwatchedstate>
    <importresumepoint>true</importresumepoint>
  </videolibrary>
</advancedsettings>

Save the file and exit it. Now... this same file can be used on all of your clients. So copy it over...
scp advancedsettings.xml pi@192.168.3.71:/home/pi/.kodi/userdata

Rinse and repeat for each client.

Populating the Database

Set up your content USING THE NFS SHARES! This is important. You can do this from a client, just to be sure. I don't recommend trying to update the library from multiple clients at the same time (where the server is a client...) - this caused my server to crash.

More reading:

I ended up having to debug this as it all broke again. If it breaks for you, or you want to avoid it breaking, check out this post.