With mi5-module-js you can easily write your interface for the Internet of Things.
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.
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:
- Install Node.js version >= v8.9.1.
- Create a new folder for your project.
- Navigate to this folder in the command prompt.
- Run
npm init
and fill in the requested information or let it empty. - Then run
npm install https://github.com/ProjectMi5/mi5-module-js --save
. - Create a file app.js and fill in some code from the following sections.
- In the command line, run
node app.js
. - 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
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
};
A module has skills that it can present to the outside and that can be executed.
let yourSkill = yourFirsModule.addSkill(name[, id]);
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
.
Module and Skills all have the following 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 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
.
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()