Network Shield Problems

Why my network shield doesn’t want to connect with my WEBServer based on apache, php and mysql (XAMPP Installer)?
My WEBServer has the following parameters:
IP: 192.168.1.2;
SM: 255.255.255.0;
GW: 192.168.1.1;
DNS1: 8.8.8.8 (google1);
DNS2: 8.8.4.4 (google2);

Yesterday it worked, today not anymore. Ovviously yesterday night i powered off my PC.
It works only if i connect it with a second level domain (www.google.com, www.altervista.org…)

The code is the following:

const int analogInPin = A0; 

float sensorValue = 0;
float outputValue = 0; 

#include <LiquidCrystal.h>
#include <Ethernet.h>
#include <SPI.h>

#define rs  8
#define enable 6

#define d4  5
#define d5  4
#define d6  3
#define d7  2

#define  ROW 4
#define  COL 20

int i = 0;
int red = 78;
int green = 79;
int blue = 80;
int red2 = 81;
int green2 = 82;
int blue2 = 83;
int buzzer = 84;
byte mac[] = { 0x00,0x18,0x3E,0x00,0xFB,0x43 };
byte ip[] = { 192,168,1,4 };
byte gateway[] = { 192,168,1,1 };
byte subnet[] = { 255,255,255,0 }; 
byte dns1[] = {8,8,8,8};
byte dns2[] = {8,8,4,4};
unsigned long time;
unsigned long last;
int state;
LiquidCrystal lcd(rs, enable, d4, d5, d6, d7);
const char * webserver = "www.google.it";
Client client(webserver, 80);

void setup() {
  
    analogWrite(buzzer, 255);
    delay(150);
    analogWrite(buzzer, 0);
  
  Serial.begin(115200);
  lcd.begin(COL, ROW);
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);  
  pinMode(red2, OUTPUT);  
  pinMode(blue2, OUTPUT);  
  pinMode(green2, OUTPUT);
  lcd.clear();
  lcd.setCursor(0,0);
  
  for(int i = 5; i > 0; i--) {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Connecting...");
  analogWrite(red, 255);
  delay(150);
  analogWrite(red, 0);
  analogWrite(green, 255);
  delay(150);
  analogWrite(green, 0);
  analogWrite(blue, 255);
  delay(150);
  analogWrite(blue, 0);
  analogWrite(red, 255);
  lcd.setCursor(0,0);
  lcd.print("Assigning IPs...");
  }
  
  Ethernet.begin(mac,ip,gateway,subnet,dns1,dns2);
  //client.connect();
  
  if (client.connect()) {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Connected");
    client.println("GET /search?q=arduino HTTP/1.0");
    client.println();
    analogWrite(red, 0);
         analogWrite(blue, 0);
    analogWrite(green, 255);
    
      analogWrite(buzzer, 255);
    delay(100);
    analogWrite(buzzer, 0);
    delay(50);
      analogWrite(buzzer, 255);
    delay(100);
    analogWrite(buzzer, 0);
  }
  
  else {
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Connection Failed");
    analogWrite(green, 0);
    analogWrite(blue, 0);
    analogWrite(red, 255);
    analogWrite(buzzer, 255);
    delay(1000);
    analogWrite(buzzer, 0);
  }
}

void loop(){
  sensorValue = analogRead(analogInPin);
  sensorValue = ((5.0 * sensorValue * 100.0)/1024.0)-10.6;
  
if (client.available()) {
    char c = client.read();
  }
  if (!client.connected()) {
    analogWrite(red, 255);
analogWrite(blue, 0);
analogWrite(green, 0);
    client.stop();
    client.connect();
  }
  
  analogWrite(buzzer, 0);
  analogWrite(red2, 0);
  analogWrite(blue2, 0);
  analogWrite(green2, 0);
  
  if (millis() > last + 999){
    last = millis();
      peripheralsControl();
  }
}

void peripheralsControl(){
  if(sensorValue>0 && sensorValue<50){  
    

  lcd.setCursor(0,0);
  lcd.clear();
         lcd.print("Temp = ");     
         lcd.print(sensorValue);
         lcd.print(" ");
         lcd.print((char)223);
         lcd.print("C");
         if (client.connected()) {
    lcd.setCursor(0,2);
    lcd.print("Connected");
    analogWrite(red, 0);
analogWrite(blue, 0);
analogWrite(green, 255);
  }

  if (!client.connected()) {
    lcd.setCursor(0,2);
    lcd.print("Disconnected");
    analogWrite(red, 255);
analogWrite(blue, 0);
analogWrite(green, 0);
  }

}
else{
    lcd.setCursor(0,2);
    lcd.print("Disconnected");
    
analogWrite(red, 0);
analogWrite(blue, 255);
analogWrite(green, 0);
}
analogWrite(red2, 255);
analogWrite(blue2, 0);
analogWrite(green2, 0);
delay(10);
}

If your server is not localnet, this will not work.

  Ethernet.begin(mac,ip,gateway,subnet,dns1,dns2);

It should be this.

  Ethernet.begin(mac,ip,dns1,gateway,subnet);

RESOLVED: Windows Firewall was blocking xampp :0

SurferTim: If your server is not localnet, this will not work.

  Ethernet.begin(mac,ip,gateway,subnet,dns1,dns2);

It should be this.

  Ethernet.begin(mac,ip,dns1,gateway,subnet);

Might also be that case, but are the same.

Might also be that case, but are the same.

No. The parameters in order are

Ethernet.begin(mac_address, ip_address, dns_server, gateway, subnet)

How do you see that as the same? You are setting your gateway to 255.255.255.0.

My WebClient example says:

  Ethernet.begin();                                   // DHCP is used, default ENCX24J600 (ENC24J60) MAC address 
//  Ethernet.begin(mac);                                // DHCP is used
//  Ethernet.begin(mac, ip);                            // Static IP, gateway equal to the IP with the last byte set to 1 => IP[3].IP[2].IP[1].1
//  Ethernet.begin(mac, ip, gateway);                   // default subnet 255.255.255.0
//  Ethernet.begin(mac, ip, gateway, subnet);           // default dns1 is equal to gateway, some router/gateways act as DNS servers
//  Ethernet.begin(mac, ip, gateway, subnet, dns1);     // default dns2 is 0.0.0.0
//  Ethernet.begin(mac, ip, gateway, subnet, dns1, dns2);

I followed examples and it works correctly, so... it's ok! :)

I followed examples and it works correctly, so... it's ok! smiley

I have bad news for you and the person who wrote that example. If you are using the ethernet library included with the IDE, this is really how it is:

int begin(uint8_t *mac_address);
void begin(uint8_t *mac_address, IPAddress local_ip);
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server);
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
void begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);

This was copied and pasted from Ethernet.h

Later on, you will post again with something like "It works on my localnet server, but not on the internet. Why not?"