Project Things by Mozilla

– Hello, hello Greetings, tech speakers Today we are joined for our next installment of the Mozilla Tech Briefings Today we have a special guest, Ben Francis Ben Francis is one of our Mozilla staff application engineers He’s been working with Mozilla for six, almost seven years now, if I believe Ben Francis is here to join us today to give us an update on the Mozilla Project Things It’s gone by many names over the past couple of years as it’s developed, Internet of Things, Web of Things Here at Mozilla, we’re calling it the Project Things, and Ben’ll be here to tell us all about it, the latest and greatest and how you can get involved in the project So without further ado, I’d like to yield the floor to Ben, who will be giving us our tech briefing and update today Thank you so much for joining, Ben – Hi, everyone Thank you very much for having me I work in the Emerging Technologies Department at Mozilla, and I’m working on the Web of Things, Mozilla’s implementation of the Web of Things, called Project Things Let me give you a quick overview of what I’m gonna talk about today So first of all, a bit of history about the Web of Things, how it came about and how it relates to the Internet of Things I’m gonna talk about the Web Thing API, which is Mozilla’s proposal for a Web of Things standard, and I’m going to talk about Project Things, which is Mozilla’s open source Web of Things implementation, which includes the Things Gateway, which is an open source Web of Things gateway implementation that you can build yourself, the Things Framework, which is a device framework for building the Web Things themselves, and ways that you can get involved and encourage other people to get involved Let’s start by talking about the Web of Things in general To do that, we have to start by talking about the Internet of Things There are lots of definitions of the Internet of Things Here is one of them The Internet of Things is a system of physical objects connected to the internet that can be discovered, monitored, controlled, or interacted with, so it’s about monitoring and controlling things over the internet The Internet of Things today is mainly built on vertical proprietary technology stacks, which don’t talk to each other, and when they do talk to each other, it requires per vendor integrations to make that happen There are standardization efforts, but there’s still no dominant model or standard The Internet of Things today is a lot like the internet before we had the World Wide Web, when there were competing hypertext systems that didn’t talk to each other The web eventually came along and provided a unified application layer protocol for sharing and linking information The Web of Things is about applying the lessons learned from the World Wide Web to the Internet of Things, to create a decentralized Internet of Things by giving those things URLs on the web to make them linkable and discoverable, and defining a standard data model and APIs to make them interoperable The Web of Things is not intended as another vertical IoT technology stacked to compete with existing platforms It’s meant to be a unifying horizontal layer to bridge together those underlying IoT protocols Rather than start from scratch, the Web of Things is built on existing, proven Web standards like HTTP, JSON, WebSockets, and all the best practice web standards for security, like TLS and OAuth But it’s also gonna require defining new web standards, in particular, a machine-readable description format for describing things in the real world and their capabilities, an API for communicating with those things over the Web, and possibly even a new version of HTTP that’s better suited to resource-constrained devices and IoT use cases I’m gonna give you a quick history ’cause the Web of Things is not something which Mozilla invented It dates back to at least the year 2000, when people started talking about connected objects and the web In 2002, there was a Cooltown project which used URLs and HTTP to interact with physical objects In 2007, Dominique Guinard and Vlad Trifa started the Web of Things community with their, and Dave Raggett started giving talks at the W3C and IoT events There have been peer-reviewed publications, an international workshop on the Web of Things, which has been running every year since 2010, Ph.D theses and the company Everything, which was founded by Dominique and Vlad, which is a company built on ideas from the Web of Things

