Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for opc-twin module api direct method calls with input arguments (not requiring OPC Twin micro services) #1512

Closed
DidierDrogba2 opened this issue Dec 22, 2021 · 7 comments
Assignees
Labels
feature request New feature or request

Comments

@DidierDrogba2
Copy link

Hi, want to call some opcua-methods with the opc-twin restapi. The restapi and the authentication worked just fine for me, but every time I want to call a method with some arguments I get the same error. Methods which dont take any parameters work fine.

Example Request body (using postman):
Screenshot 2021-12-22 161134

Example Response:
Screenshot 2021-12-22 161331

Also if run the method with no argument the request will get to the server (and will fail there):
Screenshot 2021-12-22 161645

The api documentation says that the parameter arguments exprects an < MethodCallArgumentApiModel > array which contains the
keys dataType and value. All of these are optional.

@DidierDrogba2
Copy link
Author

  • this is the post url:
    https://{{OPC-SERVICEURL}}/twin/v2/call/myDeviceId?nodeId=urn%3Afreeopcua%3Apython%3Aserver%23i%3D2031

@cristipogacean
Copy link
Contributor

@DidierDrogba2, can you check if calling this method works when using the engineering tool UI?

Everything you did seem to be fine. So maybe you want to double check if the nodesId (method&object) are correct and the method's attributes have the datatypes, order and count as expected by the server. If you can confirm that, we will have to validate if indeed this is a regression.

@DidierDrogba2
Copy link
Author

I just checked and i definitely used the correct nodeId and attributes. But I got this issue with every method of my opc server(if the method gets one or more input arguments). I changed the method itself temporary so that no input arguments are required. You can see the response below (The same node I used before):

Screenshot from 2021-12-22 22-22-48

The engineering tool works too.

@hansgschossmann hansgschossmann added need more information Needs more information help wanted and removed need more information Needs more information labels Jan 11, 2022
@hansgschossmann hansgschossmann added bug Something isn't working and removed help wanted labels Jun 21, 2022
@NoTuxNoBux
Copy link

NoTuxNoBux commented Sep 2, 2022

In case it is relevant: I'm also working on invoking methods on an OPC UA server using OPC Twin, and I got it to work both with a command without arguments, and one with a simple string argument.

However, I'm going through the TwinModuleClient that's part of the NuGet packages, not directly to the API. I then use client.NodeMethodCallAsync with the appropriate EndpointApiModel (with OPC UA TCP URI), and the MethodCallRequestApiModel which looks something like this:

ImmutableList<JsonElement> argumentList = ...;

new MethodCallRequestApiModel()
{
    MethodId = "ns=1;s=setLanguageMethod",
    ObjectId = "ns=1;s=Foo:Bar:System:Language",
    Arguments = argumentList.Select(x => new MethodCallArgumentApiModel() { DataType = "String", Value = jsonElementToVariantValueConverter.Convert(x) }).ToList(),
}

(The JsonElementToVariantValueConverter is a simple class that just checks ValueKind and does (VariantValue)element.GetString() if it is a string.)

If I serialize the above object, I get something like this:

{
    "MethodId": "ns=1;s=setLanguageMethod",
    "ObjectId": "ns=1;s=Foo:Bar:System:Language",
    "Arguments": [
        {
            "Value": {
                "PropertyNames": [],
                "Value": "english",
                "Values": [],
                "Count": 0,
                "IsListOfValues": false,
                "IsArray": false,
                "IsObject": false,
                "IsDecimal": false,
                "IsInteger": false,
                "IsInt64": false,
                "IsUInt64": false,
                "IsDouble": false,
                "IsFloat": false,
                "IsTimeSpan": false,
                "IsDateTime": false,
                "IsGuid": false,
                "IsBoolean": false,
                "IsString": true,
                "IsBytes": false
            },
            "DataType": "String"
        }
    ],
    "MethodBrowsePath": null,
    "ObjectBrowsePath": null,
    "Header": null
}

This probably happens because the Arguments property accepts VariantValues, but it might also be the case that this is resolved internally afterwards in the API client.

Not sure if that helps in any way, but I hope it does.

@hansgschossmann
Copy link
Contributor

@NoTuxNoBux are you using the OPC Twin module standalone? Usage in context of Industrial-IoT is only tested as part of the end-to-end use via the REST API as pointed out in our documentation:
OPC Twin: The OPC Twin module enables connection from the cloud to OPC UA server systems on the factory network. OPC Twin provides access to OPC UA server systems through REST APIs exposed by the Industrial-IoT cloud microservices. In contrast to OPC Publisher, in OPC Twin, working in standalone mode (module only) isn't supported. The OPC Twin module must work in combination with the Industrial-IoT cloud microservices.

