Skip to content

Instantly share code, notes, and snippets.

@danielpeintner
Created June 9, 2023 11:20
Show Gist options
  • Save danielpeintner/c20319e098e5adcb571d4f37c2eb6999 to your computer and use it in GitHub Desktop.
Save danielpeintner/c20319e098e5adcb571d4f37c2eb6999 to your computer and use it in GitHub Desktop.
// demo-opcua1.js
Servient = require("@node-wot/core").Servient;
OPCUAClientFactory = require("@node-wot/binding-opcua").OPCUAClientFactory;
const thingDescription = {
"@context": "https://www.w3.org/2019/wot/td/v1",
"@type": ["Thing"],
securityDefinitions: { nosec_sc: { scheme: "nosec" } },
security: "nosec_sc",
title: "servient",
description: "node-wot CLI Servient",
properties: {
pumpSpeed: {
description: "the pump speed",
type: "number",
forms: [
{
href: "opc.tcp://opcuademo.sterfive.com:26543", // endpoint,
op: ["readproperty", "observeproperty"],
"opcua:nodeId": "ns=1;s=PumpSpeed",
},
],
},
},
};
(async () => {
const servient = new Servient();
servient.addClientFactory(new OPCUAClientFactory());
const wot = await servient.start();
const thing = await wot.consume(thingDescription);
const content = await thing.readProperty("pumpSpeed");
const value = await content.value();
if (value != null) {
const json = (value).valueOf();
console.log("Pump Speed is", json);
}
await servient.shutdown();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment