Ian's Blog

Coffee goes in, words come out.

Vivarium Automation: Requirements and Component Spec

It’s a little over a month until we are getting our first pet - a crested gecko. Joseph has decided that if it’s female it will be called “Scarlet”, and Eric has decided that if it’s male it will be called “Rimbaud” after the surrealist poet, partially because it is also a homonym of “Rambo”. I almost hope we get a female as it will be easier to explain.

In the mean time, we are getting our vivarium set up ready for our pet. We have just about everything we need, but managing the environment is a manual process — turning the lights on in the morning and off in the evening; maintaining heat and humidity.

Vivarium shown here with simulated occupant.

This is crying out to be an electronics project, so I’m going to make it one! In this post I’ve laid out my initial requirements and listed some suggested components. I’ll probably do one or two more covering the actual hardware build and software when the components arrive.


My requirements for the automated vivarium system are that it must:

  1. Automatically turn the 12V DC LED light panel on and off at a defined schedule
  2. Monitor temperature and humidity inside the vivarium
  3. Automatically control the 240V AC 10W heat mat to keep the temperature within defined bounds
  4. Send email alerts if temperature and humidity exceed the defined bounds
  5. Take regular photos of the inside of the vivarium
  6. Regularly post photo, temperature, humidity and status information to another computer for display on a website
  7. Fit in a 450x80mm space next to the vivarium (except components that must go inside)
  8. Be powered from a household 240V AC supply
  9. Not expose 240V AC to the probing fingers of children.

Initial Design

The requirements to operate the lights at specific times of day (requiring a proper clock), to send emails, to use a camera and to send files to a computer all push the design towards one including a “proper” small form factor computer rather than a basic microcontroller. Due to my familiarity with the hardware I have chosen a Raspberry Pi for this system. The Model A should be sufficient for the system’s limited requirements.

The Raspberry Pi’s official camera modules are easy to use and have good performance due to dedicated processing on the Pi’s GPU. I have chosen the “NoIR” camera, which lacks the IR filter of the standard camera, to improve visibility of the gecko at night. No IR illuminator is proposed as this may interfere with the lizard’s sense of time or temperature regulation.

The proposed AM2315 thermometer and hygrometer module is comparatively expensive, but comes inside a tough enclosure with a wall mount and uses the standard I2C protocol, compared to the proprietary bit-banging protocols of the cheap sensors.

Relays will be used to switch the lights and heat mat power on and off. A breadboard will be mounted to a Raspberry Pi case to keep the hardware neat while allowing for easy extension in future.

Component List

Here’s my list of the components, along with links to buy them. All but one are available on Amazon in the UK; the thermometer/hygrometer seems to be an Adafruit special and will have to be imported from the US.

Component Choice Price / GBP    Link
Computer Raspberry Pi Model A+ 18.00 Amazon UK
Wifi Dongle Ralink RT5370 4.71 Amazon UK
GPIO Breakout Pi Cobbler 10.00 Amazon UK
SD Card Kingston 8GB 4.00 Amazon UK
Breadboard BB400 1.15 Amazon UK
Jumpers Generic 1.07 Amazon UK
Power Supply Generic 6.00 Amazon UK
Case Model A Case 4.49 Amazon UK
Temp/Humid Sensorr AM2315 19.97 Adafruit
Camera Raspberry Pi NoIR 19.13 Amazon UK
Suction cups Generic 3.57 Amazon UK
Relay Board Facilla 2-channel 1.13 Amazon UK
Enclosure for mains relay    Generic black ABS 150x80x50    5.90 Amazon UK
Enclosure glands Generic M12x1.5 1.59 Amazon UK
  Total: 100.71  

Stay tuned for build photos, schematics and source code once all the components arrive!

Update: It turns out the heat mat was bought with its own dedicated thermostat. With this in mind I’ve decided to ditch the timed control of the lights and use a standard mains plug timer instead. This will be easier for people to override if necessary, rather than depending on whatever software interface I provide.

Since the system is therefore not controlling anything I can ditch the relay board and the requirement to use a proper glanded enclosure to protect the 240V AC switching relay. It will still take photos, monitor temperature and humidity, display them on the web, and email on important events.

The Case Against Academies

Our son’s school is consulting parents on its proposed transformation into an “Academy”. Since ranting about online this earlier today, I’ve been asked what my reasons are for opposing the change from a Local Authority funded school to an Academy.

