SlideShare a Scribd company logo
Using WebSockets and Android
 to control robots in real-time
        Sudar Muthu (@sudarmuthu)
          http://hardwarefun.com
          http://github.com/sudar
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 




http://hardwarefun.com
Android and Arduino


          There are at least half dozen ways to do it and I am not
                     going to talk about each of them.




         http://sudarmuthu.com/blog/building-robots-using-
         arduino-and-android-at-droidcon


http://hardwarefun.com
So today…


            WebSockets in Android
         How to use it to control robots



http://hardwarefun.com
Why hardware for a software hacker?




                         Fun!

http://hardwarefun.com
Let’s start with a demo



                                Demo
                         http://hardwarefun.com/projects/asimijs




http://hardwarefun.com
Participate in the demo 


                               Visit
                         http://hardwarefun.com:3000




http://hardwarefun.com
Control the bot at stage
                           http://hardwarefun.com/projects/asimijs




              #asimijs @hardwarefun
http://hardwarefun.com
Now let’s see how I built it




http://hardwarefun.com
What is WebSockets?


             Full-duplex over a single TCP connection
             Provides push support
             Designed to work inside browsers
             Works on port 80




http://hardwarefun.com
WebSockets vs HTTP




http://hardwarefun.com
http://hardwarefun.com
HTTP (Pull)


                         Is there an update?



                                               No


                         Is there an update?


                                                No

                         Is there an update?

                                               Yes


http://hardwarefun.com
WebSockets (Push)


                          Tell me when you have an update



                                               Ok




                          Here is the update




http://hardwarefun.com
Why use WebSockets in Android


             Firewall friendly
             No need to reinvent protocol
             Real-time communication
             Easy to setup server




http://hardwarefun.com
Remember, I am not talking about
          using WebSockets inside an
               Android browser



http://hardwarefun.com
WebSocket implementation for
                       Android


              There are lot of options, but I choose Socket.IO
          implementation by Kaushik Dutta (Rom Manager fame)



                  https://github.com/koush/android-websockets




http://hardwarefun.com
Why Socket.IO?


       You should have attended jsFoo
                     ;)



http://hardwarefun.com
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




http://hardwarefun.com
and ….


        I had the server already written
                       



http://hardwarefun.com
Let’s see some code




http://hardwarefun.com
In Android, create a socket
    client = new SocketIOClient(URI.create(
   ”http://hardwarefun.com:3000"),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!);
         }
   });
http://hardwarefun.com
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();
http://hardwarefun.com
In node.js side


         var io = require('socket.io').listen(80);

         io.sockets.on('connection', function (socket) {
           socket.emit('news', { hello: 'world' });
           socket.on(’my other event', function (data) {
             console.log(data);
           });
         });




http://hardwarefun.com
Checkout the full source code
                        at
                         http://hardwarefun.com/projects/asimijs




http://hardwarefun.com
So…


                     How the demo worked?




http://hardwarefun.com
Node.js Server




                                              Android Client

                Admin page



                Web Socket     User page          Asimi (Bot)
                                User page
                 ADK             User page



http://hardwarefun.com
Links

             AsimiJS – The demo that I showed initially
             http://hardwarefun.com/projects/asimijs
             Android websockets - https://github.com/koush/android-
             websockets
             Getting started with hardware programming
             http://hardwarefun.com/tutorials/getting-started-with-hardware-
             programming
             Getting started with Arduino
             http://hardwarefun.com/tutorials/getting-started-with-arduino-
             and-avr
             Android and Arduino - http://sudarmuthu.com/blog/building-
             robots-using-arduino-and-android-at-droidcon
             Arduino Workshop - http://hardwarefun.com/arduino-workshop
http://hardwarefun.com
Thank you
      Sudar Muthu
http://hardwarefun.com
http://github.com/sudar

More Related Content

More from Sudar Muthu

A quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress MeetupA quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress Meetup
Sudar Muthu
 
WordPress Developer tools
WordPress Developer toolsWordPress Developer tools
WordPress Developer tools
Sudar Muthu
 
WordPress Developer Tools to increase productivity
WordPress Developer Tools to increase productivityWordPress Developer Tools to increase productivity
WordPress Developer Tools to increase productivity
Sudar Muthu
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPress
Sudar Muthu
 
Unit testing in php
Unit testing in phpUnit testing in php
Unit testing in php
Sudar Muthu
 
How arduino helped me in life
How arduino helped me in lifeHow arduino helped me in life
How arduino helped me in life
Sudar Muthu
 
Having fun with hardware
Having fun with hardwareHaving fun with hardware
Having fun with hardware
Sudar Muthu
 
Getting started with arduino workshop
Getting started with arduino workshopGetting started with arduino workshop
Getting started with arduino workshop
Sudar Muthu
 
Python in raspberry pi
Python in raspberry piPython in raspberry pi
Python in raspberry pi
Sudar Muthu
 
Hack 101 at IIT Kanpur
Hack 101 at IIT KanpurHack 101 at IIT Kanpur
Hack 101 at IIT Kanpur
Sudar Muthu
 
PureCSS open hack 2013
PureCSS open hack 2013PureCSS open hack 2013
PureCSS open hack 2013
Sudar Muthu
 
Pig workshop
Pig workshopPig workshop
Pig workshop
Sudar Muthu
 
Arduino Robotics workshop day2
Arduino Robotics workshop day2Arduino Robotics workshop day2
Arduino Robotics workshop day2
Sudar Muthu
 
Arduino Robotics workshop Day1
Arduino Robotics workshop Day1Arduino Robotics workshop Day1
Arduino Robotics workshop Day1
Sudar Muthu
 
Lets make robots
Lets make robotsLets make robots
Lets make robots
Sudar Muthu
 
Capabilities of Arduino (including Due)
Capabilities of Arduino (including Due)Capabilities of Arduino (including Due)
Capabilities of Arduino (including Due)
Sudar Muthu
 
Picture perfect hacks with flickr API
Picture perfect hacks with flickr APIPicture perfect hacks with flickr API
Picture perfect hacks with flickr API
Sudar Muthu
 
Hacking 101
Hacking 101Hacking 101
Hacking 101
Sudar Muthu
 
Capabilities of Arduino
Capabilities of ArduinoCapabilities of Arduino
Capabilities of Arduino
Sudar Muthu
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
Sudar Muthu
 

More from Sudar Muthu (20)

A quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress MeetupA quick preview of WP CLI - Chennai WordPress Meetup
A quick preview of WP CLI - Chennai WordPress Meetup
 
WordPress Developer tools
WordPress Developer toolsWordPress Developer tools
WordPress Developer tools
 
WordPress Developer Tools to increase productivity
WordPress Developer Tools to increase productivityWordPress Developer Tools to increase productivity
WordPress Developer Tools to increase productivity
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPress
 
Unit testing in php
Unit testing in phpUnit testing in php
Unit testing in php
 
How arduino helped me in life
How arduino helped me in lifeHow arduino helped me in life
How arduino helped me in life
 
Having fun with hardware
Having fun with hardwareHaving fun with hardware
Having fun with hardware
 
Getting started with arduino workshop
Getting started with arduino workshopGetting started with arduino workshop
Getting started with arduino workshop
 
Python in raspberry pi
Python in raspberry piPython in raspberry pi
Python in raspberry pi
 
Hack 101 at IIT Kanpur
Hack 101 at IIT KanpurHack 101 at IIT Kanpur
Hack 101 at IIT Kanpur
 
PureCSS open hack 2013
PureCSS open hack 2013PureCSS open hack 2013
PureCSS open hack 2013
 
Pig workshop
Pig workshopPig workshop
Pig workshop
 
Arduino Robotics workshop day2
Arduino Robotics workshop day2Arduino Robotics workshop day2
Arduino Robotics workshop day2
 
Arduino Robotics workshop Day1
Arduino Robotics workshop Day1Arduino Robotics workshop Day1
Arduino Robotics workshop Day1
 
Lets make robots
Lets make robotsLets make robots
Lets make robots
 
