Adding XMPP support to the actuator

Like with the sensor project, adding the final interfaces for our actuator is a minor task. The device will register itself as LearningIoT-Actuator instead of LearningIoT-Sensor for instance. Adding a sensor server interface to the actuator is done in more or less the same way as described for the sensor, except that the names and types of the fields and momentary values are different. In this section, we will discuss the actuator-specific interfaces that need to be considered.

The contracts we will use for the actuator are as follows:

xmppInteroperabilityServer = new XmppInteroperabilityServer (
  xmppClient,
  "XMPP.IoT.Actuator.DigitalOutputs",
  "XMPP.IoT.Security.Alarm",
  "Clayster.LearningIoT.Actuator.DO1-8");

Adding a controller server interface

The XMPP extension XEP-0325: IoT - Control specifies how control operations in IoT can be performed using the XMPP protocol. It defines an asynchronous messaging model and a parallel request/response model, where a client sends control commands to a server. The client can also request for a set of available controllable parameters in the server. There is a class we can use that implements this extension for us. It is called XmppControlServer.

In our actuator, we therefore create an instance of this class as soon as we have both an XMPP client created and a provisioning server defined. The constructor requires a list of control parameters defining what parameters should be controllable through the interface. These parameters should match the corresponding fields that are readable through the sensor server interface. Each control parameter is defined by the following parameters:

  • Data type of the underlying value
  • Control parameter's name
  • The current value
  • Delegate to the callback method, which is called when the parameter is read
  • Delegate to the callback method, which is called when the parameter is set
  • A title string
  • A tooltip string
  • Possible range

Some of the parameters are used when creating a control form for the corresponding parameters, and they are meant for end users and for input form validation. The Clayster.Library.IoT.XmppInterfaces.ControlParameters namespace contains classes for the different types of control parameters supported by XEP-0325. We create our control server as follows. We've replaced a sequence of repetitive parameters with an ellipsis ("…"):

xmppControlServer = new XmppControlServer (
  xmppClient, xmppProvisioningServer, 
  new BooleanControlParameter ("Digital Output 1",
    () => wsApi.GetDigitalOutput (1),
    (v) => wsApi.SetDigitalOutput (1, v),
    "Digital Output 1:", "State of digital output 1."),
  ...,
  new BooleanControlParameter ("Digital Output 8",
    () => wsApi.GetDigitalOutput (8),
    (v) => wsApi.SetDigitalOutput (8, v),
    "Digital Output 8:", "State of digital output 8."),
  new BooleanControlParameter ("State",
    () => wsApi.GetAlarmOutput (),
    (v) => wsApi.SetAlarmOutput (v),
    "Alarm Output:","State of the alarm output."),
  new Int32ControlParameter ("Digital Outputs",
    () => (int)wsApi.GetDigitalOutputs (),
    (v) => wsApi.SetDigitalOutputs ((byte)v),
    "Digital Outputs:", "State of all digital outputs.",
    0, 255));
..................Content has been hidden....................

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