Created
August 13, 2019 12:27
-
-
Save erossignon/3b31b733dee14a97fc447c7a9ef8ba6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const chalk = require("chalk"); | |
const { | |
OPCUAServer , | |
OPCUACertificateManager | |
} = require("node-opcua"); | |
const certificateManager = new OPCUACertificateManager({ | |
automaticallyAcceptUnknownCertificate: true, | |
rootFolder: "./certificates/PKI", | |
}); | |
const server = new OPCUAServer({ | |
port: 26545, | |
serverCertificateManager: certificateManager, | |
/** */ | |
certificateFile: "./certificates/server_certificate.pem", | |
privateKeyFile: certificateManager.privateKeyFile, | |
buildInfo: { | |
productUri: "urn:{hostname}:CapgeminiDemoApp" | |
} | |
}); | |
(async ()=> { | |
console.log(chalk.red("Hello s") + chalk.green("World")); | |
await server.initialize(); | |
/** | |
* | |
* @param {AddressSpace} addressSpace | |
*/ | |
function populateAddressSppace(addressSpace) | |
{ | |
const namespace = addressSpace.getOwnNamespace(); | |
const folder = namespace.addFolder(addressSpace.rootFolder.objects, | |
{ | |
browseName: "MyFolder" | |
}); | |
const boiler = namespace.addObject({ | |
browseName: "Boiler", | |
organizedBy: folder | |
}); | |
const temperature = namespace.addVariable({ | |
browseName: "Temperature", | |
accessLevel: "CurrentRead", | |
componentOf: boiler | |
}); | |
let setPointTemperatureValue = 10.0; | |
// install a Read/Write variable representing a temperature set point of a temperature controller. | |
const setpointTemperature = namespace.addVariable({ | |
browseName: "SetPointTemperature", | |
componentOf: boiler, | |
dataType: "Double", | |
accessLevel: "CurrentRead | CurrentWrite", | |
value: { | |
get: function () { | |
console.log("Client is requesting SetPointTemperature") | |
return new Variant({ | |
dataType: DataType.Double, | |
value: setPointTemperatureValue }); | |
}, | |
set: function (variant) { | |
console.log("Client is setting SetPointTemperature") | |
setPointTemperatureValue = parseFloat(variant.value); | |
return StatusCodes.Good; | |
} | |
} | |
}); | |
} | |
populateAddressSpace(server.engine.addressSpace); | |
await server.start(); | |
console.log("Certificate rejected folder ", server.serverCertificateManager.rejectedFolder); | |
console.log("Certificate trusted folder ", server.serverCertificateManager.trustedFolder); | |
console.log("Server private key ", server.serverCertificateManager.privateKey); | |
console.log("Server started"); | |
const endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl; | |
console.log(" server is ready on ", endpointUrl); | |
console.log("CTRL+C to stop"); | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment