Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Using websockets and android to control robots in realtime


Published on

Talk about using WebSockets in Android to control robots in real-time. More details at

Published in: Technology

Using websockets and android to control robots in realtime

  1. 1. Using WebSockets and Android to control robots in real-time Sudar Muthu (@sudarmuthu)
  2. 2. Who am I? Research Engineer by profession Create robots as hobby Uses an Android phone Why not combine both of them? Has spoken in 6+ hasgeek events 
  3. 3. Android and Arduino There are at least half dozen ways to do it and I am not going to talk about each of them. arduino-and-android-at-droidcon
  4. 4. So today… WebSockets in Android How to use it to control robots
  5. 5. Why hardware for a software hacker? Fun!
  6. 6. Let’s start with a demo Demo
  7. 7. Participate in the demo  Visit
  8. 8. Control the bot at stage #asimijs @hardwarefun
  9. 9. Now let’s see how I built it
  10. 10. What is WebSockets? Full-duplex over a single TCP connection Provides push support Designed to work inside browsers Works on port 80
  11. 11. WebSockets vs HTTP
  12. 12.
  13. 13. HTTP (Pull) Is there an update? No Is there an update? No Is there an update? Yes
  14. 14. WebSockets (Push) Tell me when you have an update Ok Here is the update
  15. 15. Why use WebSockets in Android Firewall friendly No need to reinvent protocol Real-time communication Easy to setup server
  16. 16. Remember, I am not talking about using WebSockets inside an Android browser
  17. 17. WebSocket implementation for Android There are lot of options, but I choose Socket.IO implementation by Kaushik Dutta (Rom Manager fame)
  18. 18. Why Socket.IO? You should have attended jsFoo ;)
  19. 19. Why Socket.IO Additional features on top of WebSockets Node.js based server Has support for maximum no: of browsers Has clients in lot of languages
  20. 20. and …. I had the server already written 
  21. 21. Let’s see some code
  22. 22. In Android, create a socket client = new SocketIOClient(URI.create( ”"),new SocketIOClient.Handler() { @Override public void onConnect() { Log.d(TAG, "Connected!"); } @Override public void on(String event, JSONArray arguments) { Log.d(TAG, "Got event); } @Override public void onDisconnect(int code, String reason) { Log.d(TAG, "Disconnected!); } });
  23. 23. Send data through socket client.connect(); JSONArray arguments = new JSONArray(); arguments.put("first argument"); JSONObject second = new JSONObject(); second.put("dictionary", true); arguments.put(second) client.emit("hello", arguments); client.disconnect();
  24. 24. In node.js side var io = require(; io.sockets.on(connection, function (socket) { socket.emit(news, { hello: world }); socket.on(’my other event, function (data) { console.log(data); }); });
  25. 25. Checkout the full source code at
  26. 26. So… How the demo worked?
  27. 27. Node.js Server Android Client Admin page Web Socket User page Asimi (Bot) User page ADK User page
  28. 28. Links AsimiJS – The demo that I showed initially Android websockets - websockets Getting started with hardware programming programming Getting started with Arduino and-avr Android and Arduino - robots-using-arduino-and-android-at-droidcon Arduino Workshop -
  29. 29. Thank you Sudar Muthuhttp://hardwarefun.com