Adding a control resource to our actuator

Out actuator will have a simpler interface. We will only register one observable resource called Output. It will return the current state of the output. Clients can subscribe to changes to the resource to be notified whenever the output changes, for any reason. Apart from adding a GET method handler, we will also add a POST method handler, allowing clients to change the output from the network. We begin by adding the GET method handler:

this.outputResource = this.coapEndpoint.Register("/Output", 
   (req, resp) => 
   { 
         string s; 
 
         if (this.output.HasValue) 
               s = this.output.Value ? "true" : "false"; 
         else 
               s = "-"; 
 
         resp.Respond(CoapCode.Content, s, 64); 

The resource returns a simple Boolean value (true or false), depending on the state of the output. If the state is unknown, - is returned. The response will be encoded as plain text in both cases.

..................Content has been hidden....................

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