This tutorial demonstrates how to use Eclipse BaSyx to create and manage an Asset Administration Shell (AAS) in Java.
In this tutorial you will learn how to:
- Connect to a BaSyx environment
- Create an AAS
- Create a Submodel
- Add Submodel Elements
- Create Operations
- Update and read data
- Delete elements
- Remove the full AAS
Create AAS
↓
Create Submodel
↓
Add Elements
↓
Add Operations
↓
Interact / Update
↓
Invoke Operations
↓
Delete Elements
↓
Delete Submodel
↓
Delete AAS
Make sure the following services are running:
- AAS Repository
- Submodel Repository
- AAS Registry
- Submodel Registry
Default endpoints used:
String aasRegistryBaseUrl = "http://localhost:8082";
String aasRepositoryBaseUrl = "http://localhost:8081";
String submodelRegistryBaseUrl = "http://localhost:8083";
String submodelRepositoryBaseUrl = "http://localhost:8081";BaSyx provides Docker images for quick setup.
Before starting the implementation, make sure your BaSyx environment is running via Docker.
You can follow the official Quick Installation Guide here:
https://wiki.basyx.org/en/latest/content/introduction/quickstart.html
Configure BaSyx by editing the file:
basyx/aas-env.properties
Use the following configuration:
server.port=8081
basyx.backend=InMemory
basyx.environment=file:aas
basyx.cors.allowed-origins=*
basyx.cors.allowed-methods=GET,POST,PATCH,DELETE,PUT,OPTIONS,HEAD
spring.servlet.multipart.max-file-size=500MB
spring.servlet.multipart.max-request-size=500MBAdd the required BaSyx and AAS4J dependencies:
import org.eclipse.digitaltwin.aas4j.v3.model.*;
import org.eclipse.digitaltwin.aas4j.v3.model.impl.*;
import org.eclipse.digitaltwin.basyx.aasenvironment.client.ConnectedAasManager;
import org.eclipse.digitaltwin.basyx.aasservice.client.ConnectedAasService;
import org.eclipse.digitaltwin.basyx.operation.InvokableOperation;
import org.eclipse.digitaltwin.basyx.submodelservice.client.ConnectedSubmodelService;Edit your pom.xml to have this (or newer version) dependencies :
<dependencies>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasenvironment-client</artifactId>
<version>2.0.0-milestone-04</version>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasrepository-client</artifactId>
<version>2.0.0-milestone-08</version>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.submodelrepository-client</artifactId>
<version>2.0.0-milestone-08</version>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.aasservice-client</artifactId>
<version>2.0.0-milestone-08</version>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.basyx</groupId>
<artifactId>basyx.submodelservice-client</artifactId>
<version>2.0.0-milestone-08</version>
</dependency>
<dependency>
<groupId>org.eclipse.digitaltwin.aas4j</groupId>
<artifactId>aas4j-dataformat-aasx</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>ConnectedAasManager helloManager =
new ConnectedAasManager(
aasRegistryBaseUrl,
aasRepositoryBaseUrl,
submodelRegistryBaseUrl,
submodelRepositoryBaseUrl
);This manager allows you to:
- Create AAS
- Create Submodels
- Delete resources
- Access services
AssetAdministrationShell helloAAS =
new DefaultAssetAdministrationShell.Builder()
.id("http://example.com/aas/helloWorld")
.idShort("HelloWorldAAS")
.build();DefaultKey key = new DefaultKey.Builder()
.type(KeyTypes.SUBMODEL)
.value("http://example.com/aas/helloWorld/submodel")
.build();
DefaultReference ref = new DefaultReference.Builder()
.type(ReferenceTypes.EXTERNAL_REFERENCE)
.keys(key)
.build();Submodel helloSubmodel =
new DefaultSubmodel.Builder()
.id("http://example.com/aas/helloWorld/submodel")
.idShort("helloSubmodel")
.semanticId(ref)
.build();helloManager.createAas(helloAAS);
helloManager.createSubmodelInAas(
helloAAS.getId(),
helloSubmodel
);ConnectedAasService helloAASService =
helloManager.getAasService(helloAAS.getId());
ConnectedSubmodelService helloSMService =
helloManager.getSubmodelService(helloSubmodel.getId());SubmodelElementCollection helloCollection =
new DefaultSubmodelElementCollection.Builder()
.idShort("helloSMCollection")
.value(List.of())
.build();
helloSMService.createSubmodelElement(helloCollection);Operation helloOperation =
new InvokableOperation.Builder()
.idShort("pythagorasOperation")
.inputVariables(input_A)
.inputVariables(input_B)
.outputVariables(result_C)
.invokable(Main::pythagoras)
.build();SubmodelElementCollection helloSMC =
(SubmodelElementCollection)
helloSMService.getSubmodelElement("helloSMCollection");
helloSMC.getValue().add(
new DefaultProperty.Builder()
.idShort("helloProperty")
.valueType(DataTypeDefXsd.STRING)
.value("h3ll0World!")
.build()
);
helloSMC.getValue().add(helloOperation);
helloSMService.updateSubmodelElement(
"helloSMCollection",
helloSMC
);The operation calculates:
C = sqrt(A² + B²)
private static OperationVariable[] pythagoras(OperationVariable[] inputs) {
Property A = (Property) inputs[0].getValue();
Property B = (Property) inputs[1].getValue();
Integer iA = Integer.valueOf(A.getValue());
Integer iB = Integer.valueOf(B.getValue());
Integer C_out = (int) Math.sqrt(iA*iA + iB*iB);
Property C = new DefaultProperty.Builder()
.idShort("C")
.value(String.valueOf(C_out))
.build();
return new OperationVariable[] {
new DefaultOperationVariable.Builder().value(C).build()
};
}helloSMService.deleteSubmodelElement(
"helloSMCollection.helloProperty"
);helloManager.deleteSubmodelOfAas(
helloAAS.getId(),
helloSubmodel.getId()
);helloManager.deleteAas(
helloAAS.getId()
);