Sunday, 3 June 2012

How can a Pi control a house from 50 miles away?

Easy!  Here's my Pi recipe:

My Ingredients:
1 Raspberry Pi
1 IBM J9 JVM
1 WebSphere Liberty Profile server
1 Really Small Message Broker (RSMB)
1 Eclipse Paho client library
1 Andy Stanford-Clark!

Architecture:

Andy has a very pervasive house with many devices set up to both tweet and publish messages based on events which occur to those devices.  Furthermore, some devices can be controlled by sending messages to topics which they are monitoring, such as a pond fountain, an outdoor light and even a heated towel rail!  The messaging design used was to bridge from the RSMB on the Pi to the existing message broker Andy has set up to monitor and controll his devices.  Any messages sent from or received by either broker will be mirrored by the other via the bridge.  This makes the remaining design on the Pi beyond the RSMB easy, as we can consider everything is local, to the RSMB. Neat!  The visual and interactive side will be taken care of by a web application on the Liberty Profile app server, which connects to the RSMB via an eclipse open source MQTT client project called Paho.

My Method:

I already had a Debian install with both the OpenJDK and IBM J9 JVM installed with my Liberty Profile application server, which I used to run the snoop servlet that I wrote about in a previous post, and also for a cool dynamic development demo for the new Liberty Profile I ran at the IBM Impact conference in May 2012.  My first step was to install, configure and run the RSMB.  It doesn't currently run on the ARM architecture, so I needed to build the source on the Pi and it then just worked out the box, easy.  Next I needed to create a broker.cfg file which had info to pointed to Andy's existing broker, such as IP address and port number, and also describe which topics I wanted to bridge.  This is simply a list of topics with my intended actions, such as 'in' to listen.  That's all I needed to do with the RSMB.

My web application itself is a jsp and servlet based webapp which automatically refreshes itself every 5 seconds to keep the dashboard up to date.  It bundles the Paho client library which it uses to connect to the RSMB and subscribe to a number of topics which passes messages of interest to the dashboard.  The webapp stores info it requires locally in memory for history graphs such as energy consumption.  This data is sent to the Google chart facility (why on earth are Google deprecating this cool graphing function?  Maybe someone can fill me in via comments). The application server config just has the one feature included, the jsp-2.2 feature, as that's all we need in this environment!  This keeps the application server runtime nimble and fast with a low memory footprint.

Results:



So what's next?

I've got a couple of things I want to play with next, I quite fancy connecting the Pi up to my current cost meter at home and to my TV as well and display a channel which shows my energy usage.  If you have any ideas of what you'd like to see, let me know :o)

For more info check out:

WebSphere Liberty Profile http://wasdev.net
Raspberry Pi - http://raspberrypi.org
Eclipse Paho - http://git.eclipse.org/c/paho/org.eclipse.paho.mqtt.java.git/
RSMB -  https://www.ibm.com/developerworks/mydeveloperworks/groups/service/html/communityview?communityUuid=d5bedadd-e46f-4c97-af89-22d65ffee070
MQTT - http://mqtt.org

16 comments:

  1. Exciting stuff. Thanks for sharing!

    Also, wanted to let you know that the link from the wasdev.net article is giving a 404 error.

    -james.

    ReplyDelete
  2. Does the ARM-compiled RSMB "just work" on the Raspberry Pi?

    As I mentioned on the YouTube video, you could do some audio cleanup on this and maybe use Screenflow to smooth out the transitions. A drop-in-diagram showing the setup might be useful, too. Either way, very cool demo - nice work!

    ReplyDelete
  3. Very interesting. Could you explain how you control a fountain and light? I'm interested in electrical aspect.

    ReplyDelete
  4. Rick Morrell7 June 2012 14:01

    Well I think he's using X10 from the command messages being displayed in the log file. It's an interesting technology which I'd installed in my bachelor pad back in 2004.. (being married now my wife wasn't quite as convinced about the expense when we got our current house re-wired. :-) ). You can find more about the devices from the Lets Automate web page (http://www.letsautomate.com/index.cfm?&Nav=X10). I'm going to use this technology for controlling the immersion heaters in my thermal store when my solar panels are generating enough energy.

    What I would be interested in knowing is how you got the current status of the X10 switch.. most of the X10 switches I have seen only allow you to set the status but not to read it. Therefore if someone manually turns on the towel rail (say using a momentary switch) then how does the RSMB receive a message about the updated state?

    ReplyDelete
    Replies
    1. This is the killer for me - how do you get feedback on a switch state ? Please tweet me if you find an answer ! @ilium007

      Delete
  5. Hi Simon,

    That's really good work - I found X10 unreliable so have switched to Zwave for monitoring and control (using Homeseer) I'm keen to know how you integrated your oil tank level (As I ran out of oil the other day and swmbo wasn't a happy teddy!) Thanks, Greg

    @ dominiquewarthel - have a google for X10 or Zwave !

    ReplyDelete
  6. I really like the ability to use MQTT to pass control messages between the Pi (and arduinos) to a home server and the 'net (cosm sounds good also). It would be helpful for the Pi community to have a more packaged capability to implement such functionality rather than a steep curve with each piece. Focus on development and not the umpteen packages. I look forward to your work.

    ReplyDelete
  7. I'm interested to use RSMB with Raspberrypi. I could'nt find the sources in order to recompile on RP. Can you tell me where can I find it or how to let it work on RP?

    ReplyDelete
  8. Julian Bridges8 June 2012 13:11

    Have Raspberry Pi connected to my CurrentCost meter using the Python scripts I found online (I think on Dale Lane's blog). Happy to discuss... note also work for IBM but not in Hursley.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. ... where's the edit button. Sorry, meant to say: Thanks Simon for the great demo! I see it's now featured on Raspberry Pi's Twitter feed as well. Any chance of putting the RSMB binary image for the Raspberry Pi's ARM architecture on the DeveloperWorks site? Non-IBMers can't get source for RSMB.

    ReplyDelete
  12. If you're interested in doing this yourself but don't work for IBM, you can use mosquitto ( http://mosquitto.org/ ) as a drop in replacement for RSMB. It's open source and has already tested on the Raspberry Pi. There are instructions on compiling (nothing more than compiling as normal) on the mqtt wiki: http://mqtt.org/wiki/doku.php/mosquitto_message_broker

    ReplyDelete
  13. One of these days a Pi-based system will blow high-end, commercial systems like Crestron out of the water.

    ReplyDelete
  14. will there be a noobs and manual for this one day ? i like to make a simple system to control some relays but i like the fact that this gives a control message .
    all systems i have seen sofar do not do that .
    unfortunately i do not understand the programming discussion and being nearly 60 i doubt i will ever understand this

    ReplyDelete