SlideShare ist ein Scribd-Unternehmen logo
1 von 29
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

Weitere ähnliche Inhalte

Mehr von 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 MeetupSudar Muthu
 
WordPress Developer tools
WordPress Developer toolsWordPress Developer tools
WordPress Developer toolsSudar Muthu
 
WordPress Developer Tools to increase productivity
WordPress Developer Tools to increase productivityWordPress Developer Tools to increase productivity
WordPress Developer Tools to increase productivitySudar Muthu
 
Unit testing for WordPress
Unit testing for WordPressUnit testing for WordPress
Unit testing for WordPressSudar Muthu
 
Unit testing in php
Unit testing in phpUnit testing in php
Unit testing in phpSudar Muthu
 
How arduino helped me in life
How arduino helped me in lifeHow arduino helped me in life
How arduino helped me in lifeSudar Muthu
 
Having fun with hardware
Having fun with hardwareHaving fun with hardware
Having fun with hardwareSudar Muthu
 
Getting started with arduino workshop
Getting started with arduino workshopGetting started with arduino workshop
Getting started with arduino workshopSudar Muthu
 
Python in raspberry pi
Python in raspberry piPython in raspberry pi
Python in raspberry piSudar Muthu
 
Hack 101 at IIT Kanpur
Hack 101 at IIT KanpurHack 101 at IIT Kanpur
Hack 101 at IIT KanpurSudar Muthu
 
PureCSS open hack 2013
PureCSS open hack 2013PureCSS open hack 2013
PureCSS open hack 2013Sudar Muthu
 
Arduino Robotics workshop day2
Arduino Robotics workshop day2Arduino Robotics workshop day2
Arduino Robotics workshop day2Sudar Muthu
 
Arduino Robotics workshop Day1
Arduino Robotics workshop Day1Arduino Robotics workshop Day1
Arduino Robotics workshop Day1Sudar Muthu
 
Lets make robots
Lets make robotsLets make robots
Lets make robotsSudar 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 APISudar Muthu
 
Capabilities of Arduino
Capabilities of ArduinoCapabilities of Arduino
Capabilities of ArduinoSudar Muthu
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDDSudar Muthu
 

Mehr von 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
 

Kürzlich hochgeladen

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Kürzlich hochgeladen (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

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