How to implement a new plugin

From AMTech WikiDocs
Revision as of 11:28, 2 February 2018 by Hector (Talk | contribs)

Jump to: navigation, search
  • Create a thing type XXXThing (See Thing types)
  • Create the observations type the thing XXXThing produces or consumes, example XXXThingObserv1 (See Observations and observation types)
  • Associate the observation XXXThingObserv1 type to the XXXThing
  • Implement a nodejs module with the following interface
    function XXXThing() {
    }

    XXXThing.prototype.start = function ( complete) {
        try {
            complete(null);
        } catch (e) {
            complete(e);
        }
    };

    XXXThing.prototype.stop = function (complete) {
        try {
            complete(null);
        } catch (e) {
            complete(e);
        }
    };

    XXXThing.prototype.command = function (observation, complete) {
        try {
            complete(null);
        } catch (e) {
            complete(e);
        }
    };

    module.exports.XXXThing = XXXThing;

Implementing smoothing

In order to include the smoothing tool we propose, the nodejs code should ensure the following

  • import the smoothing handler class
const SmoothingHandler = require("../../common/smoothingHandler.js");
  • initialize the smoothing handler in start function.
this.smoothingHandler = new SmoothingHandler(smoothingConfig, this.logger, smoothingId);

where smoothingId is used only for logging purpose and smoothingConfig contains the smoothing configuration (see below)

  • free the smoothing memory on plugin stop function
this.smoothingHandler.destroy();
this.smoothingHandler=undefined;
  • verify if the observation satisfy or not the smoothing criteria with the smooth function of the smoothing handler, for instance:
if (this.smoothingHandler.smooth(deviceId, observation)){
   this.sendObservation(...);
}


Smoothing configuration