In 2014, there was the first Web of Things W3C workshop, which led to the creation of the Web of Things interest group and a Siemens research group In 2016, the Web of Things interest group at the W3C proposed a charter for a Web of Things working group to work on some standards The W3C is not the only standards body looking at standards in this area The Open Connectivity Foundation have a system built on CoAP, which is like a mini HTTP for resource-constrained devices The Open Geospatial Consortium have the SensorThings API, which is quite similar and is dedicated to geospatial applications The IETF has even published some thoughts on using the REST pattern in IoT But the area we’re most focused on is the W3C Web of Things work The W3C has a community group, an interest group, and a working group Mozilla is a member of the Web of Things interest group at the W3C, where we’re working with device manufacturers, software developers, and service providers to help define those standards There’s also a W3C working group around the Web of Things, which Mozilla is not currently a member of, but they have been working on these four documents, an overview of the general architecture of the Web of Things The thing description spec defines a kind of abstract data model for describing things, and has a JSON-LD serialization using Symantec web technologies They are working on a programming language agnostic scripting API, and they have the templating system for binding the Web of Things to all sorts of different protocols Our feedback on this work so far is it’s maybe a little bit overcomplicated (audio cuts out) Bit of a simpler model It’s largely based on a previous W3C member submission from the EU-funded COMPOSE project We’ve written what’s basically a single specification that covers Web Thing description format and a Web Thing API That’s a plain JSON description format for describing things in the real world and their capabilities, and a concrete REST and WebSocket API for communicating with those things over the Web I’m going to tell you a bit about the Web Thing API now Some of these slides might not show up very well on the video stream, but we’ll make sure that the slides are sent afterwards so you can see the fine detail But this is an example of a thing description A thing can have a name, it can have a type, it can have a description, human-readable description, and you can define properties of that thing which can be modified, you can define actions that can be requested, and you can define events which can be subscribed to The thing description can also include links to other resources about that thing Here, there’s a link to a WebSocket endpoint to talk to that thing, which I’ll explain a bit more later Just jumping into those details, this is an example of a property definition This is describing a property of a thing in the real world It’s a level property of a lamp, which is a number from zero to 100 There’s a link here to a web resource which represents that property, so that the property has its own URL This is an example of an action A thing can have an action This is an example of an action for a lamp which says I want to fade the light to a particular level, so in this case I want to fade the light to a particular level with a particular duration, so the action has an input That action also has a link that you can post to to request the action Then, this is an event This is defining an overheated event which can be fired by the thing, which is saying that the lamp has exceeded its safe operating temperature The event also has a link You can also define a list of links about the thing There’s a link here to a list of properties, an action queue, and an event log There is a link to a WebSocket endpoint so that you can control the thing, and there is also a link here to an

HTML representation of the thing so it can provide its own custom web interface if it wants to Okay, so that’s the thing description, which basically describes a real thing in a machine-readable format using JSON Next, I’m gonna talk about the REST API, which REST meaning representational state transfer, which is a common way of building APIs on the web Here’s an example I mentioned before that a property has its own URL, so you can send an HTTP Get request to the property URL to get the current status of that property In this case, I’m asking for the status of an on/off property of a lamp, and I’m getting a response that says it’s not currently turned on, on is false I can also set that property using an HTTP Put request This is an example of a Put request, where I’m saying I want to change on to true I’m getting a response that echos back my request and it says, okay, I’ve turned on to true Now, because this is just standard HTTP requests, we don’t need any kind of new, special JavaScript API in the browser for web applications They can use the existing Fetch API to send those HTTP requests, or the old XML HTTP request API This is an example of a Fetch request to the on property of a lamp It’s using the Put method to set that property, and there’s also some headers here This is basically saying I’m sending you a content type of JSON I’d like you to respond with a content type of JSON There’s also an authorization header, which has got this key which identifies me and says I’m authorized to control this light That’s the security mechanism Then there’s a body of that HTTP request, which is just a bit of JSON that says turn on to true There are other things you can do with the REST API You can request an action This is an example of posting an action request to an action queue The action’s resource is like a queue, and you send a Post request to add a new action request to that queue In this case, it’s requesting a Fade action to set the level of a lamp to 50% over a period of two seconds I get a response back from the server saying your response request has been created Here is a URL that identifies that action request It’s currently got the status of pending, so the action hasn’t been executed yet You can also request (audio cuts out) (garbled audio) When a lamp is overheated Now, this is obviously not very efficient If you have to keep (audio cuts out) The REST pattern on that well-seated IoT use case There’s also a WebSocket API which has been and a WebSocket standard way of opening up basically a TCP socket with a web server so that you can send plain text messages backwards and forwards This is an example of a match to set a property Just bear with me for sec The slides are catching up This is a message to set a property over a WebSocket It’s message type set property It’s saying left motor 100 This is actually a message to send to a robot to tell it to turn its left motor to 100% In JavaScript, if you want to send this message, you need to open a WebSocket This could be JavaScript running on a webpage You open an WebSocket with a thing by its URL You specify the web thing subprotocol Then you can send a message, set property message, to that thing In this case, again, left motor 100% There are other things you can do with this WebSocket API Like the REST API, you can request an action This is an example of an action request saying I want you to go forward You can subscribe to an event You can say I want to subscribe to motion events Whenever a motion is detected,

