I am trying to make a connection with the EthernetClient, but it always fails with code 0. I decided to write a small code just to test if the client ever becomes ready, and as I suspected it does not.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {0x2A, 0x27, 0x55, 0x08, 0x1E, 0x6A};
IPAddress ip(172, 16, 48, 133);
EthernetClient client;
void setup() {
Ethernet.init(10);
Ethernet.begin(mac, ip);
Serial.begin(9600);
while (!Serial) {;}
for (auto link = Ethernet.linkStatus(); link != LinkON; link = Ethernet.linkStatus()) {;}
Serial.println("Link ON");
while(!client){
Serial.println("Client not ready");
delay(1000);
}
Serial.println("Client ready!");
}
void loop() {}
If I try to run the code above, it gets stuck at the "Client not ready" loop, and I can't figure it out what I'm missing for it to work.
Obs.: I have already configured a web server with success with my shield, so I'm guessing the problem is not with it.
!client. This maps to the boolean operator which tells you if it has a connected socket (github.com/arduino-libraries/Ethernet/blob/…). Since you have not calledconnect()on the client, this will always return false. What actual error do you have in your full sketch?