Switching Profiles in Kodi using an NFC Ring

Replace profiles, IP and ring ID with your own values.

Run in a Screen

node whatever.js
var fs = require('fs');
var request = require("request");
var inp = fs.createReadStream("/dev/ttyACM0");
var inptext = "";
var XBMCEventClient = require('xbmc-event-client').XBMCEventClient;
var xbmc = new XBMCEventClient('node.js app');
var blob = { "id": 1, "jsonrpc": "2.0", "method": "Profiles.LoadProfile", "params": {"profile":"lydia"}};

var options = {
  method: 'POST',
  uri: 'http://user:pass@',
  json: blob

xbmc.connect(function(errors, bytes) {
  inp.on('data', function (data) {
    if (errors.length){
      throw errors[0];

    if(data === "."){
      return; // do nothing

    if(data.indexOf("InsertRingUIDHere") !== -1){
      options.json.params.profile = "john";
      options.json.params.profile = "lydia";

    request(options, function (error, response, body) {
      console.log("changed to", options.json.params.profile);
      if (!error && response.statusCode == 200) {
        console.log(body.id) // Print the shortened url.


Note that I just threw this together as a proof of concept, it needs a bunch of polish! 🙂

A modern forum for a modern web

Screenshot from 2014-04-16 17:56:11

We recently migrated our NFC Ring forum over from ProPHPBB (Hosted PHPBB) to NodeBB. Let’s be clear, in this blog post I’m not comparing like for like. ProPHPBB is a free service, it is open source, built on PHP and it’s been the cornerstone of forums on the web for years. NodeBB is the young kid on the block.

Let’s get this out of the way, we paid the NodeBB team 300$ for our migration from PHPBB. Hosting and support is costing us ~70$ per month. With the support we’re getting we feel it’s value for money, we didn’t pay anything for the service from ProPHPBB, it was ad supported.

The guys at ProPHPBB were also great, we’d usually get our SQL export within 12 hours of asking. Obviously if we were paying them a monthly fee we’d expect a quicker response or even the ability to dump our own SQL but so is life.

The ads on the ProPHPBB forum hosting were just far too offensive and damaged our brand. It’s kinda obvious that PHPBB’s days really are numbered, the design and implementation is just too dated now for it to ever really become relevant again, I gotta thank it for it’s service though, truly great software has a shelf life like any other product and we should celebrate the circle of life. Thank you team PHPBB and the community around that project!

NodeBB presents some other significant advantages than providing value for money:

  • We can map our sub-domain
  • We can use our SSL certs
  • We can use our new Oauth2 Identity provider to provide a single unified sign on.
  • It has a great chat feature and notification system.
  • Posts can be up/downvoted and favorited
  • It is Beautiful, the UI is perfect for our Brand.
  • Responsive CSS provides a nice mobile experience

Migration wasn’t completely smooth, this wasn’t a huge surprise because we have all been crazy busy but what mattered is that pretty much any time I hit a problem I could jump onto IRC and Julian would sort it out within a few hours.
I have no regrets about using ProPHPBB initially as it gave us a very quick start with forums. Ultimately though, I’m happy with our new home and it’s onwards and upwards for the NFC Ring Forum!

Publishing to Npm on Git commit using Github Hooks and Travis

Travis-CI can auto “npm publish” your git repo to npmjs, this means that whenever you commit to your github repository your software is always updated and available to users via npm update. This should also work with pull requests so no need to jump onto CLI After a merge, just hit merge and after a few minutes / hours you should see your application updated on npmjs.

Step 1.

Create Travis-CI account, ideally signing in with your github account.

Step 2.

Find the repository you want to auto publish on the Travis Web interface (under your profile) and click Enable.

Step 3.

Install Ruby Gems

sudo apt-get install rubygems

Step 4.

Install travis CLI gem and json gem

sudo gem install json
gem install travis

Step 5.

Create a .travis.yml file in the root of your repository that looks like this (replacing your email)

language: node_js
  email: your@emailhere.com
  provider: npm

Step 6.

Get your npmjs api key and copy it into the clip board (Copy the bit after the _auth =)

cat ~/.npmrc | grep _auth

Step 7.

Run the Travis CI secret key generator

travis encrypt --add deploy.api_key

When prompted paste your APIKey then hit Control D, don’t add an additional line break or enter.

Step 8.

Add, Commit and Push the new .travis.yml file, this will trigger a build on Travis

git add .travis.yml && git commit -m "Travis auto publish config" && git push

Step 9.

Head over to your Travis page and wait for your build to begin, if it doesn’t it’s likely you didn’t push correctly up to github.

Doing lots of packages?

You will only need to complete steps 5 to 9 on future packages (assuming you enabled them on travis)

Monitoring a Wind Turbine with a Raspberry Pi


As a weekend project I wanted to receive an email if my wind turbine wasn’t generating power when it should. I didn’t want to spend loads of money on fancy new equipment so I hacked it together mostly with equipment I had lying about.


– Wind Turbine or Solar Panel (obviously)
– Bridge rectifier (converts the AC from the turbine to DC)
– Some sort of voltage regulator (10-24v –> 12v) (or to 5v and skip below)
– Car cigarette lighter mobile phone charger (£5)
– Raspberry Pi (£35)
– Delta Sigma ADC (£25)
– USB Cable (£1)
– 1 Hour free
– Met Office API Key (free — UK Only)


– Wire up the turbine and bridge rectifier
– Pop the bridge rectifier into the voltage regulator
– Put the regulated voltage through the car voltage adapter, this will give you 5v out
– Wire the 5v from the turbine into channel 0 on the Delta Sigma
– Pop the ADC into the Pi, follow this guide for setting up the software.

How it works

– The Pi asks the Met Office what the current wind speed is.
– If the wind speed is above a threshold then the Pi checks the turbine
– If the turbine isn’t generating 5v then email me.

Next Steps

– Use Machine Learning to find a better balance on announcements
– Rate limit announcements.
– Measure integer of turbine output instead of boolean state.
– Wire the Owl energy monitor up to the AC output of the grid tie inverter.
– Store value of state in something like Graphite or using Nagios for announcements

How long did it take to connect to socket io?

Send the duration(in ms) a client waited to connect to a Socket IO instance off to Google Analytics . I use this on PrimaryWall to make sure it’s not taking schools a long time to connect to walls. If I start to see this number getting bigger I know something is going wrong so I have an alert set if the average gets above 1000ms.

This code sends the ms it took from when the document was ready to when the socket was ready.

$(document).ready(function ()
  var socketConnectDuration = 0;
  setInterval ( socketConnectDurationIncrease, 100 );  // Start a timer
  socket.on('connect', function ()
    _gaq.push(['_trackEvent', 'Connection duration', 'Connection duration', socketConnectDuration]); // Send the length of time to GA

function socketConnectDurationIncrease(){
  socketConnectDuration = socketConnectDuration + 100;