Tuesday, 21 January 2014

Open Web and Open Hardware : Android Accelerometer controlled bot via WebSockets.

OK, so my Firefox OS device is with a friend of mine, and I want to control my bot with gestures. Thankfully I've got an (ageing) Android v2.3 phone.

So, what can I do?

Ok, let us analyse the situation,

  • I do not know Java. (So native development is a no-no)
  • I am a web enthusiast. (So HTML5 / JS is in).
  • I like Python because of its simplicity.
  • I'm too lazy to start from scratch. :p
Now combining all these points, I went ahead in search of suitable solutions, with the following constraints.

Constraint 1 : Use Web Sockets for transfer of sensor data.
Constraint 2 : Write as less code as possible.

Now with these points in mind, I surfed all around the net to find out about Web Sockets and their implementations in different languages, and stumbled upon this beauty : ws4py

After going through the github code of the WebSocket for Python implementation, I found another beauty that saved the day completely! They had an Android example code for ws4py!

With SL4A (Scripting Layer for Android) and Python for Android already installed on my phone, I just need to run the CherryPy Server on my machine, the example Client on my droid, and following the instructions, voila I now have the accelerometer values being streamed via websockets!
All this without writing a single line of code!

Now I just need to interface the arduino bot with the machine, and what better to achieve that than johnny-five?

After a quick round of coding, I managed to interface and move the bot as per the signals received by the WebSocket stream. Find the code here : https://gist.github.com/psbots/8545737



Alright, so, am I happy with the end result? Yes, to a certain extent. But being a web enthusiast, I want the entire stack to be JS.
Yeah that's right, I'm looking right at you Firefox OS!
Lots of features in mind!
Let the journey of Open Web and Open Hardware Begin!

Till then, watch this video of the bot in action!



1 comment:

  1. Its just a great blog on exercises I really liked it reading so many new thing here I came to know with your blog. Thanks for sharing here with us.
    openweb

    ReplyDelete