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 ...

Get Mastering Internet of Things now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.