You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@plc4x.apache.org by Laveenkumar Sridhar <la...@gmail.com> on 2023/04/21 11:32:27 UTC

Need help to figure Dependency and Project work flow-regards

Dear Team,


Am Sridhar- India , working on Startup which our own plc Board (esp32,
arduino base) will connect to Mqtt, and plc4x , kafka . Which helps to work
Industry 4.0 .. Small scale based industries..

Coming to point!! Our programmer developed PLC LD AND DUMPED into plc board
!! Also that code sended to Mqtt .

Here plc4x how to connect and to work with plc4x lot of doubts came.

Can you team support us how to sort this out?



With Regards
Laveenkumar Sridhar
Hyderabad
9789136125 - Whatsapp

Re: Need help to figure Dependency and Project work flow-regards

Posted by Lukas Ott <ot...@gmail.com>.
Hi Laveenkumar,

Welcome to the PLC4X Project.

Sorry I do not understand your question.

First can you tell us which language you are trying to use?
- Java
- Go
or C? (are you trying to deploy PLC4C on an Arduino?)

Second we can not see any links.

Please provide a code example or some more description what you are trying
to do

Thank you!

With regards
Lukas

Am So., 23. Apr. 2023 um 17:52 Uhr schrieb Laveenkumar Sridhar <
laveeen@gmail.com>:

> Dear Team,
>
>
> Am Sridhar- India , working on Startup which our own plc Board (esp32,
> arduino base) will connect to Mqtt, and plc4x , kafka . Which helps to work
> Industry 4.0 .. Small scale based industries..
>
> Coming to point!! Our programmer developed PLC LD AND DUMPED into plc board
> !! Also that code sended to Mqtt .
>
> Here plc4x how to connect and to work with plc4x lot of doubts came.
>
> Can you team support us how to sort this out?
>
>
>
> With Regards
> Laveenkumar Sridhar
> Hyderabad
> 9789136125 - Whatsapp
>

Re: Need help to figure Dependency and Project work flow-regards

Posted by Laveenkumar Sridhar <la...@gmail.com>.
Hi sir, thanks for reply

Here we doing something Small Scale Industry Automation *Industry 4.0 *, I
don't have PLC instead of PLC i am using *ESP32 *, through ESP32 I dumped
the Ladder Logic code (Example: Simple Machine Control ON and OFF) using
mqtt protocol and the code is went to mosquitto broker protocol and i am
getting real time data in mosquito.Now i want to send that data from *Mosquito
to plc4x *so here i am using Eclipse ide using *java*. So i wrote the code
in java please verify my code. What I did is correct or not?

And also say how to see the data is received by Apache PLC4X
once that Data Recive to plc4x then we try to send that data to Apache
kafka.

ALSO PLEASE SAY OUR FLOW OF WORK IS RIGHT OR ANYTHING WE MISSED!!!!

OPENPLC we used to create Ladder logic to control machine

*ESP32 Micro Controller link:
**https://robu.in/product/esp32-38pin-development-board-wifibluetooth-ultra-low-power-consumption-dual-core/?gclid=CjwKCAjwl6OiBhA2EiwAuUwWZRoLZz42dfc99s8lv14KC7knmhQNMkHK5M0DVkIPU43c3lrNvYoJexoCjXcQAvD_BwE
<https://robu.in/product/esp32-38pin-development-board-wifibluetooth-ultra-low-power-consumption-dual-core/?gclid=CjwKCAjwl6OiBhA2EiwAuUwWZRoLZz42dfc99s8lv14KC7knmhQNMkHK5M0DVkIPU43c3lrNvYoJexoCjXcQAvD_BwE>*


package mqtt1;

import java.util.function.Consumer;
import java.util.function.Function;

import org.apache.plc4x.java.mqtt.MqttPlcConnection;
import org.apache.plc4x.java.mqtt.Connection;
import org.apache.plc4x.java.api.PlcReader;
import org.apache.plc4x.java.api.PlcConnection;
import org.apache.plc4x.java.api.PlcDriverManager;
import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
import org.apache.plc4x.java.api.types.PlcResponseCode;
import org.apache.plc4x.java.api.values.PlcWriteRequest;
import org.eclipse.paho.client.mqttv3.IMqttClient;
import org.eclipse.paho.client.mqttv3.IMqttMessageListener;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



public class drill1 {

private static final Logger LOGGER = LoggerFactory.getLogger(drill1 .class);

    public static void main(String[] args) throws MqttException {
        String brokerUrl = "tcp://192.168.0.199:1883";
        String clientId = "abcdef";
        String topic = "plc/testcode/";
        String esp32IpAddress = "192.168.1.100"; // replace with actual IP
address of your ESP32

        // Create the MQTT client.
        IMqttClient mqttClient = new MqttClient(brokerUrl, clientId);

        // Configure the connection options.
        MqttConnectOptions connOpts = new MqttConnectOptions();
        connOpts.setCleanSession(true);

        // Connect to the MQTT broker.
        mqttClient.connect(connOpts);

        // Create the PLC4X connection.
        try (PlcConnection plcConnection = new
PlcDriverManager().getConnection("modbus:tcp://" + esp32IpAddress +
":502")) {

            // Subscribe to the MQTT topic.
            mqttClient.subscribe(topic, new IMqttMessageListener() {
                @Override
                public void messageArrived(String topic, MqttMessage
message) throws Exception {
                    LOGGER.info("Received message: {}", new
String(message.getPayload()));

                    // Convert the message to a PLC4X write request.
                    PlcWriteRequest writeRequest =
plcConnection.writeRequestBuilder()
                            .addItem("my-item", "%DB1:DINT")
                            .addValue("my-item", Integer.parseInt(new
String(message.getPayload())))
                            .build();

                    // Write the value to the PLC.
                    PlcResponseCode responseCode =
writeRequest.execute().get();
                    if (responseCode != PlcResponseCode.OK) {
                        LOGGER.warn("Failed to write value to PLC. Response
code: {}", responseCode);
                    } else {
                        LOGGER.info("Wrote value to PLC.");
                    }
                }
            });
        } catch (PlcConnectionException e) {
            throw new PlcRuntimeException("Error connecting to ESP32 PLC",
e);
        }
    }
}





<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.calterio3</groupId>
  <artifactId>mqtt</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>


     <dependency>
        <groupId>org.eclipse.paho</groupId>
        <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
        <version>1.2.5</version>
    </dependency>

  <dependency>
    <groupId>org.apache.plc4x</groupId>
    <artifactId>plc4j-api</artifactId>
    <version>0.10.0</version>
</dependency>








  </dependencies>

  <repositories>
    <repository>
        <id>apache.snapshots</id>
        <url>https://repository.apache.org/content/repositories/snapshots/
</url>
    </repository>
</repositories>

<build>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>

</project>