Newbie here, I am trying to use WT32-ETH01 to communicate to another WT32-ETH01 using LAN cable. Both of them are connected directly to each others.
Zero knowledge on network, but I guess I will need one as TCP client and another one as TCP server.
Correct me if I'm wrong, I will need to do the following setup:
use static IP within a range ,example: 192.168.1.1 and 192.168.1.2
use same subnet mask ,example: 255.255.255.0
use same gateway
I guess I will need to setup the port to listen? kindly enlighten me.
Is there any sample code that I can start with? Tried to search online but most of them using UDP, webserver those which I don't need. I could only get some .c code from ESPRESSIF website but they are not C++ for Arduino.
Does anyone know where to get a simple baremetal TCP for my LAN to LAN case?
The esp32 core for arduino claims to support the eth01. (Theācoreā is built on top of the espressif sdk, and adds the C++ and arduino levels.)
Aside from setting up the Ethernet itself, the higher-level tcp server/client code should look the same as for WiFi (for which there should be many examples.). Thatās the magic of ālayering.ā
Welcome! From your description it will not work. You need to use a cross over cable, switch, hub so they can communicate with each other. I would start with the UDP, it is much easier to get started. When that is working you then know the hardware is working. Posting a network block diagram helps. As I currently see it there are two Arduinos connected to each other with a standard ethernet cable.
As far as I am concerned, I guess I don't need a switch and hub since they are just communicating with each others directly without accessing anything on the internet?
Just a simple connection between both WT32-ETH01 via LAN cable for them to send and receive from each others.
Your choice but it will not work the way you want. Use the cross over cable. I never stated that it needed to connect to the internet. Those devices allow two units to communicate with other devices.
Ahhh thanks man, now only I realized that there is a difference between a normal straight through cable and cross over cable. But is it compulsory to have the switch and Hub for them to communicate with each others?
Only one of the three, sorry I was not clear. Just use the cable. If you look at the wiring there is TX and RX pairs where Tx connects to Rx. If you can crimp the connectors you can make one yourself. Splicing wires will normally not work.
The datasheet I found for this board says it uses a LAN8720A Ethernet Phy chip, which has " HP Auto-MDIX support allows the use of direct connect or cross-over LAN cables."
A hub is safer, though, and might even give you some debugging info ("look - the data led is flashing; it must be doing something!")
YMMV on whether the module you purchased has the same design or not, or whether it works as perfectly as the datasheet says.
It is not clear to me whether UDP is any easier to use than TCP, once you're running Arduino over SDK over Espressif's libraries and OS.
I just did some research and found out that the Auto-MDIX is turned on by default. Tried using the basic sample ETH_LAN8720.ino, added few lines of code in it: ( directly connect the WT32-ETH01 to my laptop for testing )
// Select the IP address according to your local network
IPAddress myIP(192, xxx, x, xx); // IP address of the sender board
IPAddress myGW(192, xxx, x, xx); // Gateway IP address
IPAddress mySN(255, 255, 255, 0); // Subnet mask
IPAddress myDNS(8, 8, 8, 8); // DNS server IP address
And this after the ETH.begin();
ETH.config(myIP, myGW, mySN, myDNS);
Still getting:
connecting to google.com
connection failed
BUT at least, I can now ping it successfully. Long way to go...
Alright, I will post it here just in case there is anyone met this problem or looking for solutions.
#include <ETH.h>
#include <WiFi.h>
/*
* ETH_CLOCK_GPIO0_IN - default: external clock from crystal oscillator
* ETH_CLOCK_GPIO0_OUT - 50MHz clock from internal APLL output on GPIO0 - possibly an inverter is needed for LAN8720
* ETH_CLOCK_GPIO16_OUT - 50MHz clock from internal APLL output on GPIO16 - possibly an inverter is needed for LAN8720
* ETH_CLOCK_GPIO17_OUT - 50MHz clock from internal APLL inverted output on GPIO17 - tested with LAN8720
*/
#define ETH_CLK_MODE ETH_CLOCK_GPIO17_OUT
// Pin# of the enable signal for the external crystal oscillator (-1 to disable for internal APLL source)
#define ETH_POWER_PIN 16
// Type of the Ethernet PHY (LAN8720 or TLK110)
#define ETH_TYPE ETH_PHY_LAN8720
// I²C-address of Ethernet PHY (0 or 1 for LAN8720, 31 for TLK110)
#define ETH_ADDR 1
// Pin# of the I²C clock signal for the Ethernet PHY
#define ETH_MDC_PIN 23
// Pin# of the I²C IO signal for the Ethernet PHY
#define ETH_MDIO_PIN 18
// MAC address of Device 1
uint8_t mac[] = {0xDE, 0xAD, 0xBE, 0xEE, 0xFE, 0xEE}; // use any MAC
// Select the IP address for Device 1
IPAddress localIP(192, 168, 1, 1); // IP address of Device 1
// Select the subnet mask for Device 1
IPAddress subnet(255, 255, 255, 0); // Subnet mask for Device 1
// Select the port number for communication
uint16_t port = 23; //telnet use port 23
const size_t ETH_bufferSize = 64;
uint8_t ETH_buffer[ETH_bufferSize] = {0};
uint8_t totalBufSize = 0;
WiFiServer server;
void setup()
{
Serial.begin(115200);
// Initialize Ethernet and set the MAC address
ETH.begin(ETH_ADDR, ETH_POWER_PIN, ETH_MDC_PIN, ETH_MDIO_PIN, ETH_TYPE, ETH_CLK_MODE);
ETH.macAddress(mac);
// Set the local IP address, subnet mask, and start Ethernet connection
ETH.config(localIP, IPAddress(), subnet);
// Start the TCP server
server.begin(port);
Serial.print("TCP server started at ");
Serial.print(localIP);
Serial.print(":");
Serial.println(port);
}
void loop()
{
// Check if there is a connected client waiting to be serviced by the server
if (server.hasClient())
{
WiFiClient client = server.available();
// New client connected
Serial.println("Client available");
while (client.connected())
{
// Check if there is data available from the client
if (client.available())
{
// Read the data from the client
char c = client.read();
Serial.println(c);
if(c == '\n')
{
break;
}
}
delay(10);
}
Serial.println("");
// Client disconnected
Serial.println("Client disconnected");
}
}
This is for the TCP server side, to validate this, we need to use telnet ( I am using Hercules ) as client and connect to the port. Also dont forget to set your ethernet IP accordingly.
My code is not perfect so you can always modify it based on what you need, feel free to contribute back to the community.