Here are my reasons, which I am also using as part of my response to the consultation. I have removed some of the hyperlinks in this version as they would identify my son’s school.

  1. I am worried in general about the extent to which public services have been sold off over the past few decades, and have no desire to accelerate the problem further by condoning the selling off of education services as well. I believe it is the national and local government’s duty to provide high-quality education for all and to ensure every child has an equal opportunity to learn and develop. Whilst complete equality is still a way off, privatising education is a step away from it, not towards it.
  2. The move is transparently motivated by money. The FAQ provided by the school says plainly that the academy plan came about because the council can no longer afford to pay for schools in this area. This is a terrible state of affairs, but one that I believe should be solved by taxation and efficiency savings at the local authority rather than selling off vital services.
  3. I am alarmed at the rate at which the conversion to an Academy appears to be proceeding. Under the question of “When will the school become an academy” (emphasis mine), the FAQ states “We would expect that the process will take 4-6 months, work is underway and the planned conversion date is 1 November 2015.” This implies that work on converting the school to an Academy may have been underway for over a month before parents were consulted. I do appreciate that it is up to the school board and not the parents to decide. However, the Academy plan has been presented very suddenly in a way that makes the change appear almost inevitable. There is no guarantee that even 100% of teachers and parents voting against the plan would be enough to stop it.
  4. Becoming an Academy involves staff taking on greater responsibility for the school’s management and financial matters. This may involve existing staff, who would then have other agendas than the education of the children in their care, or it may involve hiring consultants / extra staff to manage these issues, which removes money that would be better spent employing teachers and improving facilities.
  5. Academies have some freedom from Local Education Authority guidelines when it comes to hiring teachers, leading to the possibility that Academies could hire less qualified teachers in order to save money. Another possibility is that Academies in higher-income areas could “poach” teachers from schools in lower-income areas by offering higher salaries, and in doing so decrease the level of equality in the education system. The NASUWT and NUT oppose the national Academies scheme, saying that it will “segregate and fragment communities”. [NASUWT Statement]
  6. Academies also have freedom to set their own “broad and balanced” curriculum that may diverge from the National Curriculum. As an atheist whose son attends a Church of England school, I worry that this may include a greater focus on religious studies at the expense of other subjects. Although the former Secretary of State for Education dismissed the idea that schools would be able to teach Creationism in science classes, less extreme changes in this direction could still be possible. [Politics.co.uk]
  7. Schools controlled by the Local Authority are democratically accountable to the local community. The Academy plan would see the school accountable to the board of a charitable trust, which while it is highly likely to operate in the school’s best interests, is not accountable to the community in which the school resides.
  8. Academies receive 4-10% extra funding over schools under local authority control, as they are funded direct from central government. However, this extra money would otherwise have been spent by the local authority to provide services for all local schools, such as help for children with special needs. An increasing number of local Academies means decreasing local funding for special needs children, which is extremely important. [BBC]
  9. No financial information has been provided alongside the proposed plans. It is therefore not clear if this extra 4-10% funding is sufficient to turn what the council say is an unaffordable school into an affordable one, particularly with the addition of an “umbrella” trust which must also be paid for. It is therefore unclear whether our son’s school would see an increase or a decrease in its net funding, and if this is a decrease, where costs would be saved.
  10. Academies have a poor reputation in the local area, as many local Academies were failing Comprehensive schools that were taken over (not always successfully) in order to improve their standards of education. I am concerned that the Academy “branding” will damage the reputation of our son’s school, which previously has been regarded as one of the best schools in the area.

Preparing to Leave Heroku

An email today announced a beta test of some new features that Heroku are “excited” to introduce. New service levels are available that include a “hobby” tier that does… exactly what the old “free” tier used to do. For $7 per month per app!

The free tier has now been downgraded so that it must “sleep” — i.e. be unavailable — for at least six hours a day.

As a long-term abuser of Heroku’s free tier, I’ve enjoyed continuous uptime for all my sites courtesy of Heroku. A lot of sites.

All of which I now have to slowly migrate off Heroku as freeloaders like me are no longer welcome!

The sites that are static HTML (including the Octopress sites) and PHP have in the main already been migrated back to my own web server over the last few hours, and I’ll continue to monitor usage statistics over the next few days to ensure it can cope with the extra load.

Some sites using Ruby, and others that depend on HTTPS will be a little more difficult to move. Certain sites such as the SuccessWhale API that require high bandwidth and good uptime may stay on Heroku and move up to a paid tier if required.

Hopefully none of this should impact users of the sites, but please let me know if you find a site or application is inaccessible or suffering from poor performance.

“Archive by Year” Aside for Octopress

One thing that’s annoyed me since migrating my website from Wordpress to Octopress years ago has been the lack of an “archive by year” widget for the sidebar. The Wordpress widget that fulfills this function lists each month and year, with the number of posts in that month, and each one is a link to a page that shows all the posts from that month.

