Skip to content

Instantly share code, notes, and snippets.

@danielpeintner
Created June 9, 2023 08:35
Show Gist options
  • Save danielpeintner/e6c0f3723dce910f2dfcb8128f10b964 to your computer and use it in GitHub Desktop.
Save danielpeintner/e6c0f3723dce910f2dfcb8128f10b964 to your computer and use it in GitHub Desktop.
// demo-opcua1.ts
import { Servient } from "@node-wot/core";
import { OPCUAClientFactory } from "@node-wot/binding-opcua";
const thingDescription : WoT.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