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

Choosing relevant values

Before we publish the data, we need to consider what data is relevant to publish. We want to avoid spamming the broker, or any subscribers. We define relevant to mean values that show a significant change (more than one percentage point), or values after significant silence (at least 15 seconds):

private void PublishLight(double Light) 
{ 
   DateTime Now = DateTime.Now; 
 
   this.lastLight = Light; 
 
   if ((!this.lastPublishedLight.HasValue || 
         Math.Abs(this.lastPublishedLight.Value-Light) >= 1.0 || 
         (Now-this.lastLightPublishTime).TotalSeconds >= 15.0) && 
         this.mqttClient != null && 
         this.mqttClient.State == MqttState.Connected) 
   { 
         this.lastPublishedLight = Light; 
         this.lastLightPublishTime = Now; 
What relevant means should be configurable. ...

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