Google AIY Thoughts

Like many people I was very excited to see the Google AIY Raspberry Pi addon. Before my copy of the MagPi magazine arrived with the kit I had already installed the software on a linux laptop. One of the things I liked about the project is that, whilst it is to some extent targetted at the Raspberry Pi, it is actually a very good example of using standard modules and frameworks to produce something that is very cross platform and should work very easily on a variety of systems with very little work.

One of the aspects I would like to talk about today is the method used for the LED status indicator. Unlike the speech processing the LED is rather Raspberry Pi specific, as it depends on GPIO locationsupport which is not likely present on other platforms. However the way that this has been implemented allows you to ignore or reimplement it quite trivially in some other way.

How did they do this? Simply put they used a system called mknod to create a FIFO that can be accessed as a file. This file is then used as the input source to the led.py python script. Anyone that wants to change the led state simply writes to that file.

I have produced a simple example that illustrates how this can be done quite easily.

First the python file which will receive messages.

This simply loops until it sees user input that is equal to “Hello 9” printing what if not a:
continue
ever is input in reverse (note this is for python 2.7, if you are using python 3 you would replace raw_input with input).

Next the producer

This writes to a file called myfifo.txt , flushes the write after each line and then sleeps.

If you just run this as it is you will end up with a file containing lines from Hello 0 to Hello 9
The secret sauce is in the next bit.

This will compile the C code for the producer
use mknod to create the fifo
Launch the python script in the background redirecting myfifo.txt as user input
and then launch the producer which will write to the fifo.

There you now have a nice simply way of sending a message from one process to another.

Rolling my own Home Automation

I have been quite keen on the whole home automation trend for quite a while. I had a Ninja Block, and signed up for the Ninja Sphere too! Unfortunatly things didn’t really pan out with the Ninja platforms in the end, I am not sure what happened in the end, those of us who signed up for the Ninja Sphere, got our boxes with the system in, but the platform just didn’t seem to be ready and phizzled out 🙁

However things have moved on and home automation is picking up more mainstream interest now. There are several off the shelf solutions to choose from, however I still have bits and pieces from the Ninja Block system and don’t feel like splashing the cash to buy a whole new system. So I have been slowly getting things back to the state where I have my own system!

Step 1 Controlling the Light

My lights are some of the cheapest available, http://www.limitlessled.com/ as well as being pretty darn cheap, the wifi hub is accessible to developes and you can find information about the API online, which is handy as it means there are plenty of libraries available for working with them. My version (https://github.com/buxtonpaul/myha) is heavily based on a few others, but with some changes/additions to make it work the way I want. Namely

  1. Allow use of a messaging system, I wanted to be able to control the lights potentialy through a number of different routes. To do this I have a a service running on my home server which receives rabbitmq messages and turns them into events to control the lights.
  2. Configurable. The decision of what triggers are connected to what lights should be done through simple config file, which can potentially be used later for other things. e.g. display of state of lights/bridges?

With the server up and running I can then control lights quite easily with a bash script (which simply calls a python script that sends the rabbitmq message to the server).

Once I had control of the lights here it was pretty easy to add control of these to HA-Bridge

https://github.com/bwssytems/ha-bridge

This is a service that also runs on my home server that pretends to be a Hue bridge. This allows things like the Amazon Echo to see my lights and be able to control them.

Step 2 Sensing stuff

One of the side effects of having been a user of the Ninja Blocks platform, was that I ended up with a couple of sensors that worked with the platform, these used a 433MHz RF signal. As it happens I also have the receivers for this from the original ninja block (for some reason I decided to canabalise this). Hooking this up to a Raspberry Pi was pretty straightforward, using these instructions

Decode 433 MHz signals w/ Raspberry Pi & 433 MHz Receiver

The only thing I really had to do to get things working how I wanted was to change the way the RFSniffer program output the codes so that it flushes stdout after every line rather than buffering it up (it took me a while to realise that was the problem). I then simply piped the output of rfsniffer into my lightsender.py and it now automatically triggers lights.

Future things for me to look at involve perhaps adjusting the lights based on time of day, and linking it up with the alarm clock I am developing (more of this later!).

 

 

Online Learning – Science and Cooking

I am a big fan of online learning (or learning in general), and I periodically have a look at courses that interest me. So thought I could share some of my experiences here, starting with the first one I looked at. I will attempt to summarise the course content, style, difficulty and general presentation of the course so that you can see if it is for you.

The first online course I looked at was the EDx Harvard course ‘Science and Cooking: from Haute Cuisine to Soft Matter Science’ https://courses.edx.org/courses/HarvardX/SPU27x/2013_Oct/course/
This course mingles science and cooking, using bits from each to explain/demonstrate each. There are a number of top chefs who provide some interesting background to the course, but for me it was the science bits of it that were of interest.
The course goes into a fair amount of depth, and the review quiz’s are well spaced and sufficiently tricky that you actually need to pay attention and in some cases sit down with a calculator and work things out.
The course also has a number of (ungraded) lab excercises where you head to your kitchen and perform an experiment to underline something you have learned during the course. For example making ice-cream with ice-water and salt to produce sub-zero temperatures and demonstrate phase changes!
The course is well presented, the videos and text go together well, and it felt like they cover things in sufficient depth to actually be worthwhile without spending too long on any one thing.
Warning that there is some maths involved so, but it is not complex so shouldn’t put anyone off.

I have to confess I didn’t finish the course, I was initially trying to keep pace with it whilst it was a live course and fell behind due to life getting in the way, but I would definitely recommend the course and will try and get back to it at some point.

Disambiguation

Just to mention that there is a site http://www.sudorandom.com this is a completely unrelated site to mine. Clearly the owner has excellent taste in urls! I assume that the owner picked the name for basically the same reason as me, they like a bit of word play and wanted something to represent an open-ended site with a technical slant.

Introduction

Whilst I wait for the DNS changes to trickle through the ether, I figured I should write a quick intro. This blog is intended to be a bit of a braindump on various topics that interest me. These include general computing stuff, home brew development, running, beer, home automation, python, C, C++, QT, machine learning, video encoding, image processing, photography, machine vision and a host of other bits and pieces.

I will post stuff on my page as and when I get around to it, and will try and attribute anything borrowed from elsewhere. The current development methodology for a lot of the homebrew development community seems to be cut and paste, so I will try and highlight where this has happened when possible and also explain why I do things I do.

Thanks for reading!

Paul