Finding friends in the roster

After a successful registration or update of an existing registration in the Thing Registry, the controller calls the FindFriends method with the metadata used in the registration:

this.FindFriends(MetaInfo); 

The FindFriends method will connect the controller to the corresponding sensor and actuator in its vicinity. The first step is to check that such connections are not already defined. We will use the roster of our XMPP connection, that is, our list of "friends," as the knowledge base of our contacts. To each contact on our roster, we can assign groups. Groups are just string tags we annotate each contact with. We can use this array of groups to describe our contacts. These descriptions are stored on the broker, and follow our account, rather than our local storage. This means that if you change hardware, but reuse the XMPP account, it will retain the information and friendships. So, the first thing we need to do is check our roster if we already have our sensor and actuator identified:

private void FindFriends(MetaDataTag[] MetaInfo) 
{ 
   this.sensorJid = null; 
   this.sensor = null; 
   this.actuator = null; 
   this.actuatorJid = null; 
 
   foreach (RosterItem Item in this.xmppClient.Roster) 
   { 
         if (Item.IsInGroup("Sensor")) 
         { 
               this.sensorJid = Item.BareJid; 
               this.sensor = this.GetReference(Item, "Sensor"); 
         } 
 
         if (Item.IsInGroup("Actuator")) 
         { 
               this.actuatorJid = Item.BareJid; 
               this.actuator = this.GetReference(Item, 
                     "Actuator"); 
         } 
   }
Here, the GetReference() method loops through all groups to extract any NodeId, SourceId, and Partition parameters made available by the presence of optional group names, such as Sensor.nid:NODEID, Sensor.sid:SOURCEID, and Sensor.prt:PARTITION. See the GitHub source example for the details.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.93.136