Using on{X} to control the Where Clock

Posted in Posted on 2012-12-27 16:04

Using on{X} to Control the Where Clock

I want to be able to send GET requests to the web server on my Raspberry Pi from my phone so that I can have the hand of the Where Clock turn to point at where I am or what I’m doing.

Of course, I can fire up a web browser on my phone and type in the URL of the Pi’s web server but that’s a little inconvenient: it needs to be automatic, driven by my location or other events. That’s where an interesting project from Microsoft comes in: on{X}. You go to that site and sign in with Facebook, download an app to your Android phone and again associate it with Facebook and then, on the web site, you can write little scripts using JavaScript which get sent to your phone and run there.

The API for on{X} is designed so that you can perform actions when certain events happen (hence the name of the system: on{X}) and it’s very easy to use. Here’s my first attempt to get the Where Clock to move, it fires when my phone’s screen is unlocked:

device.screen.on("unlock", function(){
    console.log('Screen unlocked');
        url: '',
        type: 'GET',
        headers: {}
    function onSuccess(body, textStatus, response) {
        var msg = device.notifications.createNotification('Clock is set: ' + textStatus);;
        console.log('Success: ' + textStatus);
    function onError(textStatus, response) {
        var msg = device.notifications.createNotification('Error: ' + textStatus);;
        console.log('Error: ' + textStatus);

The notification messages pop up in the notification bar on the phone and the console messages go to a log that can be viewed in the on{X} app or on the on{X} website. All the script does is when the screen is unlocked it calls the Raspberry Pi’s web server (using the “ajax” method) and then depending on the response it receives reports success or the error. The move command sent to the server just sends it to 180 degrees so doing it a second time appears to have no effect on the clock.

It is surely just a small step from this to something that moves the hand based on location and anything else I can think of.


Comments powered by Disqus