As you may notice on the right-hand side of each page, I decided to recreate something similar in Octopress. There are a couple of differences:

  1. Octopress doesn’t generate pages that show all posts from a particular month (or year). It does generate an “archive” page with links to all posts in order, which is what I’ve used as a destination for each link.
  2. Partly as a result of this (and partly because I’ve been blogging far too long), I decided to stick with one link per year rather than one link per month.

My first modification was to the “archives” page. To this I simply added a named a tag to each year title (see line 12 below). This allows each year title to be used as a bookmark and linked to appropriately.

layout: page
title: Blog Archive
footer: false

<div id="blog-archives">
{% for post in site.posts reverse %}
{% capture this_year %}{{ post.date | date: "%Y" }}{% endcapture %}
{% unless year == this_year %}
  {% assign year = this_year %}
  <h2><a name="{{ year }}"></a>{{ year }}</h2>
{% endunless %}
  {% include archive_post.html %}
{% endfor %}

The code that generates the widget (or “aside”, in Octopress parlance) can’t be written in a single .html file using Liquid tags as it is too complex. Thus I implemented it by defining a new Liquid tag called archive, as follows.

module Jekyll
  class ArchiveTag < Liquid::Tag
    def render(context)
      html = ""
      yearData = Hash.new

      # Get range of years for which there are posts
      posts = context.registers[:site].posts
      firstYear = posts[0].date.year
      lastYear = posts[posts.size-1].date.year

      # Build up a map of {year => number of posts that year}
      for year in firstYear..lastYear
        yearData[year] = posts.select{ |post| post.date.year == year }.size

      # Build the html items
      yearData.sort.reverse_each { |year, numPosts|
        if numPosts > 0
          html << "<li class='post'><a href='/blog/archives##{year}'>#{year} (#{numPosts})</a></li>"

      # Write out the html

Liquid::Template.register_tag('archive', Jekyll::ArchiveTag)

The final piece of the puzzle is to create an aside to display the new tag, which is done simply as follows:

  <ul id="archive">
    {% archive %}

Adding asides/archive.html to the default_asides section in Octopress’ _config.yml adds the new aside to each page.

The end result is just like the one you can see in the sidebar of every page on this blog: a list of each year for which there are posts, in descending order, suffixed by the number of posts made that year. Each item in the list is a link to the main “archive” page, jumping straight to the bookmark for that year.

This code is in the public domain so feel free to use it on your own blog and modify it however you like!

Another Decade Older

Time flies when you’re having fun. And somehow, without really realising it, I turned thirty years old.

I’d say I’ve come far from where I began — but though I’ve been a way, I came back, and now I’m not so very far away after all. I live in the same town; have the same comfortable life; have a son who for all the world looked at age one just like I did.

I might have longer hair and smaller glasses, but the “me” I remember from age 10 is not so different to me now — we like computer games and robots and long walks on frosty winter afternoons, and I ended up with the career I always knew I’d have.

And me at age 20, I remember him vividly. We still have the same friends, the same memories; we like the same films and most of the same music; we live for the light of the summer and the laughter of our friends.

And now I turn 30, surrounded by those same friends who have been with me so long, and the family who have been there even longer. I have a family of my own, and the cycle begins again.

I have a wife and a son, a home and a job; a family and a life just like those back where I began.

My parents told me a story once; how they had a plant they couldn’t identify growing in a pot on the front porch. One day, at last, it bloomed into flower — it was a lilac. My father brought the flower to my mother, who was in hospital about to have a child.

It was the beginning of May, of the year 1985.

Every year since, I’ve known that Spring was on its way by the pink and white blossom of the lilac trees. Thirty years I have counted this way, and many more I’ll count in years to come.

For the rest of my life and thousands more once I am gone, lilacs will be special to me and to countless others, as they announce the start of the year’s long warm days; the days we lived for, the light of the summer and the laughter of our friends.

A Case of Stolen Identity

London is a strange place.

Not the places the tourists see — the shopping streets, the palaces, the museums. Those I understand. What’s strange to me is the rest of it; the places where people live and work. The estates of a thousand homes, red-brick and identical and unaffordable, each one hiding its own stories and secrets behind its unremarkable façade. The big houses split into dozens of tiny apartments, crammed in between the gas works and the scrap metal yards. The million-dollar cookie-cutter canal-side apartments, and the dirty bedsits under the railway bridges.

What gets me is the sheer scale of it all. You can drive for hours and never leave the city. Everything is there, you could live your whole life there — walking in St James’s Park and thinking it’s the country; sitting on the sand at Southwark and thinking it’s the seaside; gazing out at the Thames estuary as if it were the sea.

My own town is only a couple of miles wide, with a population just under 200,000. It’s too big for me — one day, perhaps, I’ll get that slate-roofed cottage in a little village by the sea — but it’s a place I feel comfortable, a place where I have an identity. Perhaps it’s the upper bound on the size of place that I can consider without feeling crushed by it all.

I’m pretty sure I wouldn’t survive living in London. It astounds me that others manage it; to get through each day in the knowledge that you’re one of 20 million people living in one of a million homes; catching the rickety tube train home at night to a suburb and a street indistinguishable from the rest.

And London I’m sure is not the worst offender. Take this famous photo of Barcelona from the air, block after block of apartments and shops and offices and millions on millions of people stretching all the way to the horizon.

Or worse still, this diagram superimposing the extent of the Tokyo metropolitan area over a significant portion of my entire country. It’s population is nearing 40 million.

I have nothing but respect for the people who can survive living in such a place. I hope that I never have to, for I’m sure that a year and a day in the city would be the end of me. I’d be swallowed up by the enormity of it all, the drudgery pervading my soul, my name and my identity lost in the choking air that spirals up and out over the city.

The End of the Road for SuccessWhale’s Facebook Support?

My SuccessWhale application has long supported both Twitter and Facebook social networks, despite both networks’ relatively developer-hostile stances. The worst offender by far was Twitter, with it’s 100,000 user limit that has deliberately crippled many third-party clients in order to drive users to the official website and app, which make money for Twitter through adverts. While I was never under any delusion that SuccessWhale would be popular enough to reach 100,000 users, it’s not a nice thing to have hanging over your head as a developer.

Facebook’s permissions policy, as I have ranted about before, also makes it difficult for third-party clients to deliver a useful service for their users. With the new requirement that apps migrate to API v2, they are adding the extra hassle of requiring all apps be reviewed by Facebook staff. This isn’t a problem itself — SuccessWhale has been through the somewhat scary process of manual review before when it was added to the Firefox Marketplace.

But Facebook has now snuck something extra into the notes for some of its permissions, each of which must now be manually approved as part of the review process. Into pretty much all the permissions that are fundamental for SuccessWhale, such as read_stream:

Yep, this permission will be denied, as a matter of policy, to apps running on Android, iOS, web, desktop, and more.

So predictably, SuccessWhale failed its manual review and has been denied approval to use Facebook API v2.0 or above. As far as I can tell at this point, that means on May 1st all Facebook features of SuccessWhale will cease to function. Facebook, ever the proponent of the walled garden path down which Twitter has ventured as well, has struck another blow for increasing their profits and user lock-in at the expense of the open web that SuccessWhale depends on.

It’s a sad time for the web; the “web 2.0” of mashups and free access to data is slipping away with it. And though Facebook’s change does not kill off SuccessWhale and its kin outright, the future does not look rosy for us developers that believe users should be free to access a service in a way they prefer.

Fun With Playbulb

Playbulbs are colour LED lights sold by a company called Mipow. They come with an iOS and Android app that can set their colour and various patterns via Bluetooth. There’s no security on them whatsoever, so any nearby device can connect and change their colour. That seems pretty bad — especially when you consider that as well as the small “candle” style lights we have, they also sell room lighting versions that play music and can probably flash fast enough to trigger photosensitive epilepsy. Controlled by your neighbours!

Despite the security problem, this does have one advantage: it’s easy to get any other device controlling the Playbulb, not just a phone with their official app. Anything with a Bluetooth 4.0 Low Energy transceiver can easily control the Playbulb using tools like those provided by BlueZ under Linux, and the protocol is somewhat understood. This means it’s pretty easy to control a Playbulb programatically using the language of your choice.

Here’s a demonstration I knocked up this morning: mailcheck. This python script checks an IMAP mailbox at a defined interval, and will set the Playbulb colour to red if there are no unread messages, or green (with a brief flash) when you have unread mail. It was inspired by similar “ambient electronic devices” such as Nabaztag. Here it is in action:

It’s BSD-licenced open source, so if you have a Playbulb you want to have some fun with, please take my code and use it for your own ends!

IKEA Navigational Cheats

It was suggested on IRC last night that the sad, cautionary tale of Sultan Hamnvik may have its roots in my simple lack of knowledge — particularly of the “cheats” that allow for easier navigation around IKEA’s torturous, non-Euclidean shop floors.

I’d like to take this opportunity to refute that claim by presenting a set of simple IKEA navigational cheats that I feel will help newcomers avoid the Sultan’s fate.

1. Set off the Fire Alarm

Amid thousands of fleeing people, not only does the fire escape become an exit route that can be used without arousing suspicion, but the Dread Guardians of the Store will be forced to flee also. This gives you the perfect opportunity to make your escape and flee into the night, never to return.

Break glass with IKEA for Mice™ sledgehammer.

2. Disassemble Partition Walls

IKEA is known for forcing its victims on a torturous journey around what, once upon a time, would have been an open space. Luckily, this can be rectified. A number of tools are available for purchase in IKEA, such as screwdrivers, hammers and drills. Use these to disassemble partition walls to open up a more direct route to the exit.

If you have one, wear a high-vis jacket for this cheat. No-one questions why you’re removing a wall if you’re wearing a high-vis jacket.

Beyond the wall lies freedom from tyranny.

3. Man the Barricades

Flat-pack products can, with some difficulty, be turned into functioning beds and tables. With a little more effort they can also be built into functioning barricades, which you can deploy at key points in the store and refuse to leave until the CEO of IKEA is sent to the guillotine. Without its head, the Beast Known as IKEA will slowly disintegrate into dust.

This method will earn you 1240 exp and 300 gold.

And a role in a prominent West End musical.

4. A Class at Miskatonic University

For those who have knowledge of such dark and insidious things as the workings of IKEA, the subtle geometry of their stores can be exploited. Seek refuge in shadow, blend in and slip through darkened corners into worlds of eternal night, emerging at will in other places and other times. Hopefully ones well away from IKEA. Beware the Yellow Sign.


5. Flat is Easy

Navigating the store becomes easy when it is reduced to rubble by a period of sustained naval bombardment. Shelter in the basement until the explosions stop, then emerge to discover a brighter, IKEA-free world.

Croydon IKEA (before bombardment)

6. Through the Wardrobe

Head to the bedroom section and seek out a pine-effect wardrobe called “NÄRNIJÄ”. Enter it to find yourself in a snow-bound fantasy land. You will be harassed by the minions of the White Witch, but I think we can all agree that this is safer and more enjoyable than the average visit to IKEA.

Defeat the witch to emerge in your grandparents’ attic in the year 1942, conveniently giving you the opportunity to stop IKEA from being created in the first place.

The IKEA board of directors meets for the Monday morning leadership briefing.

7. The Only Way to be Sure

Nuke it from orbit. It is, as they say, the only way to be sure.

Some collateral damage to local populations is to be expected, but I think you’ll agree this is a small price to pay to rid the land of the monstrous beast that is IKEA.

All those poor meatballs. Rest in peace, mixed with delicious iodine-131 sauce.

8. An Alternative Approach

Don’t go to IKEA.

All-Terrain Raspberry Pi!

Another year, another childrens’ toy with a Raspberry Pi needlessly attached to it.

Over the past few weeks, I’ve been taking one of my son’s old broken RC toys and turning it into something a bit more fun — by strapping a computer to it, naturally.

The result is the “All-Terrain Pi”, a robot which can be controlled by smartphone as if it were a racing game, or by using the kid-friendly Scratch programming language.

Here’s a video of the smartphone interface. It all runs in the web browser, with no need to install an app on the phone. Full-screen (ish) video streams from the robot’s on-board camera, while speed and turning are controlled using touch and tilt controls implemented in Javascript.

Programming in Scratch is possible too, recreating the 80s/90s Logo “Turtle” experience for a new generation. As with the smartphone interface there’s a Python program behind the scenes controlling the motor driver board, but this time it receives commands via Scratch’s “Remote Sensors Protocol”.

It didn’t take long for my son to get into controlling the robot, both with the game-like smartphone interface and using Scratch, which he has some experience with from school. (They start programming young now!) We took it to last weekend’s Constructorium hackerspace event at the library, where it was a big hit — by the end of the afternoon, he was teaching the grown-ups!

“Proud” is an understatement.

I’ve finished all the things I set out to achieve with this robot, in a total of only 20 hours or so. Thanks to a pre-made motor driver board and a Raspberry Pi camera fork of mjpg-streamer, some of the hardest bits of the project turned out to be very easy, so I’m very grateful to everyone whose work I’ve built upon to create this robot.

I’m hoping we might be allowed to take the robot into school and maybe hold a competition for the kids to write a program to steer it around an obstacle course; or something similar — to make programming more exciting by taking it off the computer screen and into the real world. If the teachers don’t let us do that, we might hook it up to the internet and have it controlled using redstone circuits on my son’s Minecraft server.

You can find a step-by-step guide to how I built the robot on the All-Terrain Pi page and all the code is open source!