Skip to content

fix(examples): make the OPC UA examples runnable - #1573

Open
erossignon wants to merge 4 commits into
eclipse-thingweb:masterfrom
node-opcua:fix/examples-opcua-runnable
Open

erossignon wants to merge 4 commits into
eclipse-thingweb:masterfrom
node-opcua:fix/examples-opcua-runnable

Conversation

@erossignon

Copy link
Copy Markdown
Contributor

Two independent fixes that make the OPC UA examples runnable. Refs #1012.

npm run bindings:opcua:1 / :2 pointed at files that do not exist

The scripts still named opcua-demo1.js / opcua-demo2.js; the sources are demo-opcua1.ts / demo-opcua2.ts. Also adds the missing bindings:opcua:secure — demo-opcua-secure.ts arrived with #1552 but never got a script, so there was no way to run it.

All four bindings:opcua:* targets now resolve against dist/ after npm run build.

The coffee machine demo could not invoke its actions

brewCoffee failed against the live demo server with:

Error in Calling OPCUA Method : BadMethodInvalid (0x80750000)

Both action forms passed the CoffeeMachineA object as the OPC UA objectId, but MakeCoffee and FillTank are components of its 2:MethodSet, not of the machine. The Call service requires the method to belong to the object named, so the server refused the pairing — after resolving the method node itself perfectly well, which is what made the error puzzling.

Verified against opc.tcp://opcuademo.sterfive.com:26543, calling the same method two ways:

objectId result
ns=1;i=1676 (the machine) BadMethodInvalid (0x80750000)
ns=1;i=1709 (2:MethodSet) Good (0x00000000)

fillTank had the identical defect and would have failed next; the script just died at brewCoffee first. Both forms now point at 2:MethodSet, and the demo runs end to end: both brewCoffee calls and fillTank complete, bean level drops 500 -> 460 g.

Caveats

  • Needs the public demo server, so it cannot be covered by a unit test.
  • The demo's last two milestones ("Tank is refilled !", "Done !") still never appear on screen. That is separate and pre-existing: recordAction only appends to an array, and the display repaints solely from observation callbacks, so nothing redraws once the machine settles back to standby.
  • A hand-written TD has no way to know which object owns a method. [OPC UA] Support needed for other TD terms #1407 tracks reading the owner from uav:componentOf, with a fallback to browsing the method's inverse HasComponent — that would remove this footgun.

bindings:opcua:1 and :2 still referred to opcua-demo1.js and
opcua-demo2.js, renamed to demo-opcua1.js and demo-opcua2.js by the
kebab-case rename; both scripts failed with "Cannot find module".

Adds bindings:opcua:secure for the security demo, which had no script.
brewCoffee and fillTank passed the CoffeeMachineA object as the OPC UA
objectId, but MakeCoffee and FillTank are components of its 2:MethodSet,
not of the machine. The server rejected the pairing with
BadMethodInvalid, after resolving the method node itself just fine.

Point opcua:nodeId at 2:MethodSet in both action forms.
@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.34%. Comparing base (334e894) to head (334ef15).
⚠️ Report is 38 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1573      +/-   ##
==========================================
+ Coverage   78.25%   79.34%   +1.09%     
==========================================
  Files          91       91              
  Lines       15907    16162     +255     
  Branches     1544     1587      +43     
==========================================
+ Hits        12448    12824     +376     
+ Misses       3436     3315     -121     
  Partials       23       23              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@danielpeintner danielpeintner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general comment. The readme in packages/examples/src/bindings/opcua does not explain what all the ts files are for. Maybe we can spend some time describing what each demo is meant to show...

@erossignon

Copy link
Copy Markdown
Contributor Author

I'll add a followup commit with improved readme.

The temperature property copied the unit of pumpSpeed, and demo-opcua2
printed it. The demo server reports values around 27, i.e. degrees.
Describes what each of the four demos shows, how to run it (including
the test server the secure demo needs), and the two TD idioms readers
trip on: browse paths, and the method owner in an action form.
Output samples come from real runs; images are hand-made SVGs.
Written in ASD-STE100 Simplified Technical English.
@erossignon

Copy link
Copy Markdown
Contributor Author

@danielpeintner , the readme in packages/examples/src/bindings/opcua now explains

@danielpeintner

Copy link
Copy Markdown
Member

I think the update looks good. I would wait for #1574 to be merged first since after that we need to change the TDs providing the right contentType...
Otherwise the examples will no longer work, right?

@erossignon

Copy link
Copy Markdown
Contributor Author

Otherwise the examples will no longer work, right?

I'll take take of this, but first merge this PR...

@erossignon erossignon closed this Oct 26, 2026
@erossignon erossignon reopened this Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants