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 presence changes

Now that you have presence subscriptions active for your contacts, you need to react to changes in presence. They may indicate that the corresponding device has restarted, for instance. So, you need to register an event handler that is called when presence changes for one of your contacts in the roster:

this.xmppClient.OnPresence += XmppClient_OnPresence; 

Whenever your sensor signals an online presence, you should re-subscribe to it, to make sure events are delivered in a timely fashion:

private void XmppClient_OnPresence(object Sender, PresenceEventArgs e) { Log.Informational("Presence received.", e.Availability.ToString(), e.From); if (this.sensorJid != null && string.Compare(e.FromBareJID,this.sensorJid,true)==0 ...

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