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.

Arduino and the real time web

32,081 views

Published on

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

Published in: Technology, Education
  • @hernanchodiaz Probably better to raise an issue on my github https://github.com/ajfisher/realtime-temperature there are definitely some changes as a result of Socket.IO and the python / Django wrappers changing on that.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • the ArduinoWebsocketClient library have changed 'update' and current android code dont work show many error, I cant suscribe channel 'tempsensor' I search for hours in internet but cant find someting than help me :(
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @xaral well really the benefit comes from having the arduino networked. If you wanted to use XBee you could do a point to point via Xbee and then use a bridge out to the Internet. Would slow up quite a bit I expect.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @andrea.reginato apologies only just saw this now. The full WS spec isn't available yet so the way I would do it is via tokenisation on the initial request. So you subscribe to a channel, pass a token (like an API key) and then the server will allow access to the channel on it or not.

    The full WS spec makes provision for this but that won't be handled by arduino for a while due to weight of the library.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • One question. It is possible to create a real time web even if we don't use a ethernet shield or wifi, and just a xbee connected to our arduino.?? This xbee will send the data wirelessly to another xbee connected to a computer.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

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

×