I want to be notified Then you can receives messages back from the server With a WebSocket API, you don’t have to have that request response mechanism Messages can be pushed directly to you as the client This is an example of a property status message, which is telling me that an LED has turned on LED true You can also be notified of change in status You’ll remember earlier, I requested an action, but it was pending This is a WebSocket message to tell me that my action request has been completed This is an example of an event Earlier, I subscribed to the motion event This is an example of an event message, which has been pushed to me from the server, to tell me that motion has been detected, and it has a time stamp to say when that was detected That’s the thing description, the REST API and the WebSocket API What we found from our research so far is that there are kind of three main ways for connecting things like this to the web We call them the Web of Things integration patterns The direct integration pattern is where a device itself hosts a web server It has its own URLs and it runs the web server on the device itself An example might be a wifi camera, which you can talk to over HTTP The gateway integration pattern is for resource-constrained devices which can’t host a web server themselves They need a gateway to bridge them to the web An example might be battery-powered door sensors using a low-power wireless protocol Finally, the cloud integration pattern can be used for when you have a large number of devices over a wide geographic area which needs centrally coordinating An example might be air pollution sensors In this case, the Web Thing API is exposed from a cloud service, and the devices use some other mechanisms to communicate with that cloud service on the backend That might be an MQTT messaging service, for example That’s the API that Mozilla is proposing Project Things is Mozilla’s implementation of the Web of Things It has three main components, which correspond to those three different integration patterns that I mentioned There’s the Things Cloud, which is a collection of Mozilla-hosted IoT cloud services There’s the Things Gateway, which is an open source Web of Things gateway implementation which bridges existing smart home devices to the web And the Things Framework, which is a collection of reusable software components for building the things themselves, what we call native Web Things, which expose the Web Thing API directly I’m gonna tell you about Project Things I’m gonna talk about the Things Gateway, the Things Framework and also how you can get involved and how you can encourage others to get involved First of all, the Things Gateway The Things Gateway is designed to allow you to directly monitor and control your home over the web without a middle man Here’s some example use cases of what you might use that for Turning appliances on and off remotely over the internet, having a light turn on or an alarm sound if motion is detected, be alerted on your smartphone if smoke is detected, or check what times the kids got home by looking up based on a door sensor This is the basic architecture our of Things Gateway implementation It’s a web server, a NodeJS web server, on the backend, which exposes that Web Thing API There’s a web application as a front end that’s a progressive web app that you can access on any device and add it to your home screen Then there are adapters, which bridge various IoT protocols to that Web Thing API Those adapters can be written in different languages, like Rust or NodeJS or Python Then they communicate, they run in their own process, they communicate with the main gateway process over an IPC mechanism If one of those adapters crashes, it doesn’t bring down the whole gateway The gateway is also connected to this TLS tunneling service which we set up in the cloud, which makes it really easy to set up your gateway and connect it to the internet in a secure way Just a word about security The gateway is accessed over HTTPS via this Mozilla IoT tunneling service which I mentioned It uses software called PageKite, which sets up a tunnel from the cloud to your gateway It’s completely end-to-end encrypted From the user’s browser to the gateway

is using HTTPS, so we can’t sniff all the data that’s going through that service Every gateway gets its own unique subdomain with a certificate signed by Let’s Encrypt Or if you want to, you don’t have to use that service You can configure your own DNS, have your own domain and configure your firewall and TLS and everything yourself It also uses JSON Web Tokens to authenticate This is pretty standard way for authenticating with web services so that not just anyone can control your gateway It also supports OAuth as a way to authorize third-party apps and services that may want to talk to your gateway We released this gateway software as an OS image you can download for the Raspberry Pi and fashion onto an SD card This is initially aimed at hackers and makers who are willing to source their own hardware components, put them together and flash that software image onto an SD card You need to get ahold of a Raspberry Pi computer, a single-board computer You don’t have to use Raspberry Pi, but that’s the easiest way to do it at the moment because we have a pre-built software image for that The Raspberry Pi has wifi, Bluetooth and GPIO and other things built in, but if you want to use other smart home protocols, like Zigbee and Z-Wave, you need a USB dongle to provide that feature You put that all together, and then you download the pre-built OS image from our website, flash it onto an SD card, stick it in your gateway, and you boot it up Then the Raspberry Pi acts as a wifi hotspot that you can connect to Then go through the setup process When you first set up the gateway, this is the web interface of the gateway You create your own unique subdomain for your home You choose your subdomain You associate it with an email address so you can recover it later if you need to As I said, the subdomain gets its own certificate, that automatically generated signed by Let’s Encrypt Then you can add devices to your gateway You can scan for devices using Zigbee, Z-Wave, Bluetooth, even proprietary protocols, like Apple Home Kit and Nest Weave, using adapters There’s an add-on system so that you can add extra adapters to your gateway to support different types of devices or protocols There’s an example here of Philips Hue and TP-Link for talking to those particular devices This is the Things UI so you can monitor and control your home over the web It provides this unified web interface to all these different devices, existing off-the-shelf smart home products using lots of different protocols You can control them all through this web interface, rather than having a separate mobile app for each device You can lay those devices out on a floor plan of your home in kind of a spatial way There’s also a rules engine for setting if this-then that style rules to automate your devices For example, if one thing turns on, then turn another thing on, or if a sensor is activated, then carry out some action We also have experimental voice controls The gateway can act as a kind of smart assistant for your home These are some of the DIY gateways that people have built themselves using a Raspberry Pi People have attached screens to them, speakers, microphones and use them for all kind of things Built their own custom cases and decorated them with stickers You can build your own gateway and decorate it however you like Here are some examples of the kinds of devices which we’ve already made compatible with the gateway, so Zigbee, Z-Wave, Philips Hue, TP-Link, Ikea, smart bulbs These photos by Lars, who does some great blog posts about his experiences getting all this stuff to work together There’s a list of what devices are compatible on our wiki Finally, the Things Framework This is quite new, so it was just announced a week or two ago The Things Framework is a collection of reusable software libraries for building things themselves, what we call native Web Things, which expose the Web Thing API directly They don’t need a special gateway adapter in order to make them work The Things Framework, there are libraries in various different languages There’s a Java library so you can turn Android things into Web Things C++ examples for Arduino type hardware There are also implementations in Python, NodeJS, and coming soon is also Rust library, as well There’s a blog post on Mozilla Hacks

