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

Subscribing to sensor data events

From several sections of the code, we've made references to a SubscribeToSensorData() method that will be called when we're ready to subscribe to the sensor data from the sensor. We are now ready to focus on how this is done. The first thing to note is that we can only perform a subscription if we know a sensor, and if it is online:

private void SubscribeToSensorData() 
{ 
   RosterItem SensorItem; 
 
   if (!string.IsNullOrEmpty(this.sensorJid) && 
         (SensorItem=this.xmppClient[this.sensorJid]) != null && 
         SensorItem.HasLastPresence && 
         SensorItem.LastPresence.IsOnline) 
   { 

If a previous subscription exists, we make sure to unsubscribe to it. This has the effect that if stray messages are received on this subscription, they ...

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