An extension for node-opcua implementing CoreAAS Information Model and providing new functions to easily implement your Asset Administration Shell using OPC UA and Node.js.
This new version has been completely rewritten in typescript to easily develop OPC UA Server supporting CoreAAS and take advantage of the type annotations and other amazing features that typescript introduce. It is worth noting that this new version is not compatible with the version 0.2.2. The API has been completely re-designed and now creating an OPC UA Server supporting CoreAAS Information Model is more linear and no strange workaround or fix is required.
Since Typescript is transpilled in Javascript, you are not forced to write your server in Typescript. Feel free to use node-opcua-coreaas in your Javascript code.
CoreAAS Information Model is an OPC UA implementation of the Asset Administration Shell (AAS) metamodel here provided by Platform Industrie 4.0.
node-opcua-coreaas is an extension for the Node.js stack node-opcua including new functions in order to easily populate your OPC UA Server with Objects related to AAS, Assets, Submodel, etc. without taking care about putting the Nodes and references in the right place.
In order to start developing your own AAS using node-opcua-coreaas, just create a new folder and initialize an npm project:
$ mkdir my-project
$ cd my-project
$ npm init
After that, you can install node-opcua-coreaas as dependency using the following command:
$ npm install node-opcua-coreaas --save
You don't need to install node-opcua as dependency for your project since node-opcua-coreaas already depends on it and re-export all its API. Be careful if you decide to use node-opcua as dependancy, because the version you install may be different from the one node-opcua-core aas depends on.
Creating an OPC UA Server suporting CoreAAS is very simple. The following example shows how to create a sample Server exposing an Asset Administration Shell with a Submodel and the physical Asset the AAS is representing:
import path from "path";
import { coreaasXmlFile, nodesets, localizedText, CoreServer, IdentifierType, Kind, KeyType, KeyElements } from ".";
let xmlFiles = [nodesets.standard, coreaasXmlFile]
let server = new CoreServer({
nodeset_filename: xmlFiles,
port: 4848
})
function post_initialize() {
const Identifier = server.coreaas.Identifier;
const Key = server.coreaas.Key;
let admin = server.coreaas.addAdministrativeInformation({
version: "555",
revision: "1825"
});
const aas_1 = server.coreaas.addAssetAdministrationShell({
browseName: "SampleAAS",
description: [ new LocalizedText({locale: "en", text: "Festo Controller"}),
new LocalizedText({locale: "de", text: "Festo Controller"}) ],
identification: new Identifier({
id: "www.admin-shell.io/aas-sample/1.0",
idType: IdentifierType.URI
}),
assetRef: [new Key({
idType: KeyType.URI,
local: true,
type: KeyElements.Asset,
value: "http://pk.festo.com/3S7PLFDRS35"
})],
derivedFromRef: [ new Key({
idType: KeyType.IRDI,
local: false,
type: KeyElements.AssetAdministrationShell,
value: "AAA#1234-454#123456789"
}) ],
administration: admin
}).addSubmodelRef([new Key({
idType: KeyType.URI,
local: true,
type: KeyElements.Submodel,
value: "http://www.zvei.de/demo/submodel/12345679"
})]);;
let asset = server.coreaas.addAsset({
browseName: "3S7PLFDRS35",
idShort: "3S7PLFDRS35",
identification: new Identifier({
id: "http://pk.festo.com/3S7PLFDRS35",
idType: IdentifierType.URI
}),
kind: Kind.Instance,
description: "Festo Controller Asset",
//assetOf: aas_1,
assetIdentificationModelRef: [ new Key({
idType: KeyType.URI,
local: false,
type: KeyElements.Submodel,
value: "//submodels/identification_3S7PLFDRS35"
}) ]
});
aas_1.hasAsset(asset)
.addSubmodelRef([new Key({
idType: KeyType.URI,
local: true,
type: KeyElements.Submodel,
value: "http://www.zvei.de/demo/submodel/12345679"
})]);
/**
* Start The OPC UA Server
*/
server.start(function () {
console.log("Server is now listening ... ( press CTRL+C to stop)");
console.log("port ", server.endpoints[0].port);
var endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl;
console.log(" the primary server endpoint url is ", endpointUrl );
});
}
server.initialize(post_initialize);
Of course this is a very simple example. More entities, like SubmodelElements and ConceptDescriptions, can be added in the AddressSpace.
You can found 2 demo files in the project. Just use it as a fully example about how to use node-opua-coreaas. Of course be sure to change the require
statement putting the node-opcua-coreaas module.
- "demo.js" is a single-file sample showing an AAS based on the example shown in this document.
- "demo2.js" is the same as demo.js but with more elements and shows how to do the same things using different convenience methods.
The main entities of node-opcua-coreaas are CoreServer and CoreAASExtension:
- CoreServer is the main class you use to create an OPC UA Server supporting CoreAAS. It is a subclass of OPCUAServer of node-opcua.
- CoreAASExtension is the extension part of the CoreServer exposing all the methods necessary to create CoreAAS ObjectTypes instances inside the AddressSpace. Users should not use this class directly, but the property coreaas of CoreServer will provide a CoreAASExtension instance bounded to the AddressSpace that users should use to create CoreAAS entities.
More details about the API can be found in the documentation.