Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion .github/workflows/examples_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,23 @@ jobs:
run: docker compose -f examples/BaSyxSecured/docker-compose.yaml up -d

- name: Stop BaSyx Secured Example
run: docker compose -f examples/BaSyxSecured/docker-compose.yaml down
run: docker compose -f examples/BaSyxSecured/docker-compose.yaml down

test-basyx-node-red:
runs-on: ubuntu-latest
name: Test BaSyx Node-RED Example
steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'
cache: maven

- name: Start BaSyx Node-RED Example
run: docker compose -f examples/BaSyxNodeRED/docker-compose.yml up -d

- name: Stop BaSyx Node-RED Example
run: docker compose -f examples/BaSyxNodeRED/docker-compose.yml down
45 changes: 45 additions & 0 deletions examples/BaSyxNodeRED/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# BaSyx Node-RED Example

This example showcases the integration of BaSyx with Node-RED for seamless data flow and management in industrial IoT applications.
Here, an example MQTT client for an environmental sensor is used to send data via Node-RED to the BaSyx AAS Environment.

## How to run the BaSyx + Node-RED Example

1. Open a terminal in this folder
2. Run the following command to start the BaSyx containers:

```bash
docker-compose up -d
```

> To run the example containers, you need to have Docker installed on your device.

## View the working Example