Capabilities of Arduino (including Due)
Capabilities of Arduino (including Due)Capabilities of Arduino (including Due)
Capabilities of Arduino (including Due)
 
Picture perfect hacks with flickr API
Picture perfect hacks with flickr APIPicture perfect hacks with flickr API
Picture perfect hacks with flickr API
 
Hacking 101
Hacking 101Hacking 101
Hacking 101
 
Capabilities of Arduino
Capabilities of ArduinoCapabilities of Arduino
Capabilities of Arduino
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 

Recently uploaded

Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 

Recently uploaded (20)

Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 

Using websockets and android to control robots in realtime

  • 1. Using WebSockets and Android to control robots in real-time Sudar Muthu (@sudarmuthu) http://hardwarefun.com http://github.com/sudar
  • 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  http://hardwarefun.com
  • 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. http://sudarmuthu.com/blog/building-robots-using- arduino-and-android-at-droidcon http://hardwarefun.com
  • 4. So today… WebSockets in Android How to use it to control robots http://hardwarefun.com
  • 5. Why hardware for a software hacker? Fun! http://hardwarefun.com
  • 6. Let’s start with a demo Demo http://hardwarefun.com/projects/asimijs http://hardwarefun.com
  • 7. Participate in the demo  Visit http://hardwarefun.com:3000 http://hardwarefun.com
  • 8. Control the bot at stage http://hardwarefun.com/projects/asimijs #asimijs @hardwarefun http://hardwarefun.com
  • 9. Now let’s see how I built it http://hardwarefun.com
  • 10. What is WebSockets? Full-duplex over a single TCP connection Provides push support Designed to work inside browsers Works on port 80 http://hardwarefun.com
  • 13. HTTP (Pull) Is there an update? No Is there an update? No Is there an update? Yes http://hardwarefun.com
  • 14. WebSockets (Push) Tell me when you have an update Ok Here is the update http://hardwarefun.com
  • 15. Why use WebSockets in Android Firewall friendly No need to reinvent protocol Real-time communication Easy to setup server http://hardwarefun.com
  • 16. Remember, I am not talking about using WebSockets inside an Android browser http://hardwarefun.com
  • 17. WebSocket implementation for Android There are lot of options, but I choose Socket.IO implementation by Kaushik Dutta (Rom Manager fame) https://github.com/koush/android-websockets http://hardwarefun.com
  • 18. Why Socket.IO? You should have attended jsFoo ;) http://hardwarefun.com
  • 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 http://hardwarefun.com
  • 20. and …. I had the server already written  http://hardwarefun.com
  • 21. Let’s see some code http://hardwarefun.com
  • 22. In Android, create a socket client = new SocketIOClient(URI.create( ”http://hardwarefun.com:3000"),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!); } }); http://hardwarefun.com
  • 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(); http://hardwarefun.com
  • 24. In node.js side var io = require('socket.io').listen(80); io.sockets.on('connection', function (socket) { socket.emit('news', { hello: 'world' }); socket.on(’my other event', function (data) { console.log(data); }); }); http://hardwarefun.com
  • 25. Checkout the full source code at http://hardwarefun.com/projects/asimijs http://hardwarefun.com
  • 26. So… How the demo worked? http://hardwarefun.com
  • 27. Node.js Server Android Client Admin page Web Socket User page Asimi (Bot) User page ADK User page http://hardwarefun.com
  • 28. Links AsimiJS – The demo that I showed initially http://hardwarefun.com/projects/asimijs Android websockets - https://github.com/koush/android- websockets Getting started with hardware programming http://hardwarefun.com/tutorials/getting-started-with-hardware- programming Getting started with Arduino http://hardwarefun.com/tutorials/getting-started-with-arduino- and-avr Android and Arduino - http://sudarmuthu.com/blog/building- robots-using-arduino-and-android-at-droidcon Arduino Workshop - http://hardwarefun.com/arduino-workshop http://hardwarefun.com
  • 29. Thank you Sudar Muthu http://hardwarefun.com http://github.com/sudar