Thursday 19 December 2013

Discovery and Set-up in the Object Network IoT

When we have bought our light and turned it on, what happens next?

In today's episode I'll sketch out how discovery and set-up would work for the Object Network Internet of Things.

This is the initial sequence of low-level events:
  1. The light scans for beacons around and picks the strongest one
  2. It gets connected to the LAN, either by getting the WiFi details from its neigbour..
  3. .. or through a BLE connection via its neighbour
  4. It gets the URL of the nearest neighbour Thing from its advertisement
  5. It advertises its own URL on its own beacon
These steps get the light connected to the local net and result in the URL of a nearest neighbour object to put into the light object to get it kicked off.

It can then go ahead and execute the following steps as simple Cyrus rules, which will trigger the underlying FOREST interactions over the LAN (basically just GETs and POSTs of JSON):
  1. It GETs the neighbouring Thing's JSON over the LAN from that URL
  2. It gets that Things "place" (room) URL - it's assuming it's in the same room
  3. It sets its own place/room to that URL, then POSTs its own JSON to that place
  4. The place adds the light as a new Thing in the room with a link back to it
  5. The light scans other Things linked to by the room to find any light sensor
  6. The light runs that rule I described yesterday, to decide whether or not to turn on
Steps 1-3 are encoded in just this one rule:

{ is: light rule
  within: # => @nearest-neighbour:within
  Notifying: => @. with @within
}

This grabs the "within" place URL off the nearest neighbour Thing that was set by the first steps, then sets up notifications to that place, so that it can see the light is now here.

The "#" ensures that this rule only fires if the within property hasn't already been set. The symbol "@." refers to the property being rewritten, here the "Notifying" property which is the current list of URLs to be notified of changes. The symbol "with" means "ensure that this list includes the following" - here the "@within" URL.

Step 4 is this rule:

{ is: place rule
  Alerted: { within: @ }
  sub-objects: => @. with { object: @Alerted }
}

The other end of a Notifying is an Alerted, which is where the place object gets to see the light object's state. It then adds an entry for it in its list of sub-objects.

Step 5 is this rule:

{ is: light rule
  within: { sub-objects: { object: { is: light-sensor } } }
  light-sensor: # => @=within:sub-objects:object
}

This match will jump the place/room link and then all the links of all the Things in the room, searching for a Thing that "is:" a "light-sensor". The "@=" syntax means only get the object links that have been matched by the rule, not all of them. There may be just one, or a list of them.

Additional steps would be needed for the light to triangulate an approximate location in the room for itself from other neighbours' location and signal strength.

No comments:

Post a Comment