Tomorrow Never Knows, chapter 1

Instead of finishing the various stories I have have hanging around (including the one that’s The History Boys meets An Education meets Doctor Who, that one is a doozie) I started a new one. I’m stumbling after 4 chapters so I offer up the first draft of the opening to shame me into either finishing it or shutting up.


Monday evening
Up here in the attic I can only hear my alarm clock ticking softly and the distant sound of a train chugging along the main line. I expect it’ll pass the house soon and I’ll see its smoke rising from behind the trees. It’s been raining all day and I’m bored. There was nothing on the wireless. Nothing I wanted to listen to, anyway. Just the usual boring old music dad likes and tedious talks about rationing and keeping the enemy at bay. It’s always the same.

It’s lucky my room has a good view or I’d just go totally insane. On a clear day I can see the sea, and the castle on the island. Today wasn’t a clear day.

Even though it’s almost August, I’m frozen. This morning I tiptoed downstairs and asked dad for some coal for my room and he almost bit my head off. He threw the newspaper at me. The headline was about coal shortages.

“You should read the news sometimes, Kim, instead of just reading old novels.”

This is a bit rich coming from him. He’s the town bookseller, you see. My reading of the old books tells me that once upon a time that would have been a lowly job. Not any more. He’s one of the most important people in the parish.

He was sitting in the old waiting room eating toast and writing a letter. He had a small fire going. He saw me enviously eyeing the warm coals.

“It’s for the customers. And we’ve got to keep the damp away from the stock. And Mrs Hopper. She’ll be in soon; she feels the cold at her age.”

I snorted and took the paper back upstairs with me. I’m supposed to help out in the shop in the summer holidays, but I’ve had a bad cold and I’m using it as an excuse. Got to admit I’m bored though, even after a week. I’ve already read both the Dodie Smith books we have in the shop, carefully so they can still be sold, and Emma for probably the ninth time. We’ve got loads of Jane Austen so I could read that anywhere and not worry about damaging the stock. I might read To the Lighthouse next. Dad says I’m not old enough, but Miss Danks put it on her reading list. Both of these facts make me want to read it very much.

The newspaper was pathetic. Eight badly-printed pages, tissue paper with type all smudged and misaligned, not like some of the beautiful books we’ve got downstairs in the shop which have lovely creamy, thick paper and beautiful letters. It was mostly news from London, boring stuff about the governments and telling us how everything is better than it really is. Hardly any pictures, except some adverts. Someone’s making a new wireless with shortwave and a record player built in. I’d love one of those. Might ask dad about my birthday present I never got. This year. Or last.

I was right. There goes the steam from the express train, heading North up the coast. A strip of sky has appeared just above the horizon in time for me to see the setting sun. The bright orange light is dazzling me. It’s painful, but it’s been so damp and dark today, I want to drink it in forever. Dad says sunsets make him feel sad. He’s crazy. The castle looks beautiful in silhouette. I think this a sign.

I wish we had a camera. Dad says we might get one next year. Like everything else I’m promised next year. If all our ships come in, what an amazing year 2035 will be.

Posted in fiction, literature | Tagged , , , | Leave a comment

Code making and breaking activities in Scratch – part 1

When I was a kid I loved making codes and still vividly remember my brother teaching me about simple substitution cyphers; I’d write messages and he’d then try to break them by looking for patterns and common letters like E to guess what offset I’d used. These were Ceasar Cyphers, or what in later life I would know as ROT13, where you shift each letter of the alphabet along by a certain number of letters. Both the sender and the recipient need to be using the same offset number, so some sort of prior communication is needed.

An offset of 3 would look like this:

ABCDEFGHIJ
DEFGHIJKLM

So A becomes encoded as D, B becomes E, C becomes F and so on.

I learned a hard lesson when my brother decoded one of my messages almost instantly. It turned out I’d left the plaintext message on the bottom of my code paper and hadn’t crossed it out well enough. He could still read it. ‘That’s not fair!’ I cried. ‘All’s fair in love and war’ came the reply. And indeed it was human errors like that that helped codebreakers in Bletchley Park break German World War 2 codes like Enigma. Many, many years later I taught a Year 5 lesson on the anniversary of D-Day in 2014 about codes and other things, and the same thing happened. One child caught another reading her plaintext. ‘That’s not fair!’ – which led to a discussion about the ethics of espionage in wartime.

So, everyone loves codes and cyphers, right? They make great coding activities as pairs of children can encode and decode secret messages whilst at the same time learning a bit of computer code, including how arrays, or ‘lists’, work in Scratch

My first project is a really simple substitution cypher, a bit like ROT13, only you can choose any offset, not just 13. You click on a sprite and it asks you for the secret number – this is the offset, or how many letters along the alphabet each letter is going to be shifted.

Here’s how to use it: you click on Scratch cat to make a simple cypher that reverses your plaintext. You can use this a back slang generator (or decoder) – discover where the word ‘yob’ comes from!

Click on Nano on the top right to encode your plaintext message. You’ll be asked for the offset value (the ‘secret number’) and Nano will give you an encoded version of your message. You decode a message by giving it to Pico, in the middle. Note that if the offset is 13 you can use either Pico or Nano for encoding or decoding, but if you use any other number you’ll need to pick the right sprite for the job. (It doesn’t handle spaces or numbers – you might want to do that as an extension activity. If you do, you may think about whether spaces make your cypher easier to crack).

This is the code for the encoder:

Blocks for encoding

This is how it works.

First it asks you what numerical offset you’d like to use, and puts this in a variable called offset. (There’s no error handling here if you type in 0 or letters – you might want to add that as an extension).

It then asks you for your plaintext message – the text you want to encode to keep it safe from prying eyes before sending it on. It puts your unencoded in a variable called plaintext.

You’ll then see a nested loop (a repeat loop within a repeat loop). The outer one repeats for the length of the message and keeps track of how far through the message it’s got using a variable called offsetcounter (which is a confusing name, I really need to change it). It does this to step through each character of the plaintext to analyse and encode it.

The inner loop runs 26 times (the length of the alphabet) for every character of the message. Each letter of the alphabet is held in a list (or array) called alphabet. It has to do this because, unlike some programming languages, I don’t think Scratch has an inbuilt way of turning text into numerical values. Nor do I think Scratch has a block that will find the numerical position of a given string in a list (though I may be wrong), which is why it has to test every character in the plaintext against the alphabet list to find that character’s numerical position in the alphabet, which is put in the alphacounter variable.

Each letter of the message is, in turn, put in a variable called temp. The code then runs through all 26 letters of the alphabet until it finds a match for the letter:

if (temp) = letter (offsetcounter) of (plaintext) then...

If this is true, we can get encoding!

The next line of code is quite complex, so let’s break it down.

Scratch blocks that do the encoding

We use the join block here. This is a string-handling block that allows you to glue text variables together. Our coded message is stored in a string (text variable) called code. Each time we encode a new letter we set the code string to be the message we’ve encoded so far, plus the new encoded character. That’s what the outer green join block does – look carefully how the colours overlap!

Let’s zoom in on the bit we’re adding each time:

Adding encoded text

item () of alphabet

is picking the coded letter from the alphabet, moving it on by the offset by picking item number alphacounter + offset. It’s a bit hard to see but there are two overlapping green blocks, one to do that adding, and another mod block.

Mod is short for modulo, or modular arithmetic. There’s an article on Nrich (that goes into way too much detail later on), and this really good article by Kalid Azad shows some great examples of why modular arithmetic is a useful trick to have up your sleeve: http://betterexplained.com/articles/fun-with-modular-arithmetic/

We need to use modular arithmetic for a couple of reasons. It’s best to think of our encoding not as sliding two lines of the alphabet along side each other (like I did at the top of the page), but as a circle (thank you tef):

Explaining modulo arithemtic to KS2 kids

This better shows what happens when you get to Z. What happens if I want to shift Z on by 3 letters? We cycle back round to the start again, so

TUVWXYZ
WXYZABC

So, with an offset of 3, Z in the plaintext becomes C in the encoded message.

Modular arithmetic also useful because I think it allows you to use offset numbers bigger than 26 – though they will be just the same as smaller numbers, but it helps avoid errors. Note that a secret number of 52 gives you the plaintext back again – why is this? Because 52 is twice 26. 52 mod 26 is zero, so you’re not doing any encoding at all!

The Scratch code is further complicated by the fact that there’s a special case when the encoded letter is Z. I’ll be honest, this was a bug I only spotted just as I was about to publish this and I ran the whole alphabet through it and noticed Z was missing from the coded message. If you encode WILL with an offset of 3, you should get ZLOO, but I was only getting LOO.

Useful debugging tips: display all your variables, add sounds like a drum and pauses inside loops to track what is going wrong. I found that the problem was caused when I was at the 26th letter of the alphabet (Z). 26 in modulo 26 is ZERO! And there’s no zeroth letter of the alphabet, so I catch this with

if alphacounter + offset = 26 then...

and manually set the encoded letter to z.