To see the working example, open the [BaSyx AAS Web UI](http://localhost:3000) and navigate to the `SensorExampleAAS`. You can see the data coming from the MQTT client in the `SensorData` submodel.
To see updates in real-time, active the `Auto-Sync` feature in the AAS Web UI (see top right corner of the UI).

![BaSyx AAS Web UI](./docs/basyx-ui.png)

## Where to find the configuration

### Node-RED

You can visit the [Node-RED Editor](http://localhost:1880) to view and edit the flows.

> The preconfigured Node-RED flow can be found in the `nodered` folder. The flow is defined in the `flows.json` file.

![Node-RED Flow](./docs/nodered.png)

### MQTT Client

The configuration for the MQTT client can be found in the `mqtt-client` folder. It is a small Python script that publishes data to the MQTT broker.

### MQTT Broker

The MQTT brokers configuration can be found in the `mosquitto` folder. The configuration is defined in the `config/mosquitto.conf` file.

### BaSyx Components

The configuration for the BaSyx components can be found in the `basyx` folder.
The AAS used in this example is located in the `aas` folder.
Binary file not shown.
9 changes: 9 additions & 0 deletions examples/BaSyxNodeRED/basyx/aas-discovery.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
server.port=8081

spring.application.name=AAS Discovery Service
basyx.aasdiscoveryservice.name=aas-discovery-service

basyx.backend=InMemory

basyx.cors.allowed-origins=*
basyx.cors.allowed-methods=GET,POST,PATCH,DELETE,PUT,OPTIONS,HEAD
14 changes: 14 additions & 0 deletions examples/BaSyxNodeRED/basyx/aas-env.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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

basyx.aasrepository.feature.registryintegration=http://aas-registry:8080
basyx.submodelrepository.feature.registryintegration=http://sm-registry:8080
basyx.aasrepository.feature.discoveryintegration=http://aas-discovery:8081

basyx.externalurl=http://localhost:8081
4 changes: 4 additions & 0 deletions examples/BaSyxNodeRED/basyx/aas-registry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
basyx:
cors:
allowed-origins: '*'
allowed-methods: GET,POST,PATCH,DELETE,PUT,OPTIONS,HEAD
4 changes: 4 additions & 0 deletions examples/BaSyxNodeRED/basyx/sm-registry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
basyx:
cors:
allowed-origins: '*'
allowed-methods: GET,POST,PATCH,DELETE,PUT,OPTIONS,HEAD
100 changes: 100 additions & 0 deletions examples/BaSyxNodeRED/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
services:
# Node-RED
nodered:
build: ./nodered
container_name: nodered
ports:
- "1880:1880"
volumes:
- ./nodered:/data
depends_on:
aas-env:
condition: service_healthy
mosquitto:
condition: service_healthy
restart: unless-stopped

# MQTT Broker
mosquitto:
image: eclipse-mosquitto:2.0.15
container_name: mosquitto
ports:
- 1883:1883
volumes:
- ./mosquitto/config:/mosquitto/config
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", mosquitto_sub -p 1883 -t 'topic' -C 1 -E -i probe -W 3]
interval: 5s
retries: 3
start_period: 1s
timeout: 10s

# MQTT Client
mqtt-client:
build: ./mqtt-client
container_name: mqtt-client
depends_on:
- mosquitto
restart: unless-stopped

aas-env:
image: eclipsebasyx/aas-environment:2.0.0-SNAPSHOT
container_name: aas-env
volumes:
- ./basyx/aas-env.properties:/application/application.properties
- ./aas:/application/aas
ports:
- 8081:8081
restart: unless-stopped
depends_on:
aas-registry:
condition: service_healthy
sm-registry:
condition: service_healthy
aas-discovery:
condition: service_healthy

aas-registry:
image: eclipsebasyx/aas-registry-log-mem:2.0.0-SNAPSHOT
container_name: aas-registry
ports:
- 8082:8080
volumes:
- ./basyx/aas-registry.yml:/workspace/config/application.yml
restart: unless-stopped

sm-registry:
image: eclipsebasyx/submodel-registry-log-mem:2.0.0-SNAPSHOT
container_name: sm-registry
ports:
- 8083:8080
volumes:
- ./basyx/sm-registry.yml:/workspace/config/application.yml
restart: unless-stopped

aas-discovery:
image: eclipsebasyx/aas-discovery:2.0.0-SNAPSHOT
container_name: aas-discovery
ports:
- 8084:8081
volumes:
- ./basyx/aas-discovery.properties:/application/application.properties
restart: unless-stopped

aas-ui:
image: eclipsebasyx/aas-gui:SNAPSHOT
container_name: aas-ui
ports:
- "3000:3000"
environment:
AAS_DISCOVERY_PATH: "http://localhost:8084/lookup/shells"
AAS_REGISTRY_PATH: "http://localhost:8082/shell-descriptors"
SUBMODEL_REGISTRY_PATH: "http://localhost:8083/submodel-descriptors"
AAS_REPO_PATH: "http://localhost:8081/shells"
SUBMODEL_REPO_PATH: "http://localhost:8081/submodels"
CD_REPO_PATH: "http://localhost:8081/concept-descriptions"
restart: unless-stopped
depends_on:
aas-env:
condition: service_healthy
Binary file added examples/BaSyxNodeRED/docs/basyx-ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/BaSyxNodeRED/docs/nodered.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions examples/BaSyxNodeRED/mosquitto/config/mosquitto.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Default listener port for unencrypted connections (usually 1883)
listener 1883 0.0.0.0

# Path to the directory where persistence information is stored.
# Remove or comment out to disable persistence.
persistence true
persistence_location /mosquitto/data/

# Log settings
log_dest file /mosquitto/log/mosquitto.log
log_type all

# Connection settings
# Setting for maximum concurrent connections. -1 means unlimited.
max_connections -1

# Security settings
# Uncomment and set these for enabling username-password authentication.
#allow_anonymous false
#password_file /mosquitto/config/mosquitto_passwd

# Other settings like SSL/TLS, ACLs, etc., can also be configured as needed.
allow_anonymous true
8 changes: 8 additions & 0 deletions examples/BaSyxNodeRED/mqtt-client/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.8-slim
ARG HTTP_PROXY
ARG HTTPS_PROXY
RUN pip install paho-mqtt

COPY publisher.py /publisher.py

CMD ["python", "/publisher.py"]
47 changes: 47 additions & 0 deletions examples/BaSyxNodeRED/mqtt-client/publisher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import time
import random
import json
import paho.mqtt.client as mqtt

# MQTT settings
broker_address = "mosquitto"
port = 1883
base_topic = "EnvironmentalSensor/"

# Connect to MQTT Broker
client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, "Client")
client.connect(broker_address, port)

# Start the network loop in a separate thread
client.loop_start()

try:

while True:
# Generate different types of dynamic data
temperatureValue = random.uniform(0, 30)
humidityValue = random.uniform(0.0, 100.0)
airQualityValue = random.uniform(0.0, 1000.0)

# Create a dictionary with all values
data = {
"temperature": temperatureValue,
"humidity": humidityValue,
"airQuality": airQualityValue
}

# Convert the dictionary to a JSON string
json_data = json.dumps(data)

# Publish dynamic data to respective subtopics
client.publish(base_topic + "Temperature", temperatureValue)
client.publish(base_topic + "Humidity", humidityValue)
client.publish(base_topic + "AirQuality", airQualityValue)
client.publish(base_topic + "CombinedData", json_data)

# Wait for a short period before publishing the next set of values
time.sleep(1)
except KeyboardInterrupt:
# Stop the network loop if the script is interrupted
client.loop_stop()
client.disconnect()
6 changes: 6 additions & 0 deletions examples/BaSyxNodeRED/nodered/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
.config*
*.backup
package-lock.json
package.json
lib/
8 changes: 8 additions & 0 deletions examples/BaSyxNodeRED/nodered/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
.config*
*.backup
package-lock.json
package.json
lib/
flows_cred.json
.npm
5 changes: 5 additions & 0 deletions examples/BaSyxNodeRED/nodered/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nodered/node-red:4.1.0

# Copy flows and settings
COPY flows.json /data/flows.json
COPY settings.js /data/settings.js
Loading