<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <title>Temporal Anomaly</title>
    <link>http://www.temporalanomaly.com/blog</link>
    <description>Automating our house and other random stuff</description>
    <pubDate>Sun, 08 Jan 2012 15:58:29 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Home Automation Protocols: MQTT</title>
      <link>http://www.temporalanomaly.com/blog/2011/05/02/home-automation-protocols:-mqtt</link>
      <pubDate>Mon, 02 May 2011 20:52:23 BST</pubDate>
      <category><![CDATA[home automation]]></category>
      <category><![CDATA[mqtt]]></category>
      <category><![CDATA[protocols]]></category>
      <guid isPermaLink="true">http://www.temporalanomaly.com/blog/2011/05/02/home-automation-protocols:-mqtt</guid>
      <description>Home Automation Protocols: MQTT</description>
      <content:encoded><![CDATA[<p>In my previous post, I mentioned some of the issues I was experiencing
with my current choice of home automation protocol, <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document">xPL</a>.</p>
<p>The primary issue was the need to perform filtering for every message
on every client due to the use of broadcasts for messaging.  One way
to avoid this is to use a pub/sub messaging system instead.  A number
of people that I respect have been using the <a href="http://mqtt.org/">MQTT Protocol</a> so
I thought I'd take a better look at it.</p>
<p>I figured a good way to understand it would be to implement it.  I've
implemented several protocols from scratch without any documentation
so implementing MQTT from a well-written specification was simple
process.  The basic implementation took less than a week and resulted
in <a href="http://github.com/beanz/net-mqtt-perl">Net::MQTT</a> and <a href="http://github.com/beanz/anyevent-mqtt-perl">AnyEvent::MQTT</a> on CPAN.</p>
<p>The protocol is lightweight and flexible.  This is great.  It works
well in contexts where you are both publisher and subscriber because
you can design the simplest, minimal messaging format between
agents.</p>
<p>However, building communities that can write components that can
interoperate will require some more structure.  For example, using
<a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document">xPL</a>, I have a client that monitors messages using the
"<a href="http://xplproject.org.uk/wiki/index.php?title=Schema_-_SENSOR.BASIC">sensor.basic</a>" schema and creates/updates
<a href="http://www.mrtg.org/rrdtool/">round robin database</a> files for each sensor reading.  This works
for all xPL clients that support the "<a href="http://xplproject.org.uk/wiki/index.php?title=Schema_-_SENSOR.BASIC">sensor.basic</a>"
schema regardless of developer/platform/etc.  Another good example of
this kind of protocol layering is <a href="http://xmpp.org/xmpp-protocols/">XMPP</a> and the
<a href="http://xmpp.org/xmpp-protocols/xmpp-extensions/">XMPP Extension Protocols</a>.</p>
<p>Essentially what is required to make this work is an ontology - a
specification for topic usage and semantics.  I have no idea how
to produce such a suitable ontology but I plan to think about it
some more.  I'll probably draw ideas from various existing sources
such as <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Message_Schema">xPL Message Schema</a>, <a href="http://www.xapautomation.org/index.php?title=Schema">xAP Message Schema</a>, <a href="http://www.pachube.com/">Pachube</a>
feed definitions, etc.</p>
<p>If anyone has any ideas (is it a good idea, how to proceed, etc?) then
I'd love to hear about them.</p>]]></content:encoded>
    </item>
    <item>
      <title>Home Automation Protocols: xPL</title>
      <link>http://www.temporalanomaly.com/blog/2011/04/11/home-automation-protocols:-xpl</link>
      <pubDate>Mon, 11 Apr 2011 22:42:04 BST</pubDate>
      <category><![CDATA[home automation]]></category>
      <category><![CDATA[protocols]]></category>
      <category><![CDATA[xpl]]></category>
      <guid isPermaLink="true">http://www.temporalanomaly.com/blog/2011/04/11/home-automation-protocols:-xpl</guid>
      <description>Home Automation Protocols: xPL</description>
      <content:encoded><![CDATA[<p>I've been using the <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document">xPL Protocol</a> since 2005, prior to that I
was using Jabber (or <a href="http://xmpp.org/">XMPP</a> as it is known now).  As I'm thinking
about changing protocol, I thought I'd write a bit about <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document">xPL</a> and,
in later posts, something about the candidates to replace it.</p>
<p>The <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document">xPL Protocol</a> has three types of messages: commands
(<code>xpl-cmnd</code>), triggers (<code>xpl-trig</code>) and status (<code>xpl-stat</code>).  They
have the same simple format consisting of the message type, <em>common</em>
"header" fields, the schema type and schema-specific "body" fields.
For example:</p>
<pre><code>xpl-cmnd
{
hop=1
source=vendor-device.host
target=*
}
x10.basic
{
command=on
device=c3
}
</code></pre>
<p>xPL doesn't use a server as its "message bus" is simply UDP port 3865
on the local network broadcast address.  In order to avoid multiple
devices having to listen on the same port on the same broadcast
address, each host runs a hub that distributes messages to all local
xPL clients.  I think this is a poor solution to this problem.  It
introduces an unnecessary single point of failure (albeit one with
very simple-to-test behaviour).  To avoid this single point of
failure, my <a href="https://github.com/beanz/xpl-perl/">xPL clients</a> also support a hubless mode where
they simply set the <code>SO_REUSEADDR</code> socket option on the listen socket
so that all clients can coexist on the same port on the same broadcast
address.  However, if you need to interoperate with clients from other
developers then you'll need to use the standard hub model.</p>
<p>Using UDP broadcasts to avoid any (unnecessary) single points of
failure is a good idea.  However, I have more than 20 xPL clients on
my network and all clients process all messages they receive,
discarding most of them and responding to relatively few.  This means
that all of the clients have to wake up and consume CPU resource for
every single message.  (This is one of the issues that is prompting me
to re-evaluate my choice of protocol.)</p>
<p>I thought about avoiding this problem by combining several clients in
to one more complex client but this seems like a bad idea as it will
inevitably lead to more complexity and thus more complicated failure
cases.  (My <a href="https://github.com/beanz/xpl-perl/">xPL clients</a> are structured in such a way that
this is very easy to do and some users with lower-powered servers do
this.)</p>
<p>For me, the <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Message_Schema">xPL Message Schema</a> are what make the protocol work so
well.  Essentially, the schema define the fields to expect in the body
of an xPL message.  This means I can write a client for a
<a href="http://www.audon.co.uk/udin.html">UDIN USB Relay Controller</a> or a <a href="http://www.phaedrusltd.com/pages/html/viom.html">Phaedrus VIOM</a> that supports the
<a href="http://xplproject.org.uk/wiki/index.php?title=Schema_-_CONTROL.BASIC">control.basic schema</a> and someone else can write a client that uses
the same schema to control relays and it will happily interoperate
with my clients.  (In fact, I realised this advantage when I migrated
from using a VIOM to several more compact UDIN controllers.  I only
needed to change the names of the relays for open/close on my
blinds/curtains after each set of wires were migrated to the new
hardware.)</p>
<p>The schema, as described in the protocol documentation, support a type
of inheritance.  A message schema that inherits from another must
include all of the mandatory fields of the other, in the same order,
so clients can support the basic function even if they don't
understand the additional sub-schema fields.  However, since
optional vendor-specific fields are also allowed without inheritance
(giving a simple duck typing approach), the inheritance mechanism
doesn't really give much benefit.</p>
<p>Take <code>hbeat</code> messages, there are two types, <code>basic</code>:</p>
<pre><code>xpl-stat
{
hop=1
source=vendor-device.host
target=*
}
hbeat.basic
{
interval=5
}
</code></pre>
<p>and, inherited from <code>basic</code>, <code>app</code>:</p>
<pre><code>xpl-stat
{
hop=1
source=vendor-device.host
target=*
}
hbeat.app
{
interval=5
port=43438
remote-ip=198.51.100.2
}
</code></pre>
<p>Why do the messages need the <code>.basic</code> or <code>.app</code>?  So that a client
knows to expect the port and remote-ip fields?  Why does a client need
to know to expect them?  A client can just parse the message and if
the fields are present - i.e. no <code>}</code> following the <code>interval=5</code> line -
then it can treat the message like an <code>.app</code> message and like a
<code>.basic</code> message if not.  It is simply redundant.</p>
<p>The only obviously valid use of the <code>.suffix</code> is <code>.confirm</code> suffix but
this would probably be better implemented as a fourth message type
such as <code>xpl-ack</code> or <code>xpl-conf</code>.</p>
<p>The wildcard <code>target=*</code> line is also redundant since a lack of
explicit <code>target=vendor-device.host</code> could just as easily be used to
distinguish the wildcard case.</p>
<p>These superfluous elements mean that the "Lite on the wire, by design"
subtitle on the <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document">xPL Protocol</a> specification isn't really as
"lite" as it could be (and IMHO should be).</p>
<p>Another confusing aspect of the <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document">xPL Protocol</a> is the notion of a
device.  In the protocol spec, for instance in the
<a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document#Device_Groups">Device Groups</a> section, it is clear that the <code>target</code> field is
addressing an individual device - a controller for a single
curtain/drape.  This is fine in theory, but in practice, individual
devices are general addressed using fields in the <em>body</em>.  For
instance, <code>control.basic</code>, <code>remote.basic</code>, <code>sensor.basic</code>,
<code>x10.basic</code>, and <code>x10.security</code> use <code>device</code>, <code>homeasy.basic</code> uses the
combination of <code>address</code> and <code>unit</code>, <code>zwave.basic</code> uses <code>node</code>, etc.
This is because xPL clients are typically controllers/gateways for
several devices.  For instance, I have a 1-wire sensor/relay network
with dozens of devices attached to it but one xPL client opens the
1-wire USB interface and manages all of these devices based on the
<code>device</code> field in <code>control.basic</code> and <code>sensor.basic</code> messages.</p>
<p>The protocol would be simpler to use if addressing of devices was more
consistent.  In fact, devices (rather than clients) should be
first-class citizens on the "network".  That is, they should be
discoverable (like clients are today with <code>hbeat</code> requests) and
probably should be aliasable (so that they can be given memorable
names).</p>
<p>I like the <a href="http://xplproject.org.uk/wiki/index.php?title=XPL_Specification_Document">xPL Protocol</a>; it has been my protocol of choice for
more than 5 years and most of these issues are not a big deal.  The
broadcast message bus is simple (if you ignore hubs) and reliable but
the inefficiency of waking all clients on every message is starting to
become an issue for me.  So, in the next few posts, I'll write about
some of the alternatives I am considering.</p>]]></content:encoded>
    </item>
  </channel>
</rss>

