diff --git a/streampipes-extensions/pom.xml b/streampipes-extensions/pom.xml
index b14c2471b2..0e89e64f6c 100644
--- a/streampipes-extensions/pom.xml
+++ b/streampipes-extensions/pom.xml
@@ -63,6 +63,7 @@
streampipes-sinks-databases-jvm
streampipes-sinks-internal-jvm
streampipes-sinks-notifications-jvm
+ streampipes-connectors-plc
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/pom.xml b/streampipes-extensions/streampipes-connect-adapters-iiot/pom.xml
index 39d51cf868..8d5bff6371 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/pom.xml
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/pom.xml
@@ -59,6 +59,11 @@
streampipes-connectors-opcua
0.93.0-SNAPSHOT
+
+ org.apache.streampipes
+ streampipes-connectors-plc
+ 0.93.0-SNAPSHOT
+
org.apache.streampipes
streampipes-connectors-rocketmq
@@ -138,30 +143,6 @@
org.apache.commons
commons-text
-
- org.apache.plc4x
- plc4j-api
-
-
- org.apache.plc4x
- plc4j-connection-pool
-
-
- org.apache.plc4x
- plc4j-driver-s7
- runtime
-
-
- com.fasterxml.woodstox
- woodstox-core
-
-
-
-
- org.apache.plc4x
- plc4j-driver-modbus
- runtime
-
org.bouncycastle
bcprov-jdk15on
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/ConnectAdapterIiotInit.java b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/ConnectAdapterIiotInit.java
index fa651ea92d..dd48df49be 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/ConnectAdapterIiotInit.java
+++ b/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/ConnectAdapterIiotInit.java
@@ -19,8 +19,6 @@
package org.apache.streampipes.connect.iiot;
import org.apache.streampipes.connect.iiot.adapters.iolink.IfmAlMqttAdapter;
-import org.apache.streampipes.connect.iiot.adapters.plc4x.modbus.Plc4xModbusAdapter;
-import org.apache.streampipes.connect.iiot.adapters.plc4x.s7.Plc4xS7Adapter;
import org.apache.streampipes.connect.iiot.adapters.ros.RosBridgeAdapter;
import org.apache.streampipes.connect.iiot.adapters.simulator.machine.MachineDataSimulatorAdapter;
import org.apache.streampipes.connect.iiot.protocol.stream.FileReplayAdapter;
@@ -31,6 +29,9 @@
import org.apache.streampipes.extensions.connectors.nats.adapter.NatsProtocol;
import org.apache.streampipes.extensions.connectors.opcua.adapter.OpcUaAdapter;
import org.apache.streampipes.extensions.connectors.opcua.migration.OpcUaAdapterMigrationV1;
+import org.apache.streampipes.extensions.connectors.plc.adapter.migration.Plc4xS7AdapterMigrationV1;
+import org.apache.streampipes.extensions.connectors.plc.adapter.modbus.Plc4xModbusAdapter;
+import org.apache.streampipes.extensions.connectors.plc.adapter.s7.Plc4xS7Adapter;
import org.apache.streampipes.extensions.connectors.pulsar.adapter.PulsarProtocol;
import org.apache.streampipes.extensions.connectors.rocketmq.adapter.RocketMQProtocol;
import org.apache.streampipes.extensions.connectors.tubemq.adapter.TubeMQProtocol;
@@ -65,7 +66,10 @@ public SpServiceDefinition provideServiceDefinition() {
.registerAdapter(new HttpServerProtocol())
.registerAdapter(new TubeMQProtocol())
- .registerMigrators(new OpcUaAdapterMigrationV1())
+ .registerMigrators(
+ new OpcUaAdapterMigrationV1(),
+ new Plc4xS7AdapterMigrationV1()
+ )
.build();
}
}
diff --git a/streampipes-extensions/streampipes-connectors-plc/pom.xml b/streampipes-extensions/streampipes-connectors-plc/pom.xml
new file mode 100644
index 0000000000..e41573b065
--- /dev/null
+++ b/streampipes-extensions/streampipes-connectors-plc/pom.xml
@@ -0,0 +1,81 @@
+
+
+
+
+ 4.0.0
+
+ org.apache.streampipes
+ streampipes-extensions
+ 0.93.0-SNAPSHOT
+
+
+ streampipes-connectors-plc
+
+
+
+ org.apache.streampipes
+ streampipes-extensions-api
+ 0.93.0-SNAPSHOT
+
+
+ org.apache.streampipes
+ streampipes-extensions-management
+ 0.93.0-SNAPSHOT
+
+
+ org.apache.streampipes
+ streampipes-sdk
+ 0.93.0-SNAPSHOT
+
+
+
+ org.apache.plc4x
+ plc4j-api
+
+
+ org.apache.plc4x
+ plc4j-connection-pool
+
+
+ org.apache.plc4x
+ plc4j-driver-s7
+ runtime
+
+
+ com.fasterxml.woodstox
+ woodstox-core
+
+
+
+
+ org.apache.plc4x
+ plc4j-driver-modbus
+ runtime
+
+
+
+ junit
+ junit
+ test
+
+
+
+
diff --git a/streampipes-extensions/streampipes-connectors-plc/src/main/java/org/apache/streampipes/extensions/connectors/plc/adapter/migration/Plc4xS7AdapterMigrationV1.java b/streampipes-extensions/streampipes-connectors-plc/src/main/java/org/apache/streampipes/extensions/connectors/plc/adapter/migration/Plc4xS7AdapterMigrationV1.java
new file mode 100644
index 0000000000..c88d3f9a5b
--- /dev/null
+++ b/streampipes-extensions/streampipes-connectors-plc/src/main/java/org/apache/streampipes/extensions/connectors/plc/adapter/migration/Plc4xS7AdapterMigrationV1.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.extensions.connectors.plc.adapter.migration;
+
+import org.apache.streampipes.extensions.api.extractor.IStaticPropertyExtractor;
+import org.apache.streampipes.extensions.api.migration.IAdapterMigrator;
+import org.apache.streampipes.model.connect.adapter.AdapterDescription;
+import org.apache.streampipes.model.extensions.svcdiscovery.SpServiceTagPrefix;
+import org.apache.streampipes.model.migration.MigrationResult;
+import org.apache.streampipes.model.migration.ModelMigratorConfig;
+import org.apache.streampipes.model.staticproperty.CollectionStaticProperty;
+import org.apache.streampipes.model.staticproperty.StaticProperty;
+import org.apache.streampipes.sdk.StaticProperties;
+import org.apache.streampipes.sdk.helpers.Alternatives;
+import org.apache.streampipes.sdk.helpers.CodeLanguage;
+import org.apache.streampipes.sdk.helpers.Labels;
+
+import java.util.List;
+
+import static org.apache.streampipes.extensions.connectors.plc.adapter.s7.Plc4xS7Adapter.CODE_TEMPLATE;
+import static org.apache.streampipes.extensions.connectors.plc.adapter.s7.Plc4xS7Adapter.PLC_CODE_BLOCK;
+import static org.apache.streampipes.extensions.connectors.plc.adapter.s7.Plc4xS7Adapter.PLC_NODES;
+import static org.apache.streampipes.extensions.connectors.plc.adapter.s7.Plc4xS7Adapter.PLC_NODE_INPUT_ALTERNATIVES;
+import static org.apache.streampipes.extensions.connectors.plc.adapter.s7.Plc4xS7Adapter.PLC_NODE_INPUT_CODE_BLOCK_ALTIVE;
+import static org.apache.streampipes.extensions.connectors.plc.adapter.s7.Plc4xS7Adapter.PLC_NODE_INPUT_COLLECTION_ALTERNATIVE;
+
+public class Plc4xS7AdapterMigrationV1 implements IAdapterMigrator {
+ @Override
+ public ModelMigratorConfig config() {
+ return new ModelMigratorConfig(
+ "org.apache.streampipes.connect.iiot.adapters.plc4x.s7",
+ SpServiceTagPrefix.ADAPTER,
+ 0,
+ 1
+ );
+ }
+
+ @Override
+ public MigrationResult migrate(AdapterDescription element,
+ IStaticPropertyExtractor extractor) throws RuntimeException {
+ var newConfigs = new java.util.ArrayList<>(element.getConfig().stream().map(config -> {
+ if (isCollectionConfig(config)) {
+ return modifyCollection((CollectionStaticProperty) config);
+ } else {
+ return config;
+ }
+ }).toList());
+
+ newConfigs.removeIf(c -> c.getInternalName().equals(PLC_NODES));
+ element.setConfig(newConfigs);
+
+ return MigrationResult.success(element);
+ }
+
+ private StaticProperty modifyCollection(CollectionStaticProperty collectionConfig) {
+
+ var alternatives = List.of(
+ Alternatives.from(Labels.withId(PLC_NODE_INPUT_COLLECTION_ALTERNATIVE),
+ collectionConfig,
+ true),
+ Alternatives.from(Labels.withId(PLC_NODE_INPUT_CODE_BLOCK_ALTIVE),
+ StaticProperties.codeStaticProperty(Labels.withId(PLC_CODE_BLOCK), CodeLanguage.None, CODE_TEMPLATE))
+ );
+
+ return StaticProperties.alternatives(Labels.withId(PLC_NODE_INPUT_ALTERNATIVES), alternatives);
+ }
+
+ private boolean isCollectionConfig(StaticProperty config) {
+ return config.getInternalName().equals(PLC_NODES);
+ }
+}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/modbus/ModbusConfigFile.java b/streampipes-extensions/streampipes-connectors-plc/src/main/java/org/apache/streampipes/extensions/connectors/plc/adapter/modbus/ModbusConfigFile.java
similarity index 95%
rename from streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/modbus/ModbusConfigFile.java
rename to streampipes-extensions/streampipes-connectors-plc/src/main/java/org/apache/streampipes/extensions/connectors/plc/adapter/modbus/ModbusConfigFile.java
index fbda391ecc..f6e3961126 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/modbus/ModbusConfigFile.java
+++ b/streampipes-extensions/streampipes-connectors-plc/src/main/java/org/apache/streampipes/extensions/connectors/plc/adapter/modbus/ModbusConfigFile.java
@@ -16,7 +16,7 @@
*
*/
-package org.apache.streampipes.connect.iiot.adapters.plc4x.modbus;
+package org.apache.streampipes.extensions.connectors.plc.adapter.modbus;
public class ModbusConfigFile {
@@ -58,4 +58,4 @@ public String getLogicalAddress() {
public void setLogicalAddress(String logicalAddress) {
this.logicalAddress = logicalAddress;
}
-}
\ No newline at end of file
+}
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/modbus/Plc4xModbusAdapter.java b/streampipes-extensions/streampipes-connectors-plc/src/main/java/org/apache/streampipes/extensions/connectors/plc/adapter/modbus/Plc4xModbusAdapter.java
similarity index 99%
rename from streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/modbus/Plc4xModbusAdapter.java
rename to streampipes-extensions/streampipes-connectors-plc/src/main/java/org/apache/streampipes/extensions/connectors/plc/adapter/modbus/Plc4xModbusAdapter.java
index c755901d58..6938ead546 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/modbus/Plc4xModbusAdapter.java
+++ b/streampipes-extensions/streampipes-connectors-plc/src/main/java/org/apache/streampipes/extensions/connectors/plc/adapter/modbus/Plc4xModbusAdapter.java
@@ -16,7 +16,7 @@
*
*/
-package org.apache.streampipes.connect.iiot.adapters.plc4x.modbus;
+package org.apache.streampipes.extensions.connectors.plc.adapter.modbus;
import org.apache.streampipes.commons.exceptions.connect.AdapterException;
diff --git a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/s7/Plc4xS7Adapter.java b/streampipes-extensions/streampipes-connectors-plc/src/main/java/org/apache/streampipes/extensions/connectors/plc/adapter/s7/Plc4xS7Adapter.java
similarity index 64%
rename from streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/s7/Plc4xS7Adapter.java
rename to streampipes-extensions/streampipes-connectors-plc/src/main/java/org/apache/streampipes/extensions/connectors/plc/adapter/s7/Plc4xS7Adapter.java
index 5913480d80..103e428cb1 100644
--- a/streampipes-extensions/streampipes-connect-adapters-iiot/src/main/java/org/apache/streampipes/connect/iiot/adapters/plc4x/s7/Plc4xS7Adapter.java
+++ b/streampipes-extensions/streampipes-connectors-plc/src/main/java/org/apache/streampipes/extensions/connectors/plc/adapter/s7/Plc4xS7Adapter.java
@@ -16,10 +16,11 @@
*
*/
-package org.apache.streampipes.connect.iiot.adapters.plc4x.s7;
+package org.apache.streampipes.extensions.connectors.plc.adapter.s7;
import org.apache.streampipes.commons.exceptions.connect.AdapterException;
+import org.apache.streampipes.extensions.connectors.plc.adapter.s7.config.ConfigurationParser;
import org.apache.streampipes.extensions.api.connect.IAdapterConfiguration;
import org.apache.streampipes.extensions.api.connect.IEventCollector;
import org.apache.streampipes.extensions.api.connect.IPullAdapter;
@@ -33,6 +34,7 @@
import org.apache.streampipes.model.AdapterType;
import org.apache.streampipes.model.connect.guess.GuessSchema;
import org.apache.streampipes.model.schema.EventProperty;
+import org.apache.streampipes.model.schema.EventPropertyList;
import org.apache.streampipes.model.staticproperty.CollectionStaticProperty;
import org.apache.streampipes.model.staticproperty.StaticProperty;
import org.apache.streampipes.model.staticproperty.StaticPropertyGroup;
@@ -41,11 +43,12 @@
import org.apache.streampipes.sdk.builder.adapter.AdapterConfigurationBuilder;
import org.apache.streampipes.sdk.builder.adapter.GuessSchemaBuilder;
import org.apache.streampipes.sdk.extractor.StaticPropertyExtractor;
+import org.apache.streampipes.sdk.helpers.Alternatives;
+import org.apache.streampipes.sdk.helpers.CodeLanguage;
import org.apache.streampipes.sdk.helpers.Labels;
import org.apache.streampipes.sdk.helpers.Locales;
import org.apache.streampipes.sdk.helpers.Options;
import org.apache.streampipes.sdk.utils.Assets;
-import org.apache.streampipes.sdk.utils.Datatypes;
import org.apache.plc4x.java.PlcDriverManager;
import org.apache.plc4x.java.api.PlcConnection;
@@ -53,6 +56,7 @@
import org.apache.plc4x.java.api.messages.PlcReadRequest;
import org.apache.plc4x.java.api.messages.PlcReadResponse;
import org.apache.plc4x.java.api.types.PlcResponseCode;
+import org.apache.plc4x.java.api.value.PlcValue;
import org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -78,17 +82,33 @@ public class Plc4xS7Adapter implements StreamPipesAdapter, IPullAdapter, PlcRead
*/
private static final String PLC_IP = "plc_ip";
private static final String PLC_POLLING_INTERVAL = "plc_polling_interval";
- private static final String PLC_NODES = "plc_nodes";
+ public static final String PLC_NODES = "plc_nodes";
private static final String PLC_NODE_NAME = "plc_node_name";
private static final String PLC_NODE_RUNTIME_NAME = "plc_node_runtime_name";
private static final String PLC_NODE_TYPE = "plc_node_type";
+ public static final String PLC_NODE_INPUT_CODE_BLOCK_ALTIVE = "plc_node_input_code_block_altive";
+ public static final String PLC_CODE_BLOCK = "plc_code_block";
+ public static final String PLC_NODE_INPUT_ALTERNATIVES = "plc_node_input_alternatives";
+ public static final String PLC_NODE_INPUT_COLLECTION_ALTERNATIVE = "plc_node_input_collection_alternative";
+
+ public static final String CODE_TEMPLATE = """
+ // This code block can be used to manually specify the addresses of the PLC registers.
+ // The syntax is based on the PLC4X syntax, see [1].
+ // Address Pattern:
+ // propertyName=%{Memory-Area}{start-address}:{Data-Type}[{array-size}]
+
+ temperature=%I0.0:INT
+
+ // [1] https://plc4x.apache.org/users/protocols/s7.html
+ """;
+
/**
* Values of user configuration parameters
*/
private String ip;
private int pollingInterval;
- private List