This is annoying because I had some reasonably elegant code, and now I have to test for a clunky exception right in the middle of it. Welcome to coding!

The decoder does the same process but in reverse.

Now this is fun, but it’s not a great cypher. It’s very easy to crack, partly because each letter is always encoded as the same letter making it possible to do frequency analysis if you have enough text to work on. The letter E is the most common letter in the English language, so if the most common letter in the coded text is J, you can be fairly sure that J is really E. That may suggest an offset of 5, you shunt all the other letters of the message back 5 places in the alphabet and see if the message makes sense.

Another flaw with substitution cyphers is that they allow you to spot patterns like double letters. If I encode the word HELLO using different offsets I get YVCCF or EBIIL or OLSSV. If you have an idea what the word may be, say a greeting at the start of a message, then that gives you a way in to breaking the code.

Which is why in the next session, we will make our code more cunning and harder to break by building a very simple Enigma machine in Scratch.

Posted in computers | Tagged , , | Leave a comment

Another music in a different kitchen

Dansette record playerI’ve long wanted some sort of solution for centrally storing and serving music for listening around the house. There are all sorts of commercial products (like Sonos) out there, some eye-wateringly expensive even without any storage, plus numerous open-source projects, better suited to my low-budget, Raspberry Pi-filled household. But, unless I’m missing something obvious, nothing seems to do exactly what I want. Not the commercial products, not XMBC / KODI, not Volumio, not Rune Audio (more on them later), not DLNA/uPnP servers, not headless MPD servers, not VLC… not anything. I’ve tried several of these, they all have their uses. But they don’t quite fit. Or quite work (as I type this, Volumio’s web interface has hung for the millionth time).

Here’s what I’d like to do: I want to hold all our music in some central point in the house, on a solid-state low-power device that’s always on (so this rules out a normal hard disk-drive NAS, using an old laptop or desktop computer, but suggests a RaspberryPi may be employed.) I may want to play the audio back on the device hosting the audio, but that’s not essential. What is essential, is to be able to play the audio on a laptop or desktop, and probably on an iPad or iPhone (via Airplay?) or Android phone or tablet. And possibly on a standalone RaspberryPi in the kitchen. I’d also like to listen to internet radio stations on the kitchen device.

Most solutions seem centred around having a device in the living room, plugged into the network via ethernet and plugged into the ‘hi-fi’. Do you remember hi-fi? It was big in the 70s and 80s. But it’s the space age now, and I don’t have a hi-fi in the living room, nor indeed do I spend any time in there, aside from finally sitting down at 9.50pm and falling asleep in front of the Ten O’Clock News.

My life just isn’t like that any more. I don’t sit in my arm chair, equally placed between two speakers, stroking my finely-chiselled cheekbones like Pete Murphy (out of off of Bauhaus) in a 1980s Maxell cassette tape TV ad. I never had cheekbones, even then. And Bela Lugosi’s dead.*

Volumio media playerVolumio and Rune Audio are forks of Raspify – or Rune is a fork of Volumio, I forget which. It looks like it was an acrimonious split, like The Human League splitting and becoming Heaven 17 and, er, The Human League. Or like Arduino splitting and becoming Arduino and, er, Arduino. Anyway, they are complete operating systems you install on your RaspberryPi (or similar) to play audio through an analogue output or USB DAC. These solutions tend to assume your device stores audio (or accesses a NAS) and plays it locally on a directly-connected hi-fi, but the device does not serve the audio files to other devices, which is something I need. They look cool though – both have lovely, responsive web interfaces to act as remote controls. Volumio is based on Raspbian, Rune on Arch Linux. Of the two I found Rune slightly snappier (more responsive), plus it showed album art and had a few more menu options. Even so, I wasted most of a day yesterday (but hey it was raining and I had to wait in for a John Lewis delivery that never appeared) trying out both – with limited success.

Rune Audio's web interface on a desktop computer

First problem: my audio was all on a 64GB exFAT-formatted Sandisk USB stick. It took 3 hours to copy it all there off an old iMac, so I was reluctant to change the format of this. Volumio and Rune Audio are both supposed to support exFAT drives. Except the drive never mounted in either. The OS could see it at command-line level, but the USB stick never showed up in the web interface. I tried a FAT32 stick – it showed up immediately. So I reformatted my 64GB stick as FAT32 and copied all the audio again – this took another 3 hours. (Having my audio on a drive formatted as something like FAT32 or exFAT is important because I want to be able to add audio to it on a Mac, ruling out NTFS or Linux disk formats).

