FraunhoferIOSB / FAAAST-Service

FA³ST - Fraunhofer Advanced Asset Administration Shell Tools (for Digital Twins)
Other
56 stars 11 forks source link

OpcUaAssetConnection value stays empty #328

Closed DavidWeissIFM closed 1 year ago

DavidWeissIFM commented 1 year ago

Describe the bug I try to connect a UPC UA value (Name of a Sensor) with the AAS, but the value of the AAS stays empty. There is no error or anything else in the logs.

To Reproduce

Configurations:

Configuration ```json { "core": { "requestHandlerThreadPoolSize": 2 }, "endpoints": [{ "@class": "de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.HttpEndpoint", "port": 8080 }], "persistence": { "@class": "de.fraunhofer.iosb.ilt.faaast.service.persistence.memory.PersistenceInMemory", "initialModel": "./examples/emptyAAS.json", "decoupleEnvironment": true }, "messageBus": { "@class": "de.fraunhofer.iosb.ilt.faaast.service.messagebus.internal.MessageBusInternal" }, "assetConnection": { "@class": "de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.OpcUaAssetConnection", "host": "opc.tcp://localhost:4840/OPCUA/moneo", "username": "fc6d4136-825c-490b-a2e5-a30677cc37e5", "password": "4uZXAaNBDTBfU5ROBGvg738sxbG2NAfwgRw5ucHzaJAb", "valueProviders": {}, "subscriptionProviders": { "(Submodel)[IRI]AL1350/192.168.178.250/80/X02/O5D150/Distance,(Property)[ID_SHORT]name": { "nodeId": "ns=2;s=500f025c-8a01-4ae2-bea9-65284c8fe6c3.Device.Name" } }, "operationProviders": {} } } ```
AAS ```json { "assetAdministrationShells": [ { "assetInformation": { "assetKind": "Instance", "globalAssetId": { "keys": [ { "idType": "Iri", "type": "Asset", "value": "localhost/faaast" } ] } }, "submodels": { "keys": [ { "type": "Submodel", "value": "AL1350/192.168.178.250/80/X02/O5D150/Distance", "idType": "Iri" } ] }, "identification": { "idType": "Iri", "id": "localhost/faaast" }, "idShort": "IOLinkMasterAAS", "modelType": { "name": "AssetAdministrationShell" } } ], "assets": [ { "identification": { "idType": "Iri", "id": "localhost/faaast" }, "idShort": "IOLinkMaster", "modelType": { "name": "Asset" }, "kind": "Instance" } ], "submodels": [ { "semanticId": { "keys": [ { "idType": "Iri", "type": "GlobalReference", "value": "AL1350/192.168.178.250/80/X02/O5D150/Distance" } ] }, "identification": { "idType": "Iri", "id": "AL1350/192.168.178.250/80/X02/O5D150/Distance" }, "idShort": "Distance", "modelType": { "name": "Submodel" }, "kind": "Instance", "submodelElements": [ { "value": "", "semanticId": { "keys": [ { "idType": "Iri", "type": "GlobalReference", "value": "name" } ] }, "idShort": "name", "category": "Variable", "modelType": { "name": "Property" }, "valueType": "String", "kind": "Instance", "descriptions": [ { "language": "en", "text": "" } ] } ] } ], "conceptDescriptions": [{ "modelType": { "name": "ConceptDescription" }, "administration": { "revision": "0", "version": "0.9" }, "identification": { "idType": "Iri", "id": "https://acplt.org/Test_ConceptDescription" }, "idShort": "TestConceptDescription", "isCaseOf": [ { "keys": [ { "idType": "Iri", "type": "GlobalReference", "value": "http://acplt.org/DataSpecifications/ConceptDescriptions/TestConceptDescription" } ] } ], "description": [ { "language": "en-us", "text": "An example concept description for the test application" }, { "language": "de", "text": "Ein Beispiel-ConceptDescription für eine Test-Anwendung" } ] } ] } ```
UaExpert ![image](https://user-images.githubusercontent.com/90178153/214019925-16a491ca-7306-488f-a362-65ab414313f4.png)

Results:

http://localhost:8080/submodels/QUwxMzUwLzE5Mi4xNjguMTc4LjI1MC84MC9YMDIvTzVEMTUwL0Rpc3RhbmNl/submodel/submodel-elements/name ```json // 20230123114205 // http://localhost:8080/submodels/QUwxMzUwLzE5Mi4xNjguMTc4LjI1MC84MC9YMDIvTzVEMTUwL0Rpc3RhbmNl/submodel/submodel-elements/name { "modelType": { "name": "Property" }, "kind": "Instance", "semanticId": { "keys": [ { "idType": "Iri", "type": "GlobalReference", "value": "name" } ] }, "value": "", "valueType": "String", "category": "Variable", "idShort": "name" } ```
http://localhost:8080/shells/bG9jYWxob3N0L2ZhYWFzdA==/aas/ ```json // 20230123114312 // http://localhost:8080/shells/bG9jYWxob3N0L2ZhYWFzdA==/aas/ { "modelType": { "name": "AssetAdministrationShell" }, "assetInformation": { "assetKind": "Instance", "globalAssetId": { "keys": [ { "idType": "Iri", "type": "Asset", "value": "localhost/faaast" } ] } }, "submodels": [ { "keys": [ { "idType": "Iri", "type": "Submodel", "value": "AL1350/192.168.178.250/80/X02/O5D150/Distance" } ] } ], "identification": { "idType": "Iri", "id": "localhost/faaast" }, "idShort": "IOLinkMasterAAS" } ```
http://localhost:8080/shells/bG9jYWxob3N0L2ZhYWFzdA==/aas/submodels ```json // 20230123114406 // http://localhost:8080/shells/bG9jYWxob3N0L2ZhYWFzdA==/aas/submodels [ { "keys": [ { "idType": "Iri", "type": "Submodel", "value": "AL1350/192.168.178.250/80/X02/O5D150/Distance" } ] } ] ```
http://localhost:8080/shells/bG9jYWxob3N0L2ZhYWFzdA==/aas/submodels/QUwxMzUwLzE5Mi4xNjguMTc4LjI1MC84MC9YMDIvTzVEMTUwL0Rpc3RhbmNl/submodel ```json // 20230123114436 // http://localhost:8080/shells/bG9jYWxob3N0L2ZhYWFzdA==/aas/submodels/QUwxMzUwLzE5Mi4xNjguMTc4LjI1MC84MC9YMDIvTzVEMTUwL0Rpc3RhbmNl/submodel { "modelType": { "name": "Submodel" }, "kind": "Instance", "semanticId": { "keys": [ { "idType": "Iri", "type": "GlobalReference", "value": "AL1350/192.168.178.250/80/X02/O5D150/Distance" } ] }, "identification": { "idType": "Iri", "id": "AL1350/192.168.178.250/80/X02/O5D150/Distance" }, "idShort": "Distance", "submodelElements": [ { "modelType": { "name": "Property" }, "kind": "Instance", "semanticId": { "keys": [ { "idType": "Iri", "type": "GlobalReference", "value": "name" } ] }, "value": "", "valueType": "String", "category": "Variable", "idShort": "name" } ] } ```

Expected behavior Name of the Sensor in value.

Output Value stays empty ("")

tbischoff2 commented 1 year ago

It seems that the AssetConnection is not initialized in your example. Please use array notation for the AssetConnection in the Configuration: "assetConnections": [ { "@class": "de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.OpcUaAssetConnection", "host": "opc.tcp://ILT752:48010", "valueProviders": {}, "subscriptionProviders": { "(Submodel)[IRI]AL1350/192.168.178.250/80/X02/O5D150/Distance,(Property)[ID_SHORT]name": { "nodeId": "ns=2;s=Demo.Static.Scalar.String" } }, "operationProviders": {} } ] Additional remark to the model: In my tests it was necessary to use lower case letters for the ValueType of the property: "string" instead of "String".

DavidWeissIFM commented 1 year ago

I have change the configuration of the AssetConnection it to to an Array.

Configuration ```json { "core": { "requestHandlerThreadPoolSize": 2 }, "endpoints": [ { "@class": "de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.HttpEndpoint", "port": 8080 } ], "persistence": { "@class": "de.fraunhofer.iosb.ilt.faaast.service.persistence.memory.PersistenceInMemory", "initialModel": "./examples/emptyAAS.json", "decoupleEnvironment": true }, "messageBus": { "@class": "de.fraunhofer.iosb.ilt.faaast.service.messagebus.internal.MessageBusInternal" }, "assetConnections": [ { "@class": "de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.OpcUaAssetConnection", "host": "opc.tcp://localhost:4840", "username": "c09ef991-5610-432d-9991-849e7f3cb0f1", "password": "jmuFTgruQSIUUwoOVixSe2PCB1Th3GpK2YJFQRDNWNru", "valueProviders": {}, "subscriptionProviders": { "(Submodel)[IRI]AL1350/192.168.178.250/80/X02/O5D150/Distance,(Property)[ID_SHORT]name": { "nodeId": "ns=2;s=500f025c-8a01-4ae2-bea9-65284c8fe6c3.Device.Name" } }, "operationProviders": {} } ] } ```

But now i get an Exception:

Exception in thread "main" java.lang.RuntimeException: de.fraunhofer.iosb.ilt.faaast.service.exception.ConfigurationInitializationException: error opening OPC UA connection (endpoint: opc.tcp://localhost:4840)
    at Main.main
Caused by: de.fraunhofer.iosb.ilt.faaast.service.exception.ConfigurationInitializationException: error opening OPC UA connection (endpoint: opc.tcp://localhost:4840)
    at de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.OpcUaAssetConnection.initConnection(OpcUaAssetConnection.java:191)
    at de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.OpcUaAssetConnection.initConnection(OpcUaAssetConnection.java:62)
    at de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AbstractAssetConnection.init(AbstractAssetConnection.java:106)
    at de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AbstractAssetConnection.init(AbstractAssetConnection.java:41)
    at de.fraunhofer.iosb.ilt.faaast.service.config.Config.newInstance(Config.java:60)
    at de.fraunhofer.iosb.ilt.faaast.service.Service.init(Service.java:208)
    at de.fraunhofer.iosb.ilt.faaast.service.Service.<init>(Service.java:113)
    at Main.main(Main.java:24)
Caused by: UaException: status=Bad_ConfigurationError, message=no endpoint selected
    at org.eclipse.milo.opcua.sdk.client.OpcUaClient.lambda$create$3(OpcUaClient.java:217)
    at java.base/java.util.Optional.orElseThrow(Optional.java:403)
    at org.eclipse.milo.opcua.sdk.client.OpcUaClient.create(OpcUaClient.java:216)
    at de.fraunhofer.iosb.ilt.faaast.service.assetconnection.opcua.OpcUaAssetConnection.initConnection(OpcUaAssetConnection.java:160)
    ... 7 more
Disconnected from the target VM, address: '127.0.0.1:49801', transport: 'socket'

Process finished with exit code 1

It seems, it can't create an Endpoint at OpcUaAssetConnection.java#L162. The e.getSecurityPolicyUri() returns http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256 but with the .equals(SecurityPolicy.None.getUri()) (what return false, becouse None.getUri is http://opcfoundation.org/UA/SecurityPolicy#None) the OpcUaClient.create doesn't get a valid endpoint.

tbischoff2 commented 1 year ago

Does your OPC UA Server have an OPC UA Endpoint with SecurityPolicy None?

DavidWeissIFM commented 1 year ago

The UPC UA Server only offers 1 Endpoint with the SecurityPolicy Basic256Sha256 and cannot be changed.

tbischoff2 commented 1 year ago

The OPC UA AssetConnection currently only supports Security None. The support for other Security Policies is planned. We have to check, if we can bring this forward.

tbischoff2 commented 1 year ago

The OPC UA AssetConnection can now handle different Security Policies. In the config you must set the following Properties:

Using the securityBaseDir you must trust the certificate of the OPC UA Server, and you must trust the certificate of the Asset Connection in the OPC UA Server. You can find the documentation here