O'Reilly logo

Mastering Internet of Things by Peter Waher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reacting to claims

Device claims can occur either when the device is online, or when it is offline. We need to handle both cases. If the claim occurred while the device was offline, we get notified of this fact in the response to the registration call:

   else 
   { 
         await RuntimeSettings.SetAsync(     "ThingRegistry.Key", 
               string.Empty); 
         Log.Informational("Registration updated. Device has "+ 
               "an owner.", new KeyValuePair<string, object>( 
               "Owner", e.OwnerJid)); 
   }

By adding an event handler for the Claimed event on the ThingRegistry instance, we can react immediately to the event, if the device is online. We store the network address of the owner, as well as clear the key:

this.registryClient.Claimed += async (sender, e) => { try { await RuntimeSettings.SetAsync("ThingRegistry.Owner", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required