MPI (Message Passing Interface) – Part 1

Introduction

In a previous post I touched on the fact we would be examining HPC (High Performance Computing), parallel processing and Hadoop in relation to Home Automation.

As our home network grows with multiple devices, tablets, microprocessors and similar running on it we reach a point where we have many CPU’s which are often sitting dormant. Being able to leverage this spare computational power for working on other tasks in our home poses an interesting challenge.

One method we can use in the case of multiple Raspberry Pi units is to use applications that run using MPI (Message Passing Interface). The MPI provides us with a set of base routines and functionality for communicating between multiple CPU’s.

Originally written with C and Fortran in mind, there are many libraries for languages including Python and Java that allow us to implement MPI based applications.

MPI has eight basic concepts, these are:

Communicator – An object that connects groups of processes in the MPI session.

Point-to-point basics – Allows process to process communication

Collective basics – Performs communication amongst all processes in a process group

Derived datatypes – Used for dealing with datatypes in MPI applications

One-sided communication – A set of operations used for dealing with scenarios where synchronization would be an inconvenience for example the manipulation of matrices and calculating matrix products.

Collective extensions –  For example non-blocking collective operations (A combination of non-blocking point-to-point functionality with collective basics) which can help reduce the over-head on communications.

Dynamic process management –  The ability for an MPI process to help with the creation of new processes or establish communication between MPI processes.

MPI-IO – The abstraction of the I/O management on parallel systems to the MPI

These eight concepts can help us to decide what functionality we wish to use in our home automation applications that implement MPI.

To give an example of how this may be useful in the home let’s look at the following example.

Redundant media unit and thermostat controller

In this scenario we have a thermostat controller running on a Raspberry Pi that calculates various temperature data and adjusts the thermostats, blinds and similar as needed. This thermostat controller for example may also use weather data to decide whether a device that acts as a damp/water sensor should be switched on or off based upon predicted rain fall levels.

Over time as we store more historical data and get weather streams via the web we have an ever increasing amount of data to work with. More data should hopefully provide more precision. However working with more data also means we are crunching more numbers and thus placing an ever increasing burden on the CPU of the Raspberry Pi.

We can optimize our code and database in order to help tackle performance issues, however this will only get us so far.

Now let’s imagine we have a second Raspberry Pi running XMBC in our home, which we use on occasions to watch streamed TV from the web. This Raspberry Pi may be sitting idle for much of the day, so it would be great if we could leverage it’s CPU to crunch our weather data while it is sitting dormant.

This is where using MPI can help. A program written using MPI can check if the media unit is being used and if not set its CPU to work on processing temperature data.

Using the eight basic concepts of MPI we can write an application that will handle the communication between the thermostat controller and XMBC RPi and pass calculations back and forth.

This model also allows us to add further devices to our network that can be used by the thermostat controller for parallel processing.

Conclusion

Our thermostat controller is being written in Java and will run on Tomcat, therefore in the next post on MPI we will look at its Java implementation and how we can use this in our code.

We will explore the techniques used for writing distributed applications and look at a scalable model that allows for the addition of extra devices to the network.

WeMo – Switch

Introduction

In a previous blogpost I had mentioned how we were starting to see more commercial products hit the building automation space geared towards the home user.

One example of this was the WeMo product line by Belkin. Belkin has released a number of devices that can be hooked up with your mobile phone and controlled on your home network.

Currently the WeMo line consists of:

WeMo switch – a plug socket that runs over WiFi, can be programmed to switch on/off and can be manually controlled vi a mobile app

WeMo Motion – a motion sensing device that can be used to control a WeMo switch

WeMo Baby – a baby monitoring device

(Coming soon) WeMo light switch – a light switch that can also be controlled over WiFi.

WeMo switch

I was recently in the Verizon store and saw they had the WeMo switch product for sale. I picked up one of the switch devices and decided to give it a try.

The WeMo switch can be plugged into any standard plug socket and then electrical devices can be plugged in and switched on and off remotely. This is a similar concept to the fan example I gave in my book, where you can use a relay to switch a fan on and off – although in that instance a thermistor was being used to say when to toggle between on/off.

