Tagged: linux

Rooting The Nook

I was inspired by Matthew Petroff's Kindle Weather Display to do something similar with my old Nook Simple Touch Reader.

I had planned to use a salvaged eInk screen - but the Nook STR (or NSTR from now on) is only £29 due to a massive price drop. The Glow version is a mere £69 - so I bought that and have set my old NSTR to work as a "Family Display Screen".

The idea is that this will stay by the front door, show today's weather, mine and my wife's calendar, as well as other useful bits of information.

Step 1 - Rooting

It's now dead easy to root the NSTR using NookManager.

  • Download NookManager from XDA.
  • Unzip the file - there should be a disk image in there; "NookManager.img"
  • You'll need to use a micro SD card to create a bootable disk. In Linux it's as simple as
    dd if=NookManager.img of=/dev/sdb1 bs=1M

    Windows and Mac users, will have to find tools to help them.

  • Turn off your NSTR (hold down the power button on the back, then confirm on screen).
  • Stick the micro SD card into the NSTR.
  • Turn on the NSTR and follow the on-screen instructions.

And that's pretty much it!

There are, effectively, two options for how to proceed.

  1. Point the default browser at a web page and use meta-refresh / JavaScript to update it every so often.
  2. Automatically push an image to the NSTR to be used as its default screensaver

Can Oneko Help Beat RSI?

(Praying to Betteridge!)

For the last few years, I've been using ergonomic computer input products such as the Microsoft 4000 keyboard and the Evoluent Vertical Mouse. I spend a lot of time on my computer - and I know how crippling the pain of RSI can be - especially for someone who relies on their laptop to earn a living.

Recently, I've added a new tool - Oneko!

Oneko is a little cat who follows your mouse around the desktop.

Neko has a long and illustrious history. I remember using him many years ago on Windows 3.11. Back then, I would happily distract myself by whizzing the cursor around all day long.

Nowadays, I'm using that distraction to my advantage. Whenever I move the mouse across my screen, Oneko chases it - slowly. His cute and fluffy eagerness is distracting - and that forces me to consider whether I really want to use my mouse at all.

There are some things on a modern desktop which are simply impossible to do without a mouse - or so cumbersome that no sane person would attempt them. It's particularly problematic on the web where elements are placed so higgledy-piggledy that tabbing through the page is an exercise in extreme frustration.

It's interesting to note that sites like imgur relying heavily on keyboard shortcuts for power users.

Google's search results are also very keyboard friendly. I'm also beginning to explore the other accessibility tools Linux has to offer.

In web design circles, we often hear about designing for visually impaired users but we seem to spend a lot less time taking about those can can see, but find movement difficult or restrictive.

Having large target elements is useful for those whose mousing skills are under-par, but designing a website which can be used only from the keyboard? That's a challenge.

Of course, depending on your mobility, a keyboard-only approach may not be useful for you - but I find it very helpful to minimise my mouse contact.

So, for now, Oneko is going to help me lose my love for the mouse.
I_love_Neko

Position

If you don't want Oneko to be right on top of your mouse cursor, you can set an offset position. You can adjust the horizontal and vertical position like so:

oneko -position +100-50

The first number is the X offset, the second is the Y offset. Use + or - to set the position relative to your cursor.

Screenscraping Album Artwork From The Linux Command Line

Like many people, I've collected a fair number of CDs over the years. As hard-drives and MicroSD cards have got larger and cheaper, I've gradually been ripping them to FLAC. Most CD rippers automatically tag the music files with the correct metadata and, nowadays, they will also download and embed album artwork as well.

