Skip to content

ContentType seems to confuse OPC UA #1400

Closed

Description

@danielpeintner

The following code tries to read an OPC UA property

const read1 = await thing.readProperty("1:Speed");
console.log("speed value is: ", await read1.value());

with the following TD

              "properties": {
                  "1:Speed": {
                      "title": "Speed",
                      "type": "number",
                      "forms": [
                          {
                              "href": "/?id=ns=1;s=MotorSpeed"
                          }
                      ],
                      "observable": true
                  }
             }

everything works fine while adding a "contentType": "application/octet-stream" which looks like this breaks it.

              "properties": {
                  "1:Speed": {
                      "title": "Speed",
                      "type": "number",
                      "forms": [
                          {
                              "href": "/?id=ns=1;s=MotorSpeed",
                              "contentType": "application/octet-stream"
                          }
                      ],
                      "observable": true
                  }
             }

fails with

TypeError: dataType.toLowerCase is not a function
at OctetstreamCodec.valueToBytes 

This seems to indicate that OPC UA data is processed by OctetstreamCodec also (again?)

Activity

  1. danielpeintner commented on Jun 24, 2025

    @danielpeintner
    MemberAuthor

    Changing it to something unknown like "contentType": "application/octet-stream-x" fails, with
    NotSupportedError: Content type application/octet-stream-x not supported
    which is fine.

    Changing it to "contentType": "application/opcua+octet-stream" creates a different error.

    NotSupportedError: Invalid value according to DataSchema
        at InteractionOutput.value (...\opcua-test\node_modules\@node-wot\core\dist\interaction-output.js:129:19)
        at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
        at async ...\opcua-test\test.js:54:47 {
      value: {
        Value: { Type: 11, Body: 1500 },
        SourceTimestamp: 2025-06-24T15:00:32.167Z
      }
    }
    
  2. danielpeintner commented on Jun 24, 2025

    @danielpeintner
    MemberAuthor

    I think the problem is, that the node-opcua library we are using converts the data on the wire directly to a DataValue class by calling read(...).

    public async readResource(form: OPCUAForm): Promise<Content> {
    debug(`readResource: reading ${form}`);
    const content = await this._withSession(form, async (session) => {
    const nodeId = await this._resolveNodeId(form);
    const dataValue = await session.read({
    nodeId,
    attributeId: AttributeIds.Value,
    });

    Maybe it is possible to get the raw data, but I am not sure.
    Hence, I wonder whether a simplified fix is also reasonable. What do I mean by that, we remove the contentType for any OPC UA form so that no other ContentSerdes codec can kick in?

    @sebastiankb @egekorkan do you think that is okay?
    @erossignon do you have another proposal?

  3. danielpeintner commented on Jun 25, 2025

    @danielpeintner
    MemberAuthor

    In #1402 I show what I intend to do...

  4. egekorkan commented on Jun 25, 2025

    @egekorkan
    Member

    What do I mean by that, we remove the contentType for any OPC UA form so that no other ContentSerdes codec can kick in?

    The developer should not need to do that but if node-wot does it internally until a better solution is available, I would be ok with it.

  5. danielpeintner commented on Jun 25, 2025

    @danielpeintner
    MemberAuthor

    I agree. We should keep this issue open in any case until we find a better solution.

  6. danielpeintner commented on Jun 25, 2025

    @danielpeintner
    MemberAuthor

    The developer should not need to do that

    BTW, the developer doesn't need to do anything. We take care internally...

  7. erossignon commented on Sep 1, 2025

    @erossignon
    Contributor

    I'm on it

  8. danielpeintner commented on Oct 14, 2025

    @danielpeintner
    MemberAuthor

    @erossignon any updates you can share with us?

  9. erossignon commented on Oct 15, 2025

    @erossignon
    Contributor

    @danielpeintner here you go , thank you for your patience.

  10. danielpeintner commented on Sep 14, 2026

    @danielpeintner
    MemberAuthor

    @erossignon do you plan to work on the content type issues?

  11. erossignon commented on Sep 14, 2026

    @erossignon
    Contributor

    Yes this is the next big item and is almost done on my side...

    Actually waiting for the pending PRs to be merged on master , as my work relies on them...

  12. erossignon commented on Sep 21, 2026

    @erossignon
    Contributor

    @danielpeintner @sebastiankb @egekorkan @relu91 the proposal for this issue. #1449 is closed; this replaces it.

    Measured on master today, reading a Double over OPC UA:

    • no contentType: works.
    • application/octet-stream: fails with dataType.toLowerCase is not a function, wherever type is declared. Core's generic octet-stream codec is decoding OPC UA content.
    • application/opcua+json: fails in core's schema check, with Invalid value according to DataSchema, or No schema type defined when the TD has no type.

    What the PR will do:

    Not in this PR: the application/opcua+json schema-check failures. They belong with #1243 and #1265.

    @danielpeintner this covers what #1402 was after, while keeping contentType. OK to close #1402 in favour of it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    binding-opcuaIssues related to opc ua protocol binding

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions