Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
/ mi5-module-js Public archive

no maintenance. only use after upgrading dependencies.

License

Notifications You must be signed in to change notification settings

ProjectMi5/mi5-module-js

Repository files navigation

Your own IoT Module written in node.js

With mi5-module-js you can easily write your interface for the Internet of Things.

What does it do?

This module helps you create your own interactive information model for your IoT device. Automatically, this will be deployed to a OPC UA server, which lets other IoT devices connect to your device. And you do not have to know anything about OPC UA.

This means: You can define modules, skills, skill-parameters and state-variables. The rest will be done by the mi5-module-js.

If you want to change the server structure, you are free to do so. Documentation for that comes soon.

Installation

You may have a look at the mi5-module-js-example project in order to get started. General usage of this module is described here:

  1. Install Node.js version >= v8.9.1.
  2. Create a new folder for your project.
  3. Navigate to this folder in the command prompt.
  4. Run npm init and fill in the requested information or let it empty.
  5. Then run npm install https://github.com/ProjectMi5/mi5-module-js --save.
  6. Create a file app.js and fill in some code from the following sections.
  7. In the command line, run node app.js.
  8. If you want to browse your server, you might want to use the UaExpert OPC UA Client. It is for free but you are required to register first. Have a look at the console output to see at which port the server is listening. If you do not change the settings, it will be opc.tcp://127.0.0.1:4840

The API

Your own module

Require the module and create a new instance.

const Mi5Module = require('mi5-module').Mi5Module;
let yourFirstModule = new Mi5Module(moduleName [, moduleId[, settings]]);

moduleName is a String. settings can look like this:

const settings = {
	port: 4840, // you only need to specify this, if you want another port than 4840
	// documentation on other settings coming soon
};

Skills

A module has skills that it can present to the outside and that can be executed.

Create

let yourSkill = yourFirsModule.addSkill(name[, id]);

Use Skill Parameters

Skill parameters work as the inputs and outputs of your skill. Accordingly, there are inputParameters and outputParameters. They can be created as follows:

let yourInputParameter = yourSkill.addInputParameter(name, dataType, initValue);
let yourOutputParameter = yourSkill.addOutputParameter(name, dataType, initValue);

Supported data types are Boolean, Integer, Double and String.

State Machine

Module and Skills all have the following state machine.

Image: State Machine

The only thing you have to do is to implement what happens in each state.

yourFirstModule.on('Running', ()=>{
  // your code here
  yourFirstModule.done(); // once done
});

When you are in a state followed by an unnamed transition, then call yourFirstModule.done() once your task is finished.

So, all the states are:

  • Idle
  • Starting
  • Running
  • Pausing
  • Paused
  • Suspending
  • Suspended
  • Unsuspended
  • Unsuspending
  • Completing
  • Complete
  • Aborting
  • Aborted
  • Stopping
  • Stopped
  • Holding
  • Held
  • Unholding
  • Clearing
  • Resetting

Don't worry, if it is too many states and you do not want to support all of them. You can subscribe to multiple states at once and skip them.

const skippedEvents = ['Unholding', 'Resetting', 'Clearing'];
yourFirstModule.onAny(function(event, value){
  if(skippedEvents.indexOf(event) > 0){
    yourFirstModule.done();
  }
});

State Variables

State variables don't have to do anything with the state machine. They simply enable you to display values of your module that are independent of its skills.

let yourStateVariable = yourModule.addStateVariable(name, dataType, initValue[, path]);

Supported data types are Boolean, Integer, Double and String.

OPC UA Variables

Each parameter and state variable is a OPC UA Variable and comes with the following methods:

  • variable.setValue(value)
  • variable.getValue()
  • variable.onChange(function(value){})
  • variable.oneChange(function(value){})
  • variable.monitor()
  • variable.unmonitor()

About

no maintenance. only use after upgrading dependencies.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published