Instantiating the digital input object

We are now almost done with our digital input smart object. In our application class, we create a field member digitalInput0 to hold a reference to our digital input object instance. We instantiate it, by adding it to the list of LWM2M objects supported by our LWM2M client:

this.lwm2mClient = new Lwm2mClient("MIoT:Sensor:" + this.deviceId, 
  this.coapEndpoint, 
  new Lwm2mSecurityObject(), 
  new Lwm2mServerObject(), 
  new Lwm2mAccessControlObject(), 
  new Lwm2mDeviceObject("Waher Data AB", "SensorLwm2m", 
    this.deviceId, "1.0", "Sensor", "1.0", "1.0"), 
  new DigitalInput( 
    this.digitalInput0 = new DigitalInputInstance(0, 
      this.lastMotion, "Motion Detector", "PIR"))); 

The last thing we need to do, to get our digital input object to work, is to report new values to it. We update our pin update event, to report new values to our digital input object:

bool Input = (value == PinState.HIGH); 
this.lastMotion = Input; 
this.digitalInput0?.Set(Input); 
this.motionResource?.TriggerAll(); 
this.momentaryResource?.TriggerAll(); 
Now that you know how to publish one LWM2M sensor object, the procedure for publishing more sensor objects and object instances is straightforward. The SensorLwm2m project in the GitHub repository adds objects and object instances representing an analog input, two generic sensors, one illuminance sensor, one presence sensor, and one percentage sensor to the application. They will present the motion detector and light sensor values through different IPSO Smart Object interfaces, allowing for increased interoperability.
..................Content has been hidden....................

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