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

Losing a friend

When you lose a connection, or a friend, you might need to update your state or find new devices, if the connection that was lost was your sensor or actuator. Since this may happen for various reasons, we create a function for this event:

private void XmppClient_OnRosterItemRemoved(object Sender, 
   RosterItem Item) 
{ 
   Log.Informational("Roster item removed.", Item.BareJid); 
   this.FriendshipLost(Item); 
} 

When this happens, we restart the registration procedure, which in turn triggers the search procedure. This will allow the controller to eventually find new devices in its vicinity to which it can connect, to continue its operation:

private void FriendshipLost(RosterItem Item) { bool UpdateRegistration = false; if (string.Compare(Item.BareJid, ...

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