Apollo3zehn / FluentModbus

Lightweight and fast client and server implementation of the Modbus protocol (TCP/RTU).
MIT License
188 stars 69 forks source link

[Question] - OpenPLC integration with esp32 #87

Closed ghostidentity closed 1 year ago

ghostidentity commented 1 year ago

Hello Guys,

I noticed that OpenPLC can take advantage of esp32 to establish connection to modbus server. I wanted to have a scenario wherein:

  1. The user press the push button (esp32 device)
  2. The device then send request to c# program (server) that integrates with fluentmodbus e.g. pin 2 (high)
  3. C# program acknowledge the request then modify the pin value to esp32device

The problem is that, openPLC does not appear to connect to c# program (server mode), so I'd like to ask if it's possible ?

image

Thanks, Mark

Apollo3zehn commented 1 year ago

Hi, I have a few questions:

I think my main problem is that I do not understand your architecture. Could you please create a diagram/text which explains your setup in more detail?

If you have network problems, I always recommend Wireshark. It would show you if the TCP Connect was successful. It also recognizes Modbus communication.

ghostidentity commented 1 year ago

Here's the general overview. image

  1. Yes, OpenPLC can be simulated locally, since I executed openplc and modbus server on same computer the address 127.0.0.1 can be used but once the code is deployed on esp32 device, the address will be changed.
  2. On the diagram, when the person click the push button it will send a data to modbus server like: device_1: true . During device, initialization, it will try to connect to modbus server.
  3. Once the device successfully connected to the modbus server, technically the server can write coil values or the server can connect to specific device to modify the coil position [2] value to 1. Based on openPLC mapping, position [2] = pin #2, setting it to 1 (high) will turn on the led light.
  4. How would a simple TCP Connect help to communicate via Modbus TCP? Im not sure about this one, need to understand how it connect, as its OpenPLC related. But I tried the sample code provided on fluentmodbus documentation, i was able to read the coil value using Modbus TCP client. So my assumption is that, I can use the ModBusTCPServer so the device can connect to it.

Other info:

OpenPLC, can configure the device to use ModBus TCP for communication.

image

I will try wireshark to troubleshoot.

Apollo3zehn commented 1 year ago

Thanks, so my understanding is:

For a true bidirectional communication, you would need a client and server on both sides, esp32 and on the server device.

Another solution would be to let the esp32 poll the server for changes. The server cannot push data.

Do I get it right so far? Or does "the server can connect to a specific device" mean using a different protocol other than Modbus?

ghostidentity commented 1 year ago

I'm now closing this issue as the owner of openPLC clarified that TCP_connect can't be used to establish connection to modbus server. @Apollo3zehn thanks for response. image