where you can learn more about that You can also go to on the website to see some examples I think there’s gonna be another blog post going out tomorrow with some more examples by my colleague Mike Once you’ve built a native Web Thing, you don’t need a special adapter You can just add it to the gateway by its URL Or you can scan for native Web Things which can broadcast their own URL by using MDNS on the local network, or they can even use a Bluetooth beacon to broadcast their URL You can discover the devices that way, or you can manually copy and paste the URL into this interface Just to show you some examples of things that people have built so far with the framework This is an example by my colleague James This is using the very popular ESP8266 microcontroller It’s an example of creating a dimmable light using the onboard LED You can see how that then displays itself in the gateway because it’s exposing that Web Thing description and API This is an example that’s going to be in the blog post tomorrow of a music player which Mike has created Exposes a Web Thing description and the Web of Things API, and there are gonna be examples of this in different languages, so Java, Python and NodeJS This is a particularly fun example by Lars This is a weather station which uses the rules engine to control different light bulbs There’s a kind of virtual weather station which measures the wind speed outside There’s a rule set here that says if the wind speed is greater than five, then turn the green light on It says kite time because there’s enough wind to fly my kite How can you get involved? Well, there are three main ways that we’re trying to encourage people to get involved The first way is to build your own Web Things using the Things Framework You can go to to see examples The second way is to create an adapter for the Things Gateway to bridge an existing IoT device or protocol to the web Lastly, just hacking on project things Working on Mozilla’s implementation of the Web of Things All the source codes is on GitHub We already have some great regular community contributors I’d love to see you filing issues of any bugs you find and sending Pull requests That’s about everything I have today I hope that’s given you an overview so that you can go out and tell other people about Project Things, about the idea of the Web of Things and creating a decentralized IoT You can find out more on our website at You can join us in the IoT channel on IRC You can also follow us on Twitter A really good place to ask questions if you have any problems or you want to ask about devices that are compatible and that kind of thing is on the forum on Discourse That’s the Mozilla Discourse instance Yeah, that’s everything from me I think time for questions – Awesome Well, thank you so much, Ben We really appreciated that thorough overview I believe we do have some questions in the Etherpad that have come in during your presentation I’ll start here on row 29 How many subdomain can the be used? Would this be free or will it be a freemium model going forward? – At the moment, this is completely free We have no plans of charging for it What we’re really doing is setting up a tunnel from the cloud to your gateway This is an experiment This whole project is an experiment I can’t guarantee that it’s gonna be around forever The great thing is that that tunneling service is mainly for convenience, so you can always use your own domain in the future It’s not just gonna stop working because it’s not dependent on the cloud service to function But the subdomains are free You can have as many as you’d like You get a free certificate from Let’s Encrypt, as well – Wonderful I’m sure there’s some excitement hearing that they can have as many subdomains as they’d like Next question came in from Caleon Our next question is on row 31 It reads, “What, in your opinion, “would be the best outcome of the “standardization process for Web of Things?” – That’s a great question It’s a really complicated landscape out there at the moment I mentioned a few of the standards bodies who are trying to define standards

Ideally, some of those would converge In particular, the OCF effort, which is quite far along, and the W3C effort They are already talking to each other They have regular syncs They’re also talking to the IoT schema, so, effort, as well I’d really like to see some of those converge so that we are working towards a common protocol, or at least a common data model so that those things can talk to each other Either using the same protocol or having a shared data model so that it’s easy to adapt from one to the other Then, hopefully, we’ll see some mainstream IoT platforms, like kind of the ones from Nest and Apple and Samsung and those, adopt those standards Samsung Smart Things is already a participant in that decentralization process The idea would be that we have this web standard where anyone can host their own Web Things, they can give them a URL, and any Web Thing can talk to any other Web Thing That’s what we would like to see – Absolutely So much – Thanks (garbled audio) – Our next question is on row 33 How is it possible to generate the auth key? For making the various API requests, to be specific – The JSON Web Token When it’s the web interface itself that’s talking to the API, like it uses your login, you have a username and password that you log in If you want to have a third-party app or service which talks to the gateway, you do that using OAuth In the latest .4 release, there’s a kind of easy onboarding system where you can create a local OAuth instance first, so experiment with that You can set it up such that it can hand you a token using OAuth If you want to know more about that, come and ask us in IRC ’cause my colleague James is the expert on the OAuth system and the tokens He can tell you exactly how to use the API in that way – Great, and what’s the name of that IRC channel? – It’s IoT on – So much All right, next question is on row 35 Sorry about that Our previous question came in from Vicki Thank you so much, Vicki Our next question is on row 35 How do we monitor the action endpoint? For example, I post a request to turn on the light, but how do I monitor it continuously to check if it’s working or not? – Right There are two ways to do that The first way is using the REST API You request an action using a Post request The response to that Post request gives you a URL for your action request Then you can pull that, you can get it to get its status Now, that’s obviously not the most efficient way of doing it The WebSocket API offers a push mechanism With the WebSocket API, you send an action request as a message at the WebSocket Then you get action status messages pushed back to you whenever that status changes If it’s completed, you get a message If it’s failed, you get a message You don’t have to keep calling the server – Thank you so much, and thank you (mumbles)for asking that question One more (garbled audio) For Web of Things APIs? – People are certainly working on them One of the features we’re working on, an experiment for the .5 release, is a time series database, and having a user interface for that, which provides graphs so you can graph data over time I believe my colleague James is looking at lots of different existing time series databases that you could plug into the gateway using its API, and create all kinds of dashboards and graphs and things like that – Thank you so much Is it possible to efficiently stream video through Web of Things APIs? – We think it’s possible There’s a few community members who have been experimenting with that and have actually created Web Things, camera Web Things, so webcam So far, I think the way that works is by providing a URL to the video stream in the thing description Then the web client directly fetches that video stream It can be tricky because cameras use lot of different video formats, streaming formats, container formats, encoding formats Not all of them are directly compatible with the web In a previous experiment, we had a system which transcoded video, but that can

