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

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 ...

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