ESP32 LAN communication

Hi, so I try make two ESP32 boards communicate using LAN cable:

  1. For board number one (As Server or Receiver), I use LAN module ENC28J60, here is the code:
#include <UIPEthernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC address of the receiver board
IPAddress ip(192, 168, 10, 101); // IP address of the receiver board
EthernetServer server(80);

void setup() {
  Ethernet.begin(mac, ip); // Start the Ethernet connection with ENC28J60
  server.begin();
  Serial.begin(9600);
  delay(1000);
}

void loop() {
  EthernetClient client = server.available();
  if (client) {
    Serial.println("Client connected!");
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
      }
    }
    client.stop();
    Serial.println("Client disconnected!");
  }
}

  1. and for the board number 2 (as client or sender), I use LAN module W5500, and here is the code:
#include <SPI.h>
#include <Ethernet2.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE }; // MAC address of the sender board
IPAddress ip(192, 168, 10, 102); // IP address of the sender board
IPAddress receiverIp(192, 168, 10, 101); // IP address of the receiver board
EthernetClient client;

void setup() {
  Ethernet.init(21); // CS pin for W5500 module
  Ethernet.begin(mac, ip); // Start the Ethernet connection with W5500
  Serial.begin(9600);
  delay(1000);
}

void loop() {
  if (!client.connected()) {
    Serial.println("Connecting to receiver...");
    if (client.connect(receiverIp, 80)) {
      Serial.println("Connected!");
      client.println("Hello, receiver!");
      client.stop();
    } else {
      Serial.println("Connection failed");
    }
  }
  delay(1000);
}

then I connect both of them using ethernet cable but the connection doesn't happen, it still get the Serial.println("Connection failed");

Can anybody help me?

How about using a plain simple serial connection?

In your real application: are the two ESP32s far away from each other and the data has to travel across a large network across multiple rooms ?

How about using encrypted WiFi? The ESP32 are able to use WPA2
Would this be too unsecure?

best regards Stefan

The comment points to a different ethernet-chip (W5500) than an ENC28J60.
Are you sure that the chosen library is suited for the ENC28J60-chip?

I would not be surprised if this code was created by chatGPT.

The ESP32 has two hardware-SPI-busses.
To which SPI-Bus (= to which IO-pins) did you connect the ENC28J60-chip?

What does the library-documentaion say about how to initialise the library to use a specific SPI-bus?

EDIT:

duckduck go is always worth a 5 minutes search

best regards Stefan

That's correct sir, this is the code from ChatGpt.

And I am so sorry but I still lacking of knowledge of ESP32 SPI-Bus, but what I get from the code, the ESP32-ENC28J60 as Receiver or Server is that just:

  1. For ENC28J60, I use this library: #include <UIPEthernet.h> and it compilled without hasle.
  2. For this board, inside the code, I don't initialize any pin at all, instead I use this schematic sir:

Hi @brogr4mm3r

no "sir" needed. "Sir" is in aprobriate.
A simple "you" is approbiate even if I write some rhetoric questions:

Are you able to click on this link?

are you able to click on this link that is found by duckduck go?

Are you able to click into the example-codes of this github-repository?
There you will find a demo-code expeccially made for the combination of an ESP32 with ENC28J60

The documentation in Github repos is mostly found under read.me

best regards Stefan

Hai, thanks man, I will open that tomorrow, soo appreciate all of your help...

Hello Stefan, so, my end goal is to communicate this esp32 to some industrial machine and medical devices, this machine can only communicate with other machine using an ethernet cable. The machine receive some command from client than return a data. For the first step, I already succeeded in fetching data from the machine using a Laptop using a tera term software and TCP communication protocol.

For the next step to automate it, I just have to develop a program using ESP32. But before I tyr the program to the machine, I need to test it on an ESP32, so ESP32 talk to ESP32 using ethernet cable.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.