be pretty tough with gateway hardware, which isn’t always that powerful You can provide a video stream URL directly in a thing description, or you can have a gateway which converts that video stream from one format into another format which is more compatible with the web – Great Thank you so much Our next question is on row 39, and came in anonymously via Telegram Do we have any materials available to assist if we wanna host our own IoT workshop? – Sure Let us know what you need There’s the slides I showed you today, which you’re welcome to steal and mangle and do whatever you like with My colleague Cathy does a lot of workshops all over the place She gives talks at conferences She’s got a bunch of material and example things that she’s built Another good source of examples is the Hacks blog, where we have fairly regular blog posts giving examples of how to build Web Things, how to build adapters But if there’s something you think is missing and that you need to run a workshop, then let us know You can email us, We’ll do our best to help you out – Thank you We’ll be following up with Ben to hopefully get a link to the slides That way, we can add them to our slide deck repository that we have for tech speakers if that’s all right with you, Ben I believe there’s one more question on row 43 Is unsupported software a major concern for the lifespan of smart and connected devices, in terms of products? I see we actually have a little bit of an answer here (men laugh) Would you mind speaking on that for a quick moment? – Yeah, sure It is a huge problem If you think about the lifespan of things in your home, like light switches How long have you had the light switch in your home? Probably a much longer time span than the average software app is supported for This is a big problem for IoT in general Our hope, by defining standards like the Web of Things, is that these things are gonna stick around for a lot longer Even if one particular company or cloud service disappears, your things aren’t just gonna stop working You should still be able to do those things If they can be controlled locally, if they expose a standard Web Thing API that someone else can write an interface to, it makes it much easier for those things to be useful over a longer period of time – Absolutely Well, I believe that’s all the questions we have in the Etherpad Javi, unless you have any questions come in over Telegram to you personally – I have not seen any additional questions, so I think we’re good I added some of the links that Ben was talking about into the Etherpad Tune in tomorrow, roughly eight a.m. Pacific or five, no, four p.m., four or five UTC, in your evening, at dinner tomorrow night, you can read the next episode in the Things Framework collection Very good, thanks – Absolutely Well, thank you so much, Ben, for joining us today and providing us with a thorough explanation of Web of Things We really very much looked forward to it Thank you so much – Thanks very much for having me Please do join us on IRC if you have any more questions – I will be getting us some captions for this recording At that time, I usually post the recording, the briefings up to YouTube For folks who have an easier time accessing YouTube and for you to share more widely, Ben, I’ll be sharing that URL probably early next week Thanks a lot – Thanks, Javi – Good evening – Thanks so much – Cheers – Be well, bye