We have no plans to enable use of Industrial-IoT OPC Twin standalone functionality, but will offer a subset of its functionality as part of another product.

@NoTuxNoBux
Copy link

@NoTuxNoBux are you using the OPC Twin module standalone? Usage in context of Industrial-IoT is only tested as part of the end-to-end use via the REST API as pointed out in our documentation:

Partially, yes, mainly the API client library without the microservice, and I seem to have completely missed that information, thanks.

Right now since we have an Azure Function that needs to talk to the Twin, and the additional microservice seemed an unnecessary cost as it wraps the API client we could instantiate ourselves in a couple of lines, but we can still rather easily insert it as intermediary if it becomes problematic later on.

@marcschier marcschier added feature request New feature or request and removed bug Something isn't working labels Nov 8, 2022
@marcschier marcschier self-assigned this Nov 8, 2022
@marcschier marcschier changed the title opc-twin api method call with input arguments is not working Support for opc-twin module api direct method calls with input arguments (not requiring OPC Twin micro services) Jan 16, 2023
@marcschier marcschier added this to the Future milestone Jan 17, 2023
@marcschier marcschier modified the milestones: Future, 2.9.0 Preview 1 Feb 14, 2023
marcschier added a commit that referenced this issue Apr 28, 2023
# Changes introduced:

- New Namespaces for all projects and simplified code structure. There are now 2 SDK projects, one for the OPC Publisher module, and another for the optional cloud WebAPI companion service. 
- Ability to run platform (modules, services) "standalone" on the edge #464
  - [OPC Discovery] has been included into the OPC Publisher module, the container name must be updated to refer to OPC Publisher. 
  - [OPC Discovery] A new synchronous FindServer API has been added to allow discovery by discovery url through a single API call.
  - [OPC Twin] has been included into the OPC Publisher module, the container name must be updated to refer to OPC Publisher. 
  - [OPC Twin] we removed the Activate and Deactivate calls. 
  - [OPC Twin] OPC TWIN Method call #996
  - Support for opc-twin module api direct method calls with input arguments (not requiring OPC Twin micro services) #1512
- Support for a new TestConnection API to test a connection to a server and receiving detailed error information back.
- [OPC Publisher] (breaking change) The publisher id in each message is now always the same value across all writer groups rather than previously where a random guid was used per writer group when a publisher id was not configured.
- [OPC Publisher] Several bug fixes for preview 1 (#1964)
  - [OPC Publisher] DatasetMessage SequenceNumber is now correctly incremented (preview) (#1961)
- [OPC Publisher] Enabling using DisplayNames defined for the event fields in pn.json as keys in the payload of dataset messages (#1963)
- [OPC Publisher] Request opc server's nodes information #1960
- [OPC Publisher] dotnet publish can be used to build a docker container for OPC Publisher #1949
- [OPC Publisher] Metrics output and log output showing number of sessions currently active (related to #1923)
- [OPC Publisher] Added new OPC UA stack which addressess #1937 and latest CVE's
- [All micro services] Have been combined into a single WebAPI with the same resource paths as the 2.8 AKS deployment and all-in-one service. 
  - [OPC Registry service] Supervisor, Discoverer entities have been removed, but the API has been layered on top of the publisher entity for backwards compatibiltiy. Do not use these API's anymore. 
  - [OPC Registry service] A new RegisterEndpoint API has been added that calls the new sync FindServer API and adds the result into the registry in one call.
  - [Telemetry processor] The telemetry and onboarding processors have been integrated into the WebAPI, but only forwards to SignalR. The secondary event hub has been removed. If you need to post process telemetry you must read telemetry data directly from IoT Hub.
- Document the diagnostics output and troubleshooting guide #1952

# Stats:

*  Consolidated down to 1 edge module and 1 optional cloud companion web app.  
*  Maintained 99% of API and even added new capabilities/functionality such as Event and MQTT broker support.
*  Reduced LOC for shipped binaries by 53% from to 641844 in 2.8.6 to 297144 in 2.9.0 preview 2
*  Increased Test coverage (blocks) by around 50% from 51.34% to 76.36%
@marcschier
Copy link
Collaborator

Release 2.9.0 preview 2 of OPC Publisher was just released. It supports the OPC Twin API which can be invoked without cloud services. Documentation will be provided soon.

Regarding variant value: The variant value is just an object (it is similar to JObject or JDocument, but supports msgpack also), it can be any valid json in the payload in and out that conforms to the encoding rules for JSON in Part 6 of the OPC UA spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants