I've been trying to program one arduino as the server and another one as a client.
For the server, when I use Ethernet.begin (mac, ip), Ethernet.linkStatus ( ) returns LinkOFF. And consequently there's no connection.
On the client side, where Ethernet.begin (mac) is used, Ethernet.linkStatus ( ) does not return any errors.
I was told to update my library from Ethernet.h to Ethernet2.h. But then I got errors that functions - Ethernet.hardwareStatus ( ), Ethernet.linkStatus ( ) and the condition if(server) is not defined. I used Ethernet2.h regardless, and removed all these constructs from my code.
PS
- My Server IP is unique on the network
- The port I'm using is free
- The MAC address is unique and correct
- I've double, triple, quadruple checked all the connections
- When I was using Ethernet.h, Ethernet.hardwareStatus ( ) detected the W5500 chip on both server and client side.
- Ethernet.linkStatus ( ) fails wherever Ethernet.begin (mac, ip) is used (In all sample sketches from Arduino as well)
This is the server code:
[I've tried to use server.accept ( ) instead of server.available ( ), but with Ethernet2.h that also gave me an error]
#include <Ethernet2.h>
#include <SPI.h>
byte mac[] = { 0xA8 , 0x61 , 0x0A , 0xAE , 0x76 , 0x23 };
IPAddress ip(10,16,60,201); //defined static IP
EthernetServer server (1033); //defined own port number
void setup() {
Serial.begin(9600);
Serial.println("\nIn Setup");
Ethernet.begin(mac,ip);
Serial.println("\n\nEthernet.begin( ) may have passed");
server.begin(); //INITIALISE SERVER
Serial.println("\n\nPerhaps the server is listening");
}
void loop() {
EthernetClient client = server.available(); //maybe use server accept to get a client cause the client might not have data ready?
if (client.connected( )) {
Serial.println("\nClient is connected");
}
else {
Serial.println("\nClient not connected");
}
delay (30000);
delay (30000);
delay (30000);
delay (30000);
client.stop( );
}
And here's the client code:
#include <Ethernet2.h>
#include <SPI.h>
byte mac[] = { 0xA8 , 0x61 , 0x9A , 0xAE , 0x89 , 0x25 }; //MAC address from sticker, except last hex value
IPAddress ServerIP(10,16,60,201); //defined static IP of server
EthernetClient client;
void setup() {
Serial.begin(9600);
pinMode(30, OUTPUT);
pinMode(33, OUTPUT);
if(Ethernet.begin(mac)==1) { //ETHERNET INITIALISATION TEST
Serial.println("Ethernet successfully initialised");
}
else {
Serial.println("Ethernet initialisation failed");
}
}
void loop() {
client.connect(ServerIP, 1033); //CONNECT TO SERVER AND CHECK CONNECTION
delay(1000);
if (client.connected()){
digitalWrite(30, HIGH); //BLUE LED -- STATUSLED 30
delay(10000);
digitalWrite(30, LOW);
}
else {
digitalWrite(33, HIGH); //RED LED -- STATUSLED 33
delay(10000);
digitalWrite(33, LOW);
}
}
What am I missing? What's going wrong?
I have considered that there might be a synchronization issue, but it seems that the only way to confirm this is to make it work.


