Well what a busy December its been work wise - very little spare time to tinker
At the end of November during a trip to Maplin I spotted some cheap battery powered Christmas lights. This brought back to mind something I'd seen Andy Stanford-Clark create a few years back - Twitter controlled Christmas light, and I couldn't resist the challenge. So I shelled out the £12 to buy 3 boxes of lights as shown below.
With the light acquired it was a simple task to wire them into my breakout board which I created in my earlier post to to drive a set of LED's via MQTT. Once connected in I tested the lights by using my GPIO-MQTT bridge java code and having ensured everything was working I set about looking at connecting my Raspberry PI to Twitter.
After a short search on the web I found the following neat demo Smartstar
. This pointed me at Node js which as things would have it I was being encouraged to look at by a number of other people I know. So with my mind set on using Nodejs I set about installing it on my Raspberry PI. I started by compiling the code on my PI but I soon came to the conclusion I would be better placed if I just upgraded to the latest version of Wheezy and installed everything via apt-get.
So to get my PI to the right state to start work I took the following step:
- Download the Wheezy image from HERE
- I then followed these instructions to load the image on to my spare SD card via my Mac
- Next I booted my Mac from the new SD card and ran the first boot configuration process (decided not to overclock at this stage )
- I then installed Nodejs and npm (node package manager) using the following command sudo apt-get install nodejs npm
- Given this was a new install I also had to put Mosquitto and Java back on to my PI. I did this as follows:
- sudo apt-get install mosquitto
- sudo apt-get install mosquitto-clients
- sudo apt-get install openjdk-6-jdk
- Download the sample Smartstart from github
I was now ready to start to tinker. The first task was to set about building my node.js code and installing the necessary packages. I used the SmartStar index.js code as the way to prime this. Once this was done I set about creating my twitter.js node.js code to handle bridging between Twitter and MQTT. Given my GPIO-MQTT bridge code provided me with an easy mechanism to manage the state of the Christmas lights via MQTT, all I needed to do in twitter.js was to read twitter messages and based on the contents publish to the relevant MQTT topic (as specified in GPIOMQTT.properties) to change the state of my lights.
With this clear in my head the flow of my code simply became:
- Subscribe to @tonycomms twitter stream
- When message arrives parse it for text strings [ 'green' , 'blue' , 'multi' ] which represent the lights I have
- For each string found, post a state change to the configured MQTT topic. So if the light is ON post OFF and vice-vers
With the code created it was just a case of firing it all up and it worked
This is still work in progress and I need to create a screen cam to show this in action but at least its a start. I'm also looking at adding verbs to control the speed e.g. [ 'faster' , 'slower' ] and may be something like [ 'flash' ] but just now I have a working config so its time to stop for the night.