I think I may have been using Rune Audio by this point – I’ve lost count of the number of times I’ve re-imaged SD cards for RaspberryPis – though I did discover a great OS X utility for doing this, Apple Pi Baker. Anyway, Rune Audio mounted the 64GB FAT32 USB stick and indexed it pretty quickly. It played audio off it! I had fun building playlists on the fly and listening to tracks I’d not heard for ages. The circular volume and progress controls in the web interface work really well.

But I could not get Rune Audio to work wirelessly. It wouldn’t even boot with one wifi dongle attached, and with my regular Edimax wifi dongle it could browse local wifi networks, but refused to join ours. I tried command line tools. No luck. So I reflashed the SD card as Volumio again, mounted the USB stick ok, indexed it (a bit slower), played audio, had to use the IP address for the web interface as the volumio.local address wasn’t working…

So it looked like I had some of a solution. The Volumio RaspberryPi wouldn’t serve audio to other clients, as far as I could tell, but it was playing audio off my 64GB FAT32 USB stick. I even got internet radio to work, which I’d struggled with previously. Then I moved it into the kitchen. At first all seemed good. It played, I controlled it from my phone. Then it hung. It hung a lot. I tried pinging it. 25% packet loss. The darn thing kept falling off the wireless network, sometimes never rejoining it. I moved it to a better location, though it had been in the same spot I’d used the same Pi & wifi dongle previously with no problems to listen to Fip. Still it kept dropping off the network.

I was about to give up entirely, when I noticed something on the back of my broadband router – a USB socket. My old O2 box had acted as a server, but they got bought out by Sky and the replacement Sky box didn’t have a USB socket. I never even checked our new BT one, but there it was – a USB socket, which accepts FAT32-formatted USB drives and will serve them (slowly) as Windows-style SMB shares. Not exactly a DLNA/uPnP media server, but there are some advantages to using this. First, cost: the broadband router is already here, and it’s always turned on anyway, so there’s a zero cost overhead. Secondly, SMB may not be the most media-friendly (or Mac-friendly) way of dishing up files, but at least it makes the files equally available to any device on the home network that will mount or play off an SMB share. I found I could play files in the Finder on my MacBook Air (though directory listings were painfully slow). KODI (XBMC as was) on my MacBook seamlessly indexed and played audio files off the stick in the router (it will also turn your Mac into an AirPlay receiver). I even found an iOS app called BUZZ Player which is a bit clunky, but it too would play audio files off the router.

So that left me with my RaspberryPi with Volumio installed (now connected by ethernet in the living room, where I don’t listen to music). I tried to mount the SMB share a few times and it didn’t work; I was probably doing something wrong, but it then transpired that Volumio gets very upset when you try to delete or ‘unmount’ unsuccessful shares. It goes into a sulk. It hangs. It’s all but useless.

So I may give Rune Audio one more try to see if I can mount the router’s SMB share in it, hoping that I one day solve the wifi problems. I may even see if I can get a DLNA/uPnP server running somewhere – perhaps even on the same Pi?!

But I am starting to think that the best way of getting music around the house would be to put a Dansette in every room. Even in the kitchen. The platters that matter.

Are 'Friends' Electric?

*I have now discovered that I still know all the words to ‘Bela Lugosi’s Dead’. He didn’t die in vain.

Update

I’ve been playing with Rune Audio a bit more. I definitely prefer it to Volumio – it’s quicker and less crashy in my experience. I managed to mount the SMB share containing all my music on my USB stick on my BT broadband router and play audio off it, with occasional glitches (suggesting the BT Homehub is indeed slow serving files). After doing some command line magic to update it to the latest build, I even got it to join my wireless network in the living room, but still couldn’t get it to work in the kitchen. I swapped out the USB wifi dongle and it works better – it will join the wifi network in the kitchen, but the audio playback is so choppy as to be useless.

So it looks like Rune Audio (and Volumio) are great solutions for playing audio back when you can wire in your RaspberryPi (or similar) to the network by ethernet. But here’s the thing: as I type this (in the kitchen) on my MacBook Air, I am listening to audio off the same source (USB stick in the BT Homehub mounted as a SMB share), pretty flawlessly in the OS X version of Kodi. I’ve had occasional glitches, compared with constant glitches and pauses listening to the same source via Rune Audio on a RaspberryPi in the same room.

KODI media player on MacBook

So here’s what I think I will do: put my old netbook in the kitchen to play audio off the router’s SMB share and also use the Spotify client. I can still listen to centrally-held music anywhere in the house on my laptop, or even on my phone using an app like Buzz Player. Total cost: £0.00

Or perhaps I should rebuild that Pi as a uPnP/DLNA server…

Update to the update

I did rebuild that Pi as a uPnP/DLNA server, wired in by ethernet to my broadband hub. I used these instructions. It works pretty well and seems much faster than the BT Homehub serving up a USB stick as a SMB share. The only downside so far is that it doesn’t handle accented characters in file names, but I’m sure that can be fixed somehow.

Posted in computers, Linux, music, Raspberry Pi | Tagged , , , | 2 Comments

Fip has moved

As you may know, I love making little internet radios from Raspberry Pi computers – mostly so I can listen to the wonderful French radio station Fip. Fip plays a mixture of jazz, left-field rock and pop, classical music – it’s hard to describe, but it is my favourite radio station in the world.

My little internet radio in the kitchen stopped working, and it turns out Fip’s streaming URL has changed – you can now find it at http://audio.scdn.arkena.com/11016/fip-midfi128.mp3

Update Feb 2020: now at http://icecast.radiofrance.fr/fip-midfi.mp3

When BBC radio changed its streaming methods recently, it took a huge amount of detective work for me to find out how to play BBC radio – which I’ve paid for as part of the licence fee – on my internet radios. More recently, Apple launched its own radio services, and I found it was impossible to listen to its Beats1 station at launch on a brand new MacBook. Even last night, I updated iTunes to the latest version and found that while I could get Beats1 to play, none of the links to genre-specific ‘featured stations’ did anything at all. Not one. Were they ALL off air at 10pm UK time?

Fip, on the other hand, actually want you to listen. They have this lovely page outlining a myriad of listening options: on FM in different French cities, on their web site, via Android and iOS apps, via satellite and finally, via a direct streaming URL. That’s the way to do it.

Posted in BBC, media, radio, Raspberry Pi | Tagged , , , , | 1 Comment

Accept no substitutes

It’s the end of term in most schools today, and I’d like you to take a moment to think about the supply teachers.

(Vested interest declaration: reader, I am one.)

Nobody loves a supply teacher. The class teachers (usually) have to plan for them. The parents are dismayed at more instability for their kids. And the children… well, I would say they hate supplies, but I think a lot relish the opportunity to re-invent the rules. Yes sir, we always sit where we want. And Peter, he ALWAYS sits in the corner with his back to the board playing with a tennis ball. And Miss always lets us play cards in guided reading.

It’s a tough gig rocking up in a different school every day, not knowing what might be awaiting you. Usually it’s fine. Some times you get beautiful plans and notes about the class and the children to watch out for. I’ve been supply teaching since January and I’ve only had 1 day when I pitched up and there were no plans at all; amazing how planning a day’s teaching used to take me – ooh, about a day, and yet I managed to conjure something out of thin air in 20 minutes – a maths, literacy and computer-less ICT lesson. Some times I’ve been given plans in a face-to-face handover, and then had the most awful day… wondering why you didn’t tell me Stephen is an elective mute. I mean I know you can’t give me a profile of every child in 5 minutes, but that might have been handy to know when questioning the class in maths. Or that Child Z has just been taken into care. Cos then, you know, I might cut Child Z just a tiny bit more slack.

Supply teaching is a fantastic way of seeing how different every school is. Let’s take marking policies. In School A it must all be in purple ink. In Academy X in green. In Primary Q they have a simple 5 colour system: green for good, yellow for outstanding, orange for moving on comments, blue for sadness, black for sarcasm…

It’s also confirmed my view of how you can take any random 30 children and, en masse, they will have a personality. Luckily I’ve only met one truly evil class in 6 months, but they are out there, and I would rather lose a day’s pay than teach them. Most have their ‘characters’, but if you’re lucky enough to get some regular gigs and get to know the children, even ‘difficult’ classes whose reputations precede them (“Oh my god, you’ve got BINDWEED class, I’m so sorry”) can be really rewarding, and contrary to the normal view of supply teachers, the children can be genuinely pleased to see you. And even some of the parents… if you managed to make a connection. But it only happens if you get to know the kids. I don’t think you can build meaningful relationships with 30 children in one day. And without relationships, teaching is impossible, it is nothing.

I don’t resent class teachers their cards and gifts at the end of term – heaven knows they have more than earned them. But spare a second for the supply teachers. Some of us are nice. Some of us try our best in sometimes hostile environments, where we are about as welcome as new material at an 80s band’s gig.

It’s our choice, I know, we take the hit of no holiday pay and no security for not planning, not assessing, not emptying the dishwasher. But we do feel a bit adrift and bereft as we find ourselves unemployed even before the term ends (nobody goes sick on the last day of term)…

Posted in education | Tagged , | Leave a comment