Setting it up was incredibly simple. You plug it into the wall and follow the instruction card in the box. This essentially consisted of connecting to the device directly (it is configured by default as a type of access point that allows you to connect to it for configuration), downloading the app for your phone, setting it up to run on your home WiFi network and then changing the settings as needed.

You can name each WeMo device and take a photo to assign to it as an icon, which I thought was a nice touch.

I have a small heater in one of our rooms and this device could be perfect for being able to switch it on in winter remotely before getting home from work – however you may want to consider using a VPN rather than the  “Remote Access” option in the app which allows you to control the device when not connected to your home network.  There are certain security implications with all of this I will touch on in a moment.

At $49.99 it has a fairly hefty price tag for a single plug socket. Equipping your whole house with these devices could potentially be pretty expensive, so having one of two is more likely to be the case for most users. Although as for devices hit the market I would expect to see prices fall – I wonder if Ikea will get in on the game at some point.

Security

You are probably thinking already of a ton of devices you could plugin to the the WeMo switch and I had mentioned above the idea of plugging a heater in. However I would approach this with caution.

Hack A Day published an article back in January on the potential security flaws in the WeMo switch product and how root access could be gained by hacking the switch. You can read the article here:

http://hackaday.com/2013/01/31/turning-the-belkin-wemo-into-a-deathtrap/

I’m sure Belkin will address these issues (and may have already with Firmware updates) however it is worth remembering that we live in an ever more connected world and having certain devices online that could get owned could have some nasty consequences.

If you wish to control the WeMo device from ‘off-site’ you will need to enable the remote access option (and potentially open ports on your fire wall) or setup some sort of VPN configuration for your home which will allow you to access your home network remotely. That is out of scope of this article as it deserves a whole number of posts covering the topic.

The VPN option you should consider if you want to do the above, check out OpenVPN for example. I need to do some more digging into how the remote access option works and any security implications, so check back for further updates.

The WeMo site states the following though:

Remote access is automatically enabled when you set up WeMo, as long as the network you are using has an Internet connection. With remote access enabled, you can control your WeMos from anywhere your iOS device has an Internet connection. This includes other Wi-Fi networks or your 3G/4G mobile connection. When the WeMo App is launched outside your home, the App contacts the Belkin cloud, the cloud redirects the phone’s request to the appropriate WeMo unit(s), and then you can see and control all of your WeMo devices.

Source: http://www.belkin.com/us/support-article?rnId=7358

 

Conclusion

This is a great device although a little on the pricey side. I would recommend though if you purchase using it for something like a lamp and avoid anything that has the potential to burst into flames (for example a heater!).

In later posts we will look at how this device can be controlled from your Home Dashboard software.

Winter storm Nemo

So we got slammed last night with over a couple of feet of snow. Down the road in Milford CT snow topped out at 38″.

Snow drifts thanks to the wind last night have resulted in huge snow banks, and most of the roads around here are shut with three feet of snow.

Here is a photo of the snow build up outside our front door. Using the tape measure the snow bank came in at over 40 inches.

Front door

Snow build up

Snow build up

Since we are currently snowed in and waiting for the plow trucks to clear the road, today is a great day to work on some projects. I’m going to be comparing the difference between building curtain automation devices using a stepper motor and a regular DC motor.

There is also a post in the works on using processing to design a layout of your home that can be used for displaying sensor data.

Finally a post is also in the works about the recently released book.

EEG Headsets

Just a quick post on something worth checking out.

Canadian Tech company InteraXon will be releasing their EEG powered headset called Muse next year. You can read more about the device here.

They are currently raising funds from the tech community via IndieGoGo. The process basically involves making a pledge of a certain amount of dollars up front, in return for a Muse headset after the first production run.

More details can be found on the funding section of their website here

To quote from the indieGoGo crowdfunding website:

Introducing Muse, our brainwave-sensing headband.

It’s a comfortable, sleek, four-sensor headband that allows you to control applications, games, reduce stress, improve memory and concentration, and eventually control devices directly with your mind.

Muse measures your brainwaves in real-time. It sends those brainwaves to your smart phone or tablet showing you how well your brain is performing and also translates your brainwaves into instructions to interact with content on your iOS or Android device.

 

This device obviously offers some excellent opportunities for home automation, a post will be in the works exploring some possibilities.

In the meantime check out their promo video: