<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Restful, Unified Access to the Internet of Things</title>
  <link rel="stylesheet" href="projection.css" />
  <link rel="alternate stylesheet" type="text/css" title="Overview" href="overview.css" />
  <meta name="generator" content="amaya 9.4, see http://www.w3.org/Amaya/" />
  <style type="text/css">
table {border-collapse: collapse;}
th {color: white; background-color: #888}

tr:nth-child(even) {background-color: #ddd}</style>
</head>

<body>

<div>
<h1>Restful, Unified Access to the Internet of Things</h1>

<p>Jack Jansen, <a href="http://www.cwi.nl/~steven/">Steven Pemberton</a> <a
href="http://www.cwi.nl/">CWI</a> <a
href="http://www.cwi.nl/~steven/amsterdam.html">Amsterdam</a></p>
</div>

<div>
<h2 id="L58">1957: The first municipal computer (Norwich, UK)</h2>

<p class="centred"><img class="centred fitheight"
alt="The First Computer in Norwich"
src="../04-25-nndevops/Delivering-the-first-Computer-in-Norwich-City-council.jpg"
/></p>

<p style="text-align:center;margin-left:auto;margin-right:auto;">Just one of 21
cabinets making up the computer.</p>
</div>

<div>
<h2 id="L64">2015: The Raspberry Pi Zero</h2>

<p class="centred"><img class="centred" alt="Raspberry Pi in Norwich"
src="../04-25-nndevops/pi-norwich.png" /></p>

<p class="centred">The first computer so cheap that they gave it away on the
cover of a magazine</p>
</div>

<div>
<h2 id="L70">How do they compare?</h2>

<p>What do you think the relationship is between the speeds of the two
computers?</p>
</div>

<div>
<h2 id="L77">How do they compare?</h2>

<p>What do you think the relationship is between the speeds of the two
computers?</p>

<p>The Raspberry Pi is about <strong>one million</strong> times faster...</p>

<p>Which means: If they had run the Elliot 24 hours a day for <strong>10
years</strong>, it would have done the amount of computing you can do on a
Raspberry Pi Zero in about <strong>5 minutes</strong>!</p>
</div>

<div>
<h2>Compare: Price</h2>

<p>Elliot: £85K (1957) (£2M-7M in <a
href="https://www.measuringworth.com/ukcompare/relativevalue.php?use%5B%5D=CPI&amp;use%5B%5D=NOMINALEARN&amp;year_early=1957&amp;pound71=85000&amp;shilling71=&amp;pence71=&amp;amount=85000&amp;year_source=1957&amp;year_result=2016">2015
money</a>)</p>

<p>Pi Zero: £4</p>

<p>Improvement: ½M-2M</p>

<p></p>

<p>Median take-home wage then:<a
href="http://hansard.millbanksystems.com/written_answers/1963/mar/21/manual-workers-average-weekly-earnings">~
£250 (men)</a>, <a
href="http://hansard.millbanksystems.com/written_answers/1963/mar/21/manual-workers-average-weekly-earnings">£125
(women)</a></p>

<p>Now: <a
href="http://www.ons.gov.uk/employmentandlabourmarket/peopleinwork/earningsandworkinghours/bulletins/annualsurveyofhoursandearnings/2015provisionalresults">~
£30000 (men), £25000 (women)</a></p>

<p>Improvement: 120-200</p>
</div>

<div>
<h2>Compare: Speed</h2>

<p>Elliot: <a
href="https://books.google.gr/books?id=Dhk9wHXfQMkC&amp;pg=PA550&amp;lpg=PA550&amp;dq=elliott+405&amp;source=bl&amp;ots=JSwJLI80X4&amp;sig=agiOYrku-JG2kkYtEtUWJGlEuxI&amp;hl=en&amp;sa=X&amp;redir_esc=y#v=onepage&amp;q=elliott%20405&amp;f=false">10.71-0.918
ms (93-1089 Hz)</a></p>

<p>Pi Zero: 1 ns (1 GHz clock)</p>

<p>Improvement: 1M</p>
</div>

<div>
<h2>Compare: Memory</h2>

<p>Elliot: <a href="http://www.vintage-icl-computers.com/icl40">1280
bytes</a></p>

<p>Pi Zero: 512 MB</p>

<p>Improvement: ½M</p>
</div>

<div>
<h2>Compare: Size</h2>

<p>Elliot: <a
href="https://books.google.gr/books?id=Dhk9wHXfQMkC&amp;pg=PA550&amp;lpg=PA550&amp;dq=elliott+405&amp;source=bl&amp;ots=JSwJLI80X4&amp;sig=agiOYrku-JG2kkYtEtUWJGlEuxI&amp;hl=en&amp;sa=X&amp;redir_esc=y#v=onepage&amp;q=elliott%20405&amp;f=false">21
cabinets x 2m x .77m x .77m</a></p>

<p>Pi Zero: <a
href="http://raspi.tv/2015/raspberry-pi-zero-free-on-the-cover-of-this-months-magpi-magazine">65
x 30 x 5.4mm</a></p>

<p>Improvement: 2.3M</p>
</div>

<div>
<h2>Compare: Weight</h2>

<p>Elliot: <a href="http://www.vintage-icl-computers.com/icl40">3-6 tons</a></p>

<p>Pi Zero: <a
href="http://raspi.tv/2015/raspberry-pi-zero-free-on-the-cover-of-this-months-magpi-magazine">9
g</a></p>

<p>Improvement: ½M</p>
</div>

<div>
<h2 id="L261">Compare</h2>

<p>So the Raspberry Pi is:</p>
<ul>
  <li>One million times faster</li>
  <li>One millionth the price</li>
</ul>

<p>A factor of a million million (billion for Europeans, trillion for
Anglo-Saxons).</p>

<p>A terabyte is a million million bytes: nowadays we talk in terms of very
large numbers.</p>

<p>Want to guess how long a million million seconds is?</p>
</div>

<div>
<h2 id="L284">A million million seconds</h2>

<p>Is 30,000 years...</p>

<p>In other words, a <em>really</em> big number...</p>
</div>

<div>
<h2>Moore's Law</h2>

<p>In fact a million million times improvement is about what you would expect
from Moore's Law over 58 years.</p>

<p><strong>Except</strong>: the Raspberry Pi is two million times
<em>smaller</em> as well, so it is <em>much</em> better than even that.</p>
</div>

<div class="longversion">
<h2>Abstract</h2>

<p>This talk shares insights from an on-going project coordinating data from
Internet of Things (IoT) devices, and using a declarative interface to that
data.</p>

<p>REST (REpresentational State Transfer) is the architectural basis of the
web. As Wikipedia points out “REST’s coordinated set of constraints,
applied to the design of components in a distributed hypermedia system, can
lead to a higher-performing and more maintainable software architecture.” So
how can you apply the same ideas to the Internet of Things?</p>

<p>The Internet of Things is driven by many tiny low-powered processors that
produce data in a variety of different formats, and produce the data in
different ways, sometimes on demand (such as thermostats), sometimes by pushing
it (such as presence detectors). Traditionally, applications have to be a mash
up of accesses to devices and formats. To use the data in a cohesive
application, the data has to be collected and integrated; this allows very low
demands to be put on the devices themselves.</p>

<p>This project places a thin REST-layer around a diverse collection of
Internet of Things devices, hiding the data-format and data-access differences,
and updating the devices automatically as needed; this then allows a REST-style
declarative interface to access and control the devices without having to worry
about the variety of device-interfaces and formats.</p>
</div>

<div>
<h2>Internet of Things</h2>

<p>Thousands of cheap, tiny devices, with "low" processing power.</p>

<p>Various data formats: text, xml, JSON, ...</p>

<p>Various access methods: on demand, push, in the cloud, ...</p>

<p>Turning the data into applications means programming; and dealing with lots
of fiddly detail.</p>
</div>

<div>
<h2>Not new, just Ubiquitous</h2>

<p>Twenty years ago a typical petrol station had embedded devices in the pumps,
the storage tanks, the tills, the vending machines, and these were centrally
accessible and controllable. </p>

<p>What is new is the ubiquity, the diversity, the flexibility, the
cheapness.</p>
</div>

<div>
<h2>The P in "IoT" stands for Privacy</h2>

<p>And the S stands for security...</p>

<p>You may have heard of the recent case of a <a
href="https://www.washingtonpost.com/news/innovations/wp/2017/07/21/how-a-fish-tank-helped-hack-a-casino/">Casino
being hacked via its fish tank</a>...</p>

<p>Or of a <a
href="https://www.wired.com/2015/07/hackers-remotely-kill-jeep-highway/">car
being hacked via its radio</a>...</p>

<p>IoT is introducing lots of problems:</p>

<p><strong>Ownership</strong>: Who owns the data?</p>

<p><strong>Privacy</strong>: Who can see the data?</p>

<p><strong>Security</strong>: Who is allowed to do anything with the data?</p>
</div>

<div>
<h2>What we are doing</h2>

<p>Creating a system that allows us to</p>
<ul>
  <li>Retain ownership of the data</li>
  <li>Control who may see and modify the data and devices</li>
  <li>Hide the data-format and data-access differences</li>
  <li>Integrate the data into homogeneous collections,</li>
  <li>Update the data and devices automatically as needed, without
  intervention.</li>
</ul>
</div>

<div>
<h2>REST</h2>

<p>REST (REpresentational State Transfer) is the architectural basis of the
web. As Wikipedia says:</p>

<blockquote>
  <p><em>“REST’s coordinated set of constraints, applied to the design of
  components in a distributed hypermedia system, can lead to a
  higher-performing and more maintainable software architecture.”</em></p>
</blockquote>

<p>In other projects we actually have proof of this claim: it can save around
an order of magnitude in time and costs.</p>

<p>Our system uses a REST-style declarative interface to access and control the
devices with no worry about the variety of device-interfaces and formats.</p>
</div>

<div>
<h2>Declarative vs Procedural</h2>
<ul>
  <li><strong>Declarative</strong> approaches describe the solution space.</li>
  <li><strong>Procedural</strong> approaches describe how to reach one
  solution.</li>
</ul>
</div>

<div>
<h2>Declarative vs Procedural</h2>
<ul>
  <li><strong>Declarative</strong> approaches describe the solution space.</li>
  <li><strong>Procedural</strong> approaches describe how to reach one
  solution.</li>
</ul>

<p><strong>Declarative</strong>: The square root of a number <em>n</em> is the
number <em>r</em> such that <em>r × r = n.</em></p>
</div>


<div>
<h2>Declarative vs Procedural</h2>
<ul>
  <li><strong>Declarative</strong> approaches describe the solution space.</li>
  <li><strong>Procedural</strong> approaches describe how to reach one
  solution.</li>
</ul>

<p><strong>Declarative</strong>: The square root of a number <em>n</em> is the
number <em>r</em> such that <em>r × r = n.</em></p>

<p><strong>Procedural</strong>: </p>
<pre>function f a:
{
   x ← a
   x' ← (a + 1) ÷ 2
   epsilon ← 1.19209290e-07
   while abs(x − x') &gt; epsilon × x: 
   {
      x ← x'
      x' ← ((a ÷ x') + x') ÷ 2
   }
   return x'
}</pre>
</div>

<div>
<h2>The Architecture</h2>
<ul>
  <li>Data repository/ies</li>
  <li>Layer that hides data format and access differences, and communicates
    with devices</li>
  <li>Constraints on, and relationships between, values</li>
  <li>Events</li>
</ul>
</div>

<div>
<h2>Architectural elements: repository</h2>

<p>Uses XML.</p>

<p>Repository is kept up-to-date with the devices bi-directionally: if the
device changes, the repository is updated to match, and if the data in the
repository is changed, the device is updated.</p>

<p>For instance: change the data value for the lights from 0 to 1, and the
lights go on.</p>
</div>

<div>
<h2>Architectural elements: communication</h2>

<p>Thin functional layer around the repository communicates with the devices.
</p>

<p>Plug-ins for devices and formats are responsible for knowing how to access
the data from the devices:</p>
<ul>
  <li>obtaining data from them</li>
  <li>converting as necessary to XML</li>
  <li>sending data back to the devices in their native format should the data
    change in the repository.</li>
</ul>

<p>One or more instances of the system can intercommunicate.</p>
</div>

<div>
<h2>Architectural elements: events</h2>

<p>Events can be listened for and reacted to within the repository. </p>

<p>The fundamental event is <em>value changed</em>, which allows event
listeners to react.</p>

<p>Other events include timers, and changes in the structure of the repository.
</p>

<p>Events travel up the data hierarchy, allowing listening at a collection
level rather than an individual value level.</p>
</div>

<div>
<h2>Architectural elements: relationships</h2>

<p>Constraints and relationships specify how values relate to each other.</p>

<p>Ensures that values that depend on each other are automatically updated (in
the process possibly changing the state of the related devices).</p>
</div>

<div>
<h2>(Necessarily simple) Examples</h2>

<p>For instance there is a single value: <code>lights</code>.</p>

<p>When that value is 1, the lights are on, and when it is 0, the lights are
off.</p>

<p>It is a two-way relationship: to turn the lights off, you just set the value
to 0; if anything changes the value to 1 they go on again.</p>

<p>There is another value: Is jack home? (This is not two-way ;-) )</p>
</div>

<div>
<h2>Lights!</h2>

<p>There are two ways to influence a value in the repository. One is equality
"=", which ensures that the equality is <em>always</em> true:</p>
<pre>lights = jack-home</pre>

<p>However this means that whenever he is home the lights are on, and whenever
he isn't home, the lights are off. Upsetting if he wants to sleep.</p>
</div>

<div>
<h2>Lights!</h2>

<p>The other method is "←". This changes the value only when the value of the
expression changes.</p>
<pre>lights ← jack-home</pre>

<p>This ensures the lights are on when he arrives home (they may have already
been on), and ensures they are off when he leaves.</p>

<p>Since this only happens at events, it allows an override. For instance a
switch on the wall also has a 0/1 value in the repository, and this can be can
be bound to the value of the lights:</p>
<pre>lights ← switch</pre>

<p>Note how switches are no longer hard-wired to their function.</p>
</div>

<div>
<h2>XPath</h2>

<p>For the purpose of this talk, we treat <code>jack-home</code> as if it were
a single standalone value.</p>

<p>In reality it is part of a structured value, such as </p>
<pre><code>home/people/person[name="Jack"]/present</code></pre>
</div>

<div>
<h2>Dark</h2>

<p>You don't want the lights to come on when it is already light, but you can
have a sensor that detects whether it is dark or not, with an affiliated value
in the store:</p>
<pre>lights ← jack-home &amp; dark</pre>

<p>This </p>
<ul>
  <li>switches the lights on if Jack comes home in the dark;</li>
  <li>switches them on if he is already home and it gets dark; </li>
  <li>ensures that the lights are off when Jack leaves (whether they were on or
    not already, and whether or not it is dark).</li>
  <li>ensures that the lights are off when it gets light.</li>
</ul>
</div>

<div>
<h2>Modularity</h2>

<p>Note that you could combine the statements into a single one using
equality:</p>
<pre>lights = (jack-home &amp; dark) or switch</pre>

<p>However, the separate statements allow a certain degree of modularity,
since, for instance, if you decide to reassign the switch to another purpose,
the other statements continue to work.</p>
</div>

<div>
<h2>How do we know if Jack is home?</h2>

<p>He carries a mobile phone, that connects to the wifi, maybe a bluetooth
watch that a sensor can see, and he has a laptop that also connects. These all
get recorded in the repository (along with other details such as IP address
assigned). So we could say </p>
<pre>jack-home = jack-phone &amp; jack-watch &amp; jack-laptop</pre>

<p>However, sometimes he switches his laptop off. How about:</p>
<pre>jack-home = jack-phone or jack-watch or jack-laptop</pre>

<p>Well, he might accidently leave his phone at home. Then we use </p>
<pre>jack-home = count(jack-phone, jack-watch,  jack-laptop) &gt; 1</pre>
</div>

<div>
<h2>Living together</h2>

<p>Jack doesn't live alone though. So there is a value that records if anyone
we know is home:</p>
<pre>someone-home = jack-home or jill-home or jim-home</pre>

<p>We can let the central heating automatically activate depending on whether
someone is home or not:</p>
<pre>heating = someone-home</pre>

<p>Of course, the required temperature of the heating is also a value in the
repository, as well as the actual temperature, so unlike the lights example, we
don't need an extra override.</p>
</div>

<div>
<h2>Distributed</h2>

<p>There is nothing you can do if there is a powercut and no backup power
supply, but you don't want to depend on the wifi to be running, or the domain
name server to be up, in order to be able to get in to your house. </p>

<p>Therefore individual devices must have as few dependencies on the general
infrastructure as possible. </p>

<p>So our system runs on the local devices as well: several copies of the
system distributed, and communicating with each other. </p>

<p>There is no requirement that a central version of the system is up and
running.</p>
</div>

<div>
<h2>Privacy</h2>

<p>None of the data is visible outside the system, unless explicitly revealed
to someone.</p>

<p>Jack can expose that he is home to someone, without revealing details such
as his phone identity.</p>
<ul>
  <li>He can reveal to the janitor of the building whether he is home</li>
  <li>Reveal whether someone is home to other inhabitants of the building
    without revealing any other details.</li>
</ul>

<p>This means the janitor can't also determine if Jack is at the bar down the
road.</p>
</div>

<div>
<h2>Advantages of State</h2>

<p>Since the architecture is primarily state-based, with events a side-effect,
in effect it is the reverse of <a href="iot.html#ifttt">IFTTT</a>-style systems
that are quite common nowadays for IoT solutions.</p>

<p>Fine-grained access control in an event-based system like IFTTT would be
more difficult, because there would basically have to be access rules for every
event/trigger.</p>

<p>State-based gives you:</p>
<ul>
  <li>hierarchical containment of XML</li>
  <li>scaffolding for the necessary security and privacy mechanisms.</li>
</ul>

<p>With this system it can be done on the basis of subtrees.</p>
</div>

<div>
<h2>Privacy mechanism</h2>

<p>Data is stored in XML elements and attributes are used for system meta-data,
part of which is information about access.</p>

<p>Exact mechanism is still being investigated.</p>

<p>Current preference is for Capabilities [<a href="iot.html#cap">CAP</a>],
where to access a part of the structure you have to be in possession of a
token.</p>
</div>

<div>
<h2>User Interface</h2>

<p>Since all actions are now controlled by changing data, all we need is a
straightforward way to access and change data.</p>

<p>Luckily we have <strong>XForms</strong>, which has more or less the same
structure as the system: a collection of (XML) data, events, and
constraints.</p>

<p>On top of that, XForms has a method of binding user interface controls to
the data for displaying and updating the data.</p>

<p>See for instance the talk <a
href="http://www.cwi.nl/~steven/Talks/2015/06-07-iot/">"XML Interfaces to the
Internet of Things"</a> (and <a
href="http://xmllondon.com/2015/xmllondon-2015-proceedings.pdf">the paper</a>
that it is based on, <a
href="http://www.cwi.nl/~steven/Talks/2015/06-07-iot/paper/">also available in
HTML</a>).</p>
</div>

<div>
<h2>Conclusion</h2>

<p>Early stages yet.</p>

<p>We have a system that insulates us from the details of the different
devices, how to drive them and the format of the data.</p>

<p>Runs on Raspberry Pi.</p>

<p>It gives us a very simple yet powerful mechanism for reading and controlling
devices.</p>

<p>We currently have systems running 24/7 at three locations.</p>

<p>You are welcome to play: <a
href="https://github.com/cwi-dis/igor">https://github.com/cwi-dis/igor</a></p>
</div>
</body>
</html>
