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

Re-subscribing to sensor data

Our first test is to compute the number of seconds since we got some information from our subscription. If it's more than 70 seconds (remember that we configured a maximum interval of 60 seconds), we draw the conclusion that the subscription is no longer active. So we make a new subscription request:

private void SecondTimerCallback(object State) 
{ 
   DateTime Now = DateTime.Now; 
   double SecondsSinceLastEvent = Math.Min( 
         (Now - this.lastEventFields).TotalSeconds, 
         (Now - this.lastEventErrors).TotalSeconds); 
   double SecondsSinceLastOutput =  
         (Now - this.lastOutput).TotalSeconds; 
   RosterItem Item; 
   bool Search = false; 
 
   if (this.subscription != null && SecondsSinceLastEvent > 70) 
         this.SubscribeToSensorData(); 

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