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.
Upcoming SlideShare
Web Facilitated Play in the Real World
Next
Download to read offline and view in fullscreen.

29

Share

Download to read offline

Arduino and the real time web

Download to read offline

Using real time aspects of the web and Socket IO (Django SocketIO) to pull data from an Arduino or to control one.

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Arduino and the real time web

  1. 1. Arduino and the real time webLinux Conf AU – Arduino Miniconf16 January, 2012@ajfisher
  2. 2. Slides, notes & code...@ajfisherslideshare.net/andrewjfishergithub.com/ajfisher
  3. 3. Arduino ❤ Web
  4. 4. Arduino networking introductionPhoto (CC): Flickr rfranklinaz
  5. 5. Arduino networking resourcesArduino IDEExamples/Ethernet/Web Client & Web ServerArduino documentationarduino.cc/it/Reference/Ethernet
  6. 6. Sensor serving doesnt have to be plain @ajfisher @superhighfives
  7. 7. Simple web servingArduino web server examplesExamples/Ethernet/Web ServerArduServerwww.arduserver.com
  8. 8. Web interaction using an arduinoReSTduinogithub.com/jjg/RESTduinowebduinogithub.com/sirleech/Webduinoduino.jsgithub.com/ecto/duinoGeneric network pulsergist.github.com/1290670
  9. 9. Why is real time webinteraction important for an arduino?
  10. 10. World domination by arduinoPhoto (CC): Flickr marcus ramberg
  11. 11. @kevinrohling s web sockets controlled robot
  12. 12. Difficult?Photo (CC): Flickr Vrogy
  13. 13. Photo (CC): Flickr InertiaCreeps
  14. 14. Web sockets resourcesW3C web sockets specdev.w3.org/html5/websockets/Wikipediaen.wikipedia.org/wiki/WebSocketSocket.IO (JS Library)github.com/LearnBoost/socket.io-specDjango Socket.IO (Django app)github.com/stephenmcd/django-socketio
  15. 15. Real time architecture Web Sockets Server
  16. 16. Web serverfrom django_socketio import events, broadcast,broadcast_channel@events.on_subscribe(channel="channel-name")def channel_subscription(request, socket, context,channel): #do some stuff related to a subscription@events.on_message(channel="^channel-name")def message_processor(request, socket, context,message): message = message[0] foo = message["foo"] bar = message["bar"] #do some processing socket.send({"value":some_value}) socket.broadcast({"foo": foo, "value": some_value})
  17. 17. Web browser clientvar room = channel-name;var socket;$(function() { socket = new io.Socket(); socket.connect(); socket.on(connect, function() { socket.subscribe(room); }); socket.on(message, function(data) { console.log(data.value); }); socket.send({room: room, foo: foo, bar: bar});});
  18. 18. Arduino client#include <WebSocketClient.h>// defsWebSocketClient client(server, "/socket.io/websocket/",80);void setup() { Ethernet.begin(mac, ip); delay(1000); if(client.connect()) { client.setDataArrivedDelegate(dataArrived); client.subscribe("channel-name"); delay(1000); } else { while(1) {} }}void dataArrived(WebSocketClient client, String data) { Serial.println("Data Arrived: " + data);}
  19. 19. Arduino clientvoid loop() { client.monitor(); // send a message String message = "{"room":"channel-name", ""foo": bar }"; client.send(message); delay(1000);}
  20. 20. Example – real time sensor data  display Stream live temperature data from two distinct sensors on the network to a web based display that overlays the dataFull code available at https://github.com/ajfisher/realtime-temperature
  21. 21. Arduino sensorvoid loop() { char _s[8]; String message = "{"room":"tempsensor", "; message += ""sensor":"; message += sensor_id; message += ", "value":"; message += dtostrf(get_temp(0), 8, 3, _s); message += "}"; client.send(message); delay(100);}
  22. 22. Web serverfrom django_socketio import events, broadcast_channel#other views@events.on_message(channel="^tempsensor")def get_temperature(request, socket, context,message): message = message[0] value = message["value"] sensor_id = message["sensor"] socket.broadcast_channel( {"sensor": sensor_id, "value":value}, channel="tempvalues" )
  23. 23. Discussion$(function() { socket = new io.Socket(); socket.connect(); socket.on(connect, function() { socket.subscribe(tempvalues); CreateTimeline(); }); socket.on(message, function(data) { tempdata[data.sensor].append( new Date().getTime(), data.value ); });});
  24. 24. Static view of data that was presented locally live
  25. 25. Other applicationsScale out sensor networkWeb controlled installationsM2M
  26. 26. Things to try outPusherpusher.comSocket IOsocket.ioArduino Web Sockets Clientsgithub.com/krohling/ArduinoWebsocketClientgithub.com/krohling/ArduinoPusherClient
  27. 27. Arduino and the real time web@ajfisherslideshare.net/andrewjfishergithub.com/ajfisher
  • BernardoEnriqueEylen

    Sep. 16, 2017
  • DrimeyPema

    Aug. 8, 2016
  • SunilSaharan2

    Jan. 11, 2016
  • ssuser536ea6

    Dec. 30, 2015
  • DanielSimiao

    Oct. 29, 2015
  • aboutstudy

    Sep. 18, 2015
  • VishalRapte

    Aug. 28, 2015
  • joseluizcoe

    Jul. 14, 2015
  • ivanaliaga777

    May. 11, 2015
  • volpe_hd28v

    Feb. 26, 2015
  • rgaidot

    Nov. 17, 2014
  • rmcsc

    Apr. 29, 2014
  • lotssteven

    Mar. 18, 2014
  • LorenzoRomagnoli

    Mar. 12, 2014
  • mpanjakagasigasy

    Dec. 5, 2013
  • faragelfadaly

    Sep. 19, 2013
  • diaavan

    Sep. 5, 2013
  • malefsmalefski

    Feb. 26, 2013
  • yoelcm90

    Feb. 11, 2013
  • dleroy

    Feb. 10, 2013

Using real time aspects of the web and Socket IO (Django SocketIO) to pull data from an Arduino or to control one.

Views

Total views

35,174

On Slideshare

0

From embeds

0

Number of embeds

839

Actions

Downloads

381

Shares

0

Comments

0

Likes

29

×