Triggering events

As mentioned earlier, the sensor data interfaces support event subscription as well as the readout on request. When subscribing to events, you provide minimum and maximum time intervals for events. You can also provide information about individual fields, and describe threshold values for how much a value is allowed to change until an event is triggered. To enable this feature properly, the application needs to report new momentary values to the Sensor Server object. The object, in turn, keeps track of all active subscriptions and makes sure events are triggered as they should be. When they are triggered, the OnExecuteReadoutRequest event is triggered as if a request would have been received. The event arguments point to the original subscription request when processing the readout.

Reporting new momentary values is easy. You only call the NewMomentaryValues() method whenever you calculate a new momentary value. For example:

this.sensorServer?.NewMomentaryValues(new QuantityField( 
ThingReference.Empty,Timestamp, "Light", Light, 2, "%", 
FieldType.Momentary, FieldQoS.AutomaticReadout)); 

And we do the same for our motion:

this.sensorServer?.NewMomentaryValues( 
new BooleanField(ThingReference.Empty, this.lastPublished, 
"Motion", Motion, FieldType.Momentary, 
FieldQoS.AutomaticReadout)); 

Similarly, we should also report each change of the output value in our actuator. This would allow others to subscribe to events relating to the change of the switch:

this.sensorServer?.NewMomentaryValues( 
new BooleanField(ThingReference.Empty, DateTime.Now, "Output", 
On, FieldType.Momentary, FieldQoS.AutomaticReadout)); 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.111.125