(As an aside, it always boggled my mind that CDs don't come with metadata burned onto the disc. Even a single spare megabyte would be enough to hold detailed track listing, artwork, etc.)

Back when I started, there was no way to get album artwork. Most media players will recognise that if a .jpg is in a folder with music, then it should be treated as the album artwork. This file is usually called "cover.jpg" or "albumart.jpg" - but that's only convention; any name will do.

So, rather than re-rip all by CDs, I wrote a quick bash script to scrape the images from albumart.org. First the script and then some notes about the choices I made when writing it.

#!/bin/bash -e
  1. # get_coverart.sh
  2. #
  3. # This simple script will fetch the cover art for the album information provided on the command line.
  4. # It will then download that cover image, and place it into the child directory.
  5. #
  6. # ./get_coverart.sh <relative -path>
  7. #
  8. # get_coverart Beatles/Sgt\ Pepper
  9. #
  10. # get_coverart Beatles/Sgt_Pepper
  11. #
  12. # get_coverart "Beatles - Sgt_Pepper"
  13. #
  14. # To auto-populate all directories in the current directory, run the following command
  15. #
  16. # find . -type d -exec ./get_coverart "{}" \;
  17. albumpath="$1"
  18.  
  19. # Escape any problematic character
  20. encoded="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$albumpath")"
  21.  
  22. # Skip if a cover.jpg exists in the directory
  23. if [ -f "$albumpath/cover.jpg" ]
  24. then
  25. echo "$albumpath/cover.jpg already exists"
  26. exit
  27. fi
  28.  
  29. # Tell the user what is going on
  30. echo ""
  31. echo "Searching for: [$1]"
  32.  
  33. # scraping AlbumArt.org
  34. url="http://www.albumart.org/index.php?skey=$encoded&itempage=1&newsearch=1&searchindex=Music"
  35. echo "Searching ... [$url]"
  36.  
  37. # Grab the first Amazon image without an underscore (usually the largest version)
  38. coverurl=`wget -qO - "$url" | grep -m 1 -o 'http://ecx\.images-amazon\.com\/images\/I\/*/[\%0-9a-zA-Z.,-]*\.jpg'`
  39.  
  40. echo "Cover URL: [$coverurl]"
  41.  
  42. # Save the imager
  43. wget "$coverurl" -O "$albumpath/cover.jpg"</relative>

Notes

I originally suggested this as an enhancement for the popular ABCDE Linux ripper.
It's based off this older, now obsolete, script.

AlbumArt.org uses images from Amazon.com - why not just use the Amazon API?

The Amazon API is great but it requires that you get an account with Amazon and include an API key with every request. That means you can't just dump the script on a box and start downloading - you'd need to configure it first?

Why the change from XPATH?

I love XPATH and use it regularly. What I found when deploying this script to a new Ubuntu install was that xmllint wasn't installed by default. On the other hand, grep is installed on every machine. Seeing as how the Amazon images are a fixed pattern, a regular expression works just fine.

What if there are multiple results from a search?

This will automatically download the first one. As this is a command line tool, there's no practical way to display the various images.
I did look at ASCII art conversion, but that's problematic.
Some albums work well - e.g. Little Mix's DNA

.=====+++O887?+++.+===~~INMNMMMMMN?~==~.
.=7I+=~~NMM8ND$=+.====~OMMMMMMMMMMMD~=~.
.~=+=ONMD8ZNNN88I.~~~~:MMMM=?MMMMMMMN=~.
.~==ZNN+:,,,N8ODO.:~~~=NMMZZ:$MMMMMMN=~.
.===NZNII..+O88ONI.=~:=,DM+$::7NMMMMN:~.
.+=7DD8,::~,,DD88O.OOIZOMMM~=7.+MMND+~,:
.=+8DND+,:~,=DD8DD~,8DZ+:NMZ?~?8MMMNNMO~
.==DNNNNI=++NDDNNDZ$MNOOOON7++IMMM8?==~M
.+?NMNNN78N8MNNNNNOI?+???I?I+=+IM8$+++I:
.=NMMMNDN==MNNMNMN$=+?8$I+?+==+???III==+
.8NMMMNN?=+M$IIII:I,77II7D?+~~=??:ONMNZ?
.MNMNMMZ7~+MO7~II:7=7???77$,......,:??=M
.MMMM8=.......,~=~=.I:I,7,I=+==+=====+=.
...,~=?8D878DO+~~~=?~=7++NNM8NNMD===+==.
.==~=~DD8DNNON8+7I=+?=78ND~:::~NNNI===~.
.==~~~NI:,,:I88+:~~~.~=8M?:,?,=+NOM7+=~.
.=~=~~8~,...,?8~~~~~.+=MDND:,I::8MMZ=+=.
.==~~~ZDD+.+7+$~~~~~,,~MM7:~=.,=DNNMI+=.
.~~~~:?:,~,,,7=:~::~~.+NMMI7:~:~NDNNN+=.
.~~==~:I,,,,~D::~:~~=.DMDNNI::O+NN8DN+=.
.====~=:,,,~N~:::~~==.N8NDDN+=~+DOODN$=.
.+====~D+,M~~,.,:====.ND8NNN+::=DD8OND=.
.??,++++I~,?+:,,:::~+87D8DNM:::~MNODND=.
.?=,.~=~,+,$+?+??++~IMNNNMNN$,,,MNNMNNOI
..$+~~=.:~,Z====++++7MMNMNM,~,,,MMNNNMM.

