Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "BaSyx / Introductory Examples / Java / Step 6"

(Created page with "= Step 6: Creating an example application = In the last example, the AAS was set up and registered. Its contents can be explored through the HTTP-Rest API. In the browser,...")
 
m (Adds line numbers)
 
(One intermediate revision by one other user not shown)
Line 5: Line 5:
 
  In the browser, look at the various endpoints to see what is returned:
 
  In the browser, look at the various endpoints to see what is returned:
 
  To access the AAS: http://localhost:4000/handson/oven/aas/
 
  To access the AAS: http://localhost:4000/handson/oven/aas/
  To access the oven sub model: http://localhost:4000/handson/oven/aas/submodels/oven/
+
  To access the oven Submodel: http://localhost:4000/handson/oven/aas/submodels/oven/
+
  
 
The registry also has a HTTP-REST interface. So, it is possible to directly query it:
 
The registry also has a HTTP-REST interface. So, it is possible to directly query it:
 
  Show all AAS: http://localhost:4000/handson/registry/api/v1/registry/
 
  Show all AAS: http://localhost:4000/handson/registry/api/v1/registry/
 
  Show my AAS: http://localhost:4000/handson/registry/api/v1/registry/urn:org.eclipse.basyx:OvenAAS
 
  Show my AAS: http://localhost:4000/handson/registry/api/v1/registry/urn:org.eclipse.basyx:OvenAAS
Note: the "#" character in the URN s encoded as "%23"
 
  
  
Line 19: Line 17:
 
First, to access the remote registry, a ''AASRegistryProxy'' is created. Next, a ''ConnectedAssetAdministrationShellManager'' is created using this registry proxy. This will be used to access the Asset Administration Shell. The AAS is retrieved through its unique URN from the connection manager. The connector manager gets a parameter that defines how, i.e. using which protocol, the AAS server and registry can be reached. This example uses http/REST interfaces, and therefore, the HTTPConnectorFactory will be used. The ConnectedAssetAdministrationShell will be the proxy to the remote AAS.
 
First, to access the remote registry, a ''AASRegistryProxy'' is created. Next, a ''ConnectedAssetAdministrationShellManager'' is created using this registry proxy. This will be used to access the Asset Administration Shell. The AAS is retrieved through its unique URN from the connection manager. The connector manager gets a parameter that defines how, i.e. using which protocol, the AAS server and registry can be reached. This example uses http/REST interfaces, and therefore, the HTTPConnectorFactory will be used. The ConnectedAssetAdministrationShell will be the proxy to the remote AAS.
  
<syntaxhighlight lang="java" style="margin-left: 4em">
+
<syntaxhighlight lang="java" style="margin-left: 4em" line>
 
// Return a AASHTTPRegistryProxy for the registry on localhost at port 4000
 
// Return a AASHTTPRegistryProxy for the registry on localhost at port 4000
 
IAASRegistry registry = new AASRegistryProxy("http://localhost:4000/handson/registry");
 
IAASRegistry registry = new AASRegistryProxy("http://localhost:4000/handson/registry");
Line 33: Line 31:
  
  
Last, the provided interfaces and classes are used for submodel, property and operation retrieval. The following code queries a list of sub models.
+
Last, the provided interfaces and classes are used for Submodel, property and operation retrieval. The following code queries a list of Submodels.
  
<syntaxhighlight lang="java" style="margin-left: 4em">
+
<syntaxhighlight lang="java" style="margin-left: 4em" line>
 
// Connect to the AAS and read the current temperature
 
// Connect to the AAS and read the current temperature
 
// Either Create a connected property using the connected facades
 
// Either Create a connected property using the connected facades
Line 44: Line 42:
 
Finally, the temperature value is retrieved and based on its unit either converted to Celsius or printed directly.
 
Finally, the temperature value is retrieved and based on its unit either converted to Celsius or printed directly.
  
<syntaxhighlight lang="java" style="margin-left: 4em">
+
<syntaxhighlight lang="java" style="margin-left: 4em" line>
 
ISubmodel connectedSensorSM = submodels.get("Sensor");
 
ISubmodel connectedSensorSM = submodels.get("Sensor");
 
Map<String, IProperty> properties = connectedSensorSM.getProperties();
 
Map<String, IProperty> properties = connectedSensorSM.getProperties();
Line 52: Line 50:
  
  
Now, depending on the type of the application, the information can be used for whatever is necessary. Applications may access multiple AAS and sub models, and therefore collect and aggregate data from different sources.
+
Now, depending on the type of the application, the information can be used for whatever is necessary. Applications may access multiple AAS and Submodels, and therefore collect and aggregate data from different sources.

Latest revision as of 08:18, 23 August 2021

Step 6: Creating an example application

In the last example, the AAS was set up and registered. Its contents can be explored through the HTTP-Rest API.

In the browser, look at the various endpoints to see what is returned:
To access the AAS: http://localhost:4000/handson/oven/aas/
To access the oven Submodel: http://localhost:4000/handson/oven/aas/submodels/oven/

The registry also has a HTTP-REST interface. So, it is possible to directly query it:

Show all AAS: http://localhost:4000/handson/registry/api/v1/registry/
Show my AAS: http://localhost:4000/handson/registry/api/v1/registry/urn:org.eclipse.basyx:OvenAAS


However, in a real application this exploration and data retrieval should not happen through manual calls but instead through interfaces encapsulating the access. The following example shows how to use the provided interfaces and how to alternatively access the AAS directly through the VAB.


First, to access the remote registry, a AASRegistryProxy is created. Next, a ConnectedAssetAdministrationShellManager is created using this registry proxy. This will be used to access the Asset Administration Shell. The AAS is retrieved through its unique URN from the connection manager. The connector manager gets a parameter that defines how, i.e. using which protocol, the AAS server and registry can be reached. This example uses http/REST interfaces, and therefore, the HTTPConnectorFactory will be used. The ConnectedAssetAdministrationShell will be the proxy to the remote AAS.

  1. 	// Return a AASHTTPRegistryProxy for the registry on localhost at port 4000
  2. 	IAASRegistry registry = new AASRegistryProxy("http://localhost:4000/handson/registry");
  3.  
  4. 	// Create a ConnectedAssetAdministrationShell using a ConnectedAssetAdministrationShellManager
  5. 	IConnectorFactory connectorFactory = new HTTPConnectorFactory();
  6. 	ConnectedAssetAdministrationShellManager manager = new ConnectedAssetAdministrationShellManager(registry, connectorFactory);
  7.  
  8. 	// The ID of the oven AAS
  9. 	ModelUrn aasURN = new ModelUrn("urn:org.eclipse.basyx:OvenAAS");
  10. 	ConnectedAssetAdministrationShell connectedAAS = manager.retrieveAAS(aasURN);


Last, the provided interfaces and classes are used for Submodel, property and operation retrieval. The following code queries a list of Submodels.

  1. 	// Connect to the AAS and read the current temperature
  2. 	// Either Create a connected property using the connected facades
  3. 	Map<String, ISubmodel> submodels = connectedAAS.getSubmodels();


Finally, the temperature value is retrieved and based on its unit either converted to Celsius or printed directly.

  1. 	ISubmodel connectedSensorSM = submodels.get("Sensor");
  2. 	Map<String, IProperty> properties = connectedSensorSM.getProperties();
  3. 	IProperty temperatureProperty = properties.get("currentTemperature");
  4. 	double temperature = (double) temperatureProperty.getValue();


Now, depending on the type of the application, the information can be used for whatever is necessary. Applications may access multiple AAS and Submodels, and therefore collect and aggregate data from different sources.

Back to the top