Created
June 9, 2023 08:35
-
-
Save danielpeintner/e6c0f3723dce910f2dfcb8128f10b964 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
// 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