Whereas Sgt Pepper is hard to make out.

:::::::::::::::::::::::~~~~~~::::::,,,,,
:,:::::,~::==:::O7~~:~8~=~~=Z+~:I:::,,,.
~+.:+8~D7:::~+8??:==I:O?~$:~$ZI=7IO:,,~:
:I$=,N$=:8O7?7+I?=.8?78OI:~+I~7O$Z$O+?$:
,O$.~D8$~~Z+ZD7$$DOO=8ZZ?OI8?:D7=887Z8Z?
~87+Z$+:~8+,:OD8O~=NDD7OO$+Z8D:ZDDDD88Z?
$O88Z8?DDD?ZZN+ODI,D?88D887$7=D8D+D8O8Z=
,7ID=88II7IOZ7ZZZ7$:===$77~I:~88ZIIO88$?
~..DDDDDDDDOIN=7$7~?I?=OIZ$I:$Z7+?Z+88ZI
Z+,8DDDDDDD+D7O?8ZZ777?8Z8I==OD~8~D$7OZ?
,,D8DDDDNDDDO8Z=$Z8+IZDOZ+ZI+D?88+78O8~=
I?ZDDDDNDN8N=+O+7II$7?ZO+Z$7I8DDOZ?DDII=
=~DDDONNNNNDZZOZZI+?Z+87OOZOZ$8D888D8+II
+=D8NNDDDNDD8N+Z,?OZ~?~88ODOZ+ODDD88DI:?
~~DDDDD8DNDDDO~??:,+7~=DD8DNDDD8788:D,::
~=D8==8DDNNNDO=$=?O$~I:DDO$?DDDDDDD=?OZ+
OD8DZONNDNNDNNN=~7~Z+,DNN8?$DNZZ?DDDO8$7
7O=O8:D78DZNZZN77$7OD8?7$I7=?~D$O8O~~Z7I
=Z$O88D$N$O8N88ZZZ$ON8NDNNZO7ON$7OD8?Z$~
IZD8ZOD8O$OOD$8DDNZNN$DDNN$8ZDNDO$DDZ8OI
7ZDO8ODDO8DOD8N88$ZNDDNDNN8DD8N8$OOZ8O$?
IZDNNNNN8NNNNNNNMZ7N=+Z7O=O7ZI:~DD8DD8OI
Z8DND+$Z+OD+NNNDN8DNDNNNN++I+$=ZDDDDDD8?
ONNDDNO8=D8NNNNDDZD8~NNNONNNNNN8NDDDDDD$
8D88ZNNNOONNNNNDDD$ODNDD8ZMNNDN8D8NNDDDI

There are amazing tools like aview - but again, that's an extra program which the user might not have.

If your album directories are sensibly named, the first hit is usually good enough.

Hang on! There's a mistake!

Quite probably, this is a quick and dirty script. I'm sure there are lots of edge case and (no-doubt) some poor coding practices. If you wish to contribute a patch, please drop it in the comments.

Inkscape - cropping SVG files on the Command Line

A little post as an aide-mémoire.

I've found a lovely set of SVG playing cards. The only problem is each image is displayed within a page. This means the relatively small cards have an enormous white margin.

Within Inkscape (the vector image editor for Linux) it's possible to crop the margins by going to:

File > Document Properties > Resize Page To Content > Resize page to Drawing or Selection 

That's a pain in the arse for adjusting 52 images. Luckily, Inkscape will take command line arguments (called verbs). This means we can point it to all SVG files in a directory, instruct it to Fit to Drawing, and save the file again.

It all takes place on one line.

inkscape --verb=FitCanvasToDrawing --verb=FileSave --verb=FileClose *.svg

Run that, the Inkscape window will pop up for each file, and automatically close once saved. I'm not sure if there's a way to do it on a headless install.

3G Internet on Raspberry Pi - Success!

This is a bit of a brain dump of how I got a 3G USB dongle working on the Raspberry Pi. Following on from getting the Raspberry Pi to send SMS.

That's The Power Of Love

The first thing to say is use a powered USB hub! I had lots of problems getting the modem working when it was plugged directly into the Pi. A 3G signal takes more power than the Pi's USB sockets can supply.

3G Raspberry Pi

In the above image, you can see that the Raspbery Pi is plugged into the mains - via a 1.8A plug.
The USB cable has two male ends. The black plug goes directly into the Pi for data. The red plug goes into the mains via a 1A plug (an Amazon Kindle adapter).

I used a USB Y Cable to supply power and data.

I also tried plugging both plugs into the Pi - that didn't work either. You need a separate powered hub.

Rather than use two plugs, I'm going to try to find a mains plug with two USB sockets. Each socket needs to supply at least 1A. Something like this looks like it should do the trick.

Or, you can use a cable like this.

Put one male USB plug into the PI and the other into a power supply. The dongle fits into the female USB socket.

P-p-p-p-pick Up A PPPD

In order to get our network connected, we need to install the ppp package.

sudo apt-get install ppp

If You Think I'm Sakis, And You Want My Body...

I tried using wvdial and numerous other ways to connect to 3G. None of them worked reliably. In the end, I turned to sakis - the All-In-One script for connecting 3G modem.

Sakis says it is:

"The easiest way to have your 3G/UMTS/GRPS connection up and running."

I can't argue with that!

Installation is very simple:

First, download the latest version. The Raspberry Pi runs on an ARM processor, so this is the version we download.

wget "http://www.sakis3g.org/versions/latest/armv4t/sakis3g.gz"

The script is compressed. Unzip it.

gunzip sakis3g.gz

Finally, we want to make the file executable so that we can run it.

chmod +x sakis3g

Running sakis is quite straightforward. It has a basic GUI which will work even if you're just using the command line.

sudo ./sakis3g --interactive

sakis3g interface

Sakis has a fairly comprehensive list of connection details - it should find yours automatically and present you with this screen.
sakis3g interface APN

If it doesn't know your connection settings (if you're on GiffGaff for example) you can manually enter them.

All being well, after a few seconds, you should see this screen.
sakis3g interface connected

You can now exit sakis. You will stay connected.

To check the details of your connection, run the following command:

sudo ./sakis3g connect info

You'll get back something like this:

K3565 connected to giffgaff (23410).
Connection Information
 
Interface: P-t-P (ppp0)
 
Connected since: 2012-07-13 07:36
Kilobytes received: 2
Kilobytes sent: 2

Network ID: 23410
Operator name: giffgaff
APN: giffgaff.com
 
Modem: K3565
Modem type: USB
Kernel driver: option
Device: /dev/ttyUSB0
 
IP Address: 10.136.6.52
Subnet Mask: 255.255.255.255
Peer IP Address: 10.64.64.64
Default route(s): 10.64.64.64

That's it! You can now access the Internet via your 3G modem.

Surfin' Safari

One last tip for you! There's no need to start your window manager to surf the web. There's a brilliant lo-fi web browser called Lynx.

You install it by typing:

sudo apt-get install lynx

You run it by typing:

lynx http://www.bbc.co.uk/news

(or whatever website you want to visit).
lynx on the Raspberry Pi

So, that should be everything you need to get the Raspberry Pi connected over a USB 3G dongle. Have fun!