Echo TCP server on Arduino based PLC

Echo TCP server on Arduino based PLC

On this post is showed how to create a server TCP on an Arduino based PLC. The requirements of this post is just an M-Duino PLC with Ethernet connection and an available TCP client in order to test it. 

Take a look an example of how to implement a TCP client with Arduino based PLC.

Once the server is running, any client can connect to the server. On this example it is used an M-Duino to generate the server. The example of TCP client showed before could be one of the clients.

Next it is showed the Arduino IDE code:

// use Ethernet.h if you have a M-Duino V7 version
#include <Ethernet2.h>

// mac address for M-Duino
byte mac[] = { 0xBE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Ip address for M-Duino
byte ip[] = { 192, 168, 1, 100 };
int tcp_port = 5566;

EthernetServer server = EthernetServer(5566);

void setup()
{
  // initialize the ethernet device
  Ethernet.begin(mac, ip);

  // start server for listenign for clients
  server.begin();
}

void loop()
{
  // if an incoming client connects, there will be bytes available to read:
  EthernetClient client = server.available();
  if (client.available()) {
    // read bytes from the incoming client and write them back
    // to the same client connected to the server
    client.write(client.read());
  }
}

 

Once the sketch is running on Arduino based PLC any client can connect with this echo server.

For more information see on Arduino web site the TCP functions Ethernet / Ethernet 2 library

See also:

MODBUS TCP/IP LIBRARY FOR ARDUINO BASED PLC’S

TCP CLIENT ON ARDUINO BASED PLC

Comments are closed.