I use the Ethernet shield with an Uno and create a web client. If I put a delay like one second for initialization it works fine. However if I wait for it in a while loop (like waiting for the serial, and as mentioned in Arduino docs) it never gets out of the loop that means the client instance is null.
I found this method on Arduino website in an example code:
while(!client) { ; } // waiting to get ready
Here's the code; if I uncomment it will stay there. Also the same with providing the MAC argument only.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE };
char server[] = "www.google.com"; // name address for Google (using DNS)
IPAddress ip(192, 168, 1, 213);
EthernetClient client;
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
Ethernet.begin(mac, ip);
delay(1000);
//while(!client){ ; }
Serial.println(Ethernet.localIP());
}