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

Collecting relevant sensor data

The field event handler is called when sensor data is received from the subscription. It will contain an enumeration of fields. All we need to do is loop through them and see if we can find the fields we are looking for. If we do, we update our internal state, and make sure we update the controller output. We also make sure to update our main window, so that we get visual feedback:

private void Subscription_OnFieldsReceived(object Sender, IEnumerable<Field> NewFields) { bool RecalcOutput = false; this.lastEventFields = DateTime.Now; foreach (Field Field in NewFields) { switch (Field.Name) { case "Light": if (Field is QuantityField Q) { MainPage.Instance.LightUpdated( Q.Value, Q.NrDecimals, Q.Unit); if (Q.Unit ...

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