Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Web Sites & Fairy Lights

Web Sites & Fairy Lights

Have you ever wondered how to connect your blog to a string of fairy lights?

I’ll talk about how we can connect web servers and browsers to physical objects around us; taking us through some technical aspects of building and communicating with IoT devices, covering some new features of the web platform that allow us to make these interactions far more intuitive. We’ll also look at some higher-level ideas of our interactions with technology and how we can relate them to the things that we design and build day-to-day.

Ben Foxall

April 27, 2017
Tweet

More Decks by Ben Foxall

Other Decks in Technology

Transcript

  1. Handling HTTP — Opening ports — Parsing request & headers

    — Responding to requests — Handling http codes & response headers — Persistent connections — IP address changes
  2. Subscribing to topics > CONNECT < CONNACK > SUBSCRIBE /fairy-lights/+

    … … < PUBLISH /fairy-lights/12 red … … < PUBLISH /fairy-lights/15 blue …
  3. 2/ Subscribe to topics MQTT-WP listen for messages then forward

    them on to the WP-REST API github/benfoxall/mq!-wp
  4. const mqtt = require('mqtt') const client = mqtt.connect(config.mqtt_host) client.subscribe('my/sensor') client.on('message',

    (topic, buffer) => { const content = escape(buffer.toString()) updatePage('my-sensor', content) })
  5. const WPAPI = require('wpapi') const wp = new WPAPI(config.wp) const

    updatePage = (slug, content) => wp.pages().slug(slug) .update({content})
  6. target outcome: When I visit a web page, I can

    choose the colour of my lights
  7. navigator.bluetooth.requestDevice({ filters: [{namePrefix: 'Puck'}], optionalServices: [0xBCDE] }) .then(device => device.gatt.connect())

    .then(server => server.getPrimaryService(0xBCDE)) .then(service => service.getCharacteristic(0xABCD)) .then(fairyLights => { fairyLights.writeValue(Uint8ClampedArray.from([255,150,0]).buffer) })
  8. { "short_name": "Lights", "name": "Fairy Lights", "icons": [ { "src":

    "icons/48.png", "type": "image/png", "sizes": "48x48" }, ... { "src": "icons/512.png", "type": "image/png", "sizes": "512x512" } ], "start_url": "https://benjaminbenben.com/lights/?homescreen", "background_color": "#333", "theme_color": "#000", "display": "fullscreen